Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for the Haskell programming language #2178

Draft
wants to merge 50 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a6d122f
Start Haskell support
wenkokke Jan 16, 2024
0cf5739
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jan 17, 2024
30bbad8
Changes
wenkokke Jan 17, 2024
341358c
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jan 17, 2024
5e61157
take inside funk
wenkokke Jan 17, 2024
2d7ce9d
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jan 17, 2024
1f91086
Query for functions (~400 LoC)
wenkokke Jan 18, 2024
5a8ca7a
Formatting & restructuring
wenkokke Jan 18, 2024
d6e2817
Rename files
wenkokke Jan 18, 2024
91d8f4d
Fixes for namedFunction
wenkokke Jan 18, 2024
accfb9a
Try adding values
wenkokke Jan 18, 2024
5a1cec7
Add scope facet support for Haskell
wenkokke Jan 22, 2024
7195124
Test namedFunction/functionName/name.function
wenkokke Jan 22, 2024
fd4f30c
Update Haskell scope support facet stuff
wenkokke Jan 22, 2024
24743f7
Update Haskell fixtures
wenkokke Jan 22, 2024
7017a4e
@name tests don't work
wenkokke Jan 22, 2024
cf1cbae
@name.function -> @name
wenkokke Jan 22, 2024
be3d7af
Fix RFCs.hs
wenkokke Jan 22, 2024
2ad74bb
Remove @name from @namedFunction
wenkokke Jan 22, 2024
e7a64a8
Add name.function
wenkokke Jan 22, 2024
fe61271
Add @branch.iteration
wenkokke Jan 22, 2024
6c80baa
Restore haskell.namedFunction
wenkokke Jan 22, 2024
773baba
Remove branch.iteration and name
wenkokke Jan 22, 2024
915013e
Split out functionName
wenkokke Jan 22, 2024
8bd3902
Add name
wenkokke Jan 22, 2024
314be8f
Add fixtures for @name.function
wenkokke Jan 22, 2024
721132e
Add @branch and @branch.iteration
wenkokke Jan 22, 2024
858e285
Add @branch and @branch.iteration
wenkokke Jan 22, 2024
b856d3e
I don't know what's happening.
wenkokke Jan 22, 2024
4fb6403
Why????
wenkokke Jan 22, 2024
3a31715
consistent comments
wenkokke Jan 22, 2024
9f564c3
Move files & add argumentOrParameter iteration tests
wenkokke Jan 22, 2024
65c2faa
Add call & callee
wenkokke Jan 22, 2024
0aa8ce5
Tests for @argument.actual
wenkokke Jan 22, 2024
d3f9b44
Add roadmap
wenkokke Jan 22, 2024
32bb73f
Add name.function
wenkokke Jan 22, 2024
aeb580e
Update haskell.md
wenkokke Jan 22, 2024
3241e86
Add anonymousFunction
wenkokke Jan 22, 2024
a885b01
Update haskell.md
wenkokke Jan 22, 2024
1ca43d7
Add list & string
wenkokke Jan 22, 2024
a0ad642
Basic support for map & move anonymousFunction, functionCall, functio…
wenkokke Jan 23, 2024
122908d
Add some warning comments
wenkokke Jan 23, 2024
95e20f3
Group queries a little bit more closely by relation
wenkokke Jan 23, 2024
4bbbd4f
Fixed generate-scope-tests-for-haskell
wenkokke Jan 23, 2024
45cf49e
Generate wrong fixtures
wenkokke Jan 23, 2024
1b243e4
Remove URL
wenkokke Jan 23, 2024
2d3b08d
*actual -> formal
wenkokke Jan 23, 2024
7bd621d
Fixes to scope support
wenkokke Jan 23, 2024
1d4c887
Rebase on top of HEAD and disable previous queries and supported scopes
wenkokke Sep 13, 2024
12ad364
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Sep 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 20 additions & 0 deletions data/playground/haskell/RFC.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- RFC 1: What should "arg" match?
fst :: (a, b) -> a
fst tup@(x, y) = x
-- ^^^^^^^^^^ <- 🎉 the whole pattern
-- ^^^ <- 👀 only the name of the whole argument, if given
-- ^^^ ^ ^ <- 🚀 all names in the pattern

-- RFC 2: What should "branch" match?
foo = bar
where
bar = 1
-- 🎉 `foo = bar` and `bar = 1`
-- 👀 `foo = bar where bar = 1`
-- 🚀 `foo = bar where bar = 1` and `bar = 1`

-- RFC 3: What should "condition" match?
bap :: Int -> Int
bap | 1 == 1, 2 == 2 = undefined
-- 🎉 `1 == 1` and `2 == 2`
-- 👀 `1 == 1, 2 == 2`
46 changes: 46 additions & 0 deletions data/playground/haskell/branch.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
data a :*: b = a :*: b
type a :+: b = Either a b

fst :: a :*: b -> a
fst (a :*: b) = a

pair a b = a :*: b

fromLeft :: a :+: b -> a
fromLeft (Left a) = a
fromLeft _ = undefined

fib :: Integer -> Integer
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)

abs :: Int -> Int
abs x
| x >= 0 = x
| otherwise = -x

bap :: Int -> Int
bap x
| x > 0, x == 0 = x
| otherwise = -x

compare :: Int -> Int -> Ordering
compare x y
| x < y = LT
| x == y = EQ
| x > y = GT

fromEither :: (a -> c) -> (b -> c) -> Either a b -> c
fromEither f g x = case x of
Left l -> f l
Right r -> g r

someFunction x (y1 : y2 : ys) (a, b, (c, [d])) = undefined

compose :: (a -> b) -> (b -> c) -> (a -> c)
compose f g x = g (f x)

zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith f [] [] = []
zipWith f (x : xs) (y : ys) = f x y : zipWith f xs ys
30 changes: 30 additions & 0 deletions data/playground/haskell/namedFunction.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
one :: Integer
one = 1

type MyInt = Int

fib :: Integer -> Integer
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)

not True = False
not False = True

wot True = 1
wot False = crash
where
crash = undefined

zot = undefined

pot :: a
pot =
let kettle = undefined
in kettle

lot = undefined

type MyDouble = Double

dot = undefined
1 change: 1 addition & 0 deletions packages/common/src/extensionDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const extensionDependencies = [
"mrob95.vscode-talonscript", // talon
"jrieken.vscode-tree-sitter-query", // scm
"mathiasfrohlich.kotlin", // kotlin
"justusadam.language-haskell", // haskell

// Necessary for the `drink cell` and `pour cell` tests
"ms-toolsai.jupyter",
Expand Down
84 changes: 84 additions & 0 deletions packages/common/src/scopeSupportFacets/haskell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* eslint-disable @typescript-eslint/naming-convention */

import type { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types";
import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types";

const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel;

export const haskellScopeSupport: LanguageScopeSupportFacetMap = {
list: unsupported,
map: unsupported,
ifStatement: unsupported,
regularExpression: unsupported,
switchStatementSubject: unsupported,
fieldAccess: unsupported,

statement: unsupported,
"statement.iteration.document": unsupported,
"statement.iteration.block": unsupported,

class: unsupported,
// "class.instance": unsupported,
className: unsupported,

namedFunction: unsupported,
"namedFunction.method": unsupported,
anonymousFunction: unsupported,
functionName: unsupported,

functionCall: unsupported,
"functionCall.constructor": unsupported,
functionCallee: unsupported,
"functionCallee.constructor": unsupported,

"argument.actual": unsupported,
"argument.actual.iteration": unsupported,
"argument.formal": unsupported,
"argument.formal.iteration": unsupported,

"comment.line": unsupported,
"comment.block": unsupported,

"string.singleLine": unsupported,

"branch.match": unsupported,
"branch.match.iteration": unsupported,
"branch.if": unsupported,
"branch.if.iteration": unsupported,
"branch.ternary": unsupported,

"condition.if": unsupported,
"condition.ternary": unsupported,

"name.assignment": unsupported,
"name.assignment.pattern": unsupported,
"name.function": unsupported,
"name.class": unsupported,
"name.field": unsupported,

"key.mapPair": unsupported,
"key.mapPair.iteration": unsupported,

"value.assignment": unsupported,
"value.mapPair": unsupported,
"value.mapPair.iteration": unsupported,
"value.return": unsupported,
"value.return.lambda": unsupported,
"value.field": unsupported,

// "type.adt": unsupported,
// "type.alias": unsupported,
// "type.annotation": unsupported,
// "type.constraint": unsupported,
// "type.dataFamily": unsupported,
// "type.dataInstance": unsupported,
// "type.field": unsupported,
// "type.foreignExport": unsupported,
// "type.foreignImport": unsupported,
// "type.formalParameter": unsupported,
// "type.function": unsupported,
// "type.gadt": unsupported,
// "type.newtype": unsupported,
// "type.typeFamily": unsupported,
// "type.typeInstance": unsupported,
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { cppScopeSupport } from "./cpp";
import { csharpScopeSupport } from "./csharp";
import { cssScopeSupport } from "./css";
import { goScopeSupport } from "./go";
import { haskellScopeSupport } from "./haskell";
import { htmlScopeSupport } from "./html";
import { javaScopeSupport } from "./java";
import { javascriptScopeSupport } from "./javascript";
Expand Down Expand Up @@ -36,6 +37,7 @@ export const languageScopeSupport: StringRecord<LanguageScopeSupportFacetMap> =
csharp: csharpScopeSupport,
css: cssScopeSupport,
go: goScopeSupport,
haskell: haskellScopeSupport,
html: htmlScopeSupport,
java: javaScopeSupport,
javascript: javascriptScopeSupport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,16 @@ export const scopeSupportFacetInfos: Record<
scopeType: "disqualifyDelimiter",
},

"branch.match": {
description: "A pattern match branch",
scopeType: "branch",
},
Comment on lines +302 to +305
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this introduces a bit of confusion in Python, where a match statement is basically a switch statement with pattern matching

"branch.match.iteration": {
description:
"Iteration scope for pattern match branches; should be the entire branch",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by "should be the entire branch"?

scopeType: "branch",
isIteration: true,
},
"branch.if": {
description: "An if/elif/else branch",
scopeType: "branch",
Expand All @@ -308,7 +318,6 @@ export const scopeSupportFacetInfos: Record<
"A for / while loop branch. For most languages there will just be one branch for the entire loop, but eg in Python you can have an else branch for a loop.",
scopeType: "branch",
},

"branch.if.iteration": {
description:
"Iteration scope for if/elif/else branch; should be the entire if-else statement",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export const scopeSupportFacets = [

"disqualifyDelimiter",

"branch.match",
"branch.match.iteration",
"branch.if",
"branch.if.iteration",
"branch.try",
Expand Down
3 changes: 2 additions & 1 deletion packages/cursorless-vscode-e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"scripts": {
"compile": "tsc --build",
"watch": "tsc --build --watch",
"clean": "rm -rf ./out tsconfig.tsbuildinfo ./dist ./build"
"clean": "rm -rf ./out tsconfig.tsbuildinfo ./dist ./build",
"generate-scope-tests-for-haskell": "my-ts-node src/scripts/generateScopeTestsForHaskell.mts"
},
"keywords": [],
"author": "",
Expand Down
Loading
Loading