@exercism/codemirror-lang-haskell 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +91 -0
- package/LICENSE +21 -0
- package/README.md +199 -2
- package/dist/index.cjs +1146 -0
- package/dist/index.d.cts +144 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.js +1139 -0
- package/package.json +54 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { LanguageSupport, LRLanguage } from '@codemirror/language';
|
|
3
|
+
import { CompletionSource } from '@codemirror/autocomplete';
|
|
4
|
+
|
|
5
|
+
declare const parser: LRParser
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
Snippets for the constructs people write most often in Haskell.
|
|
9
|
+
*/
|
|
10
|
+
declare const snippets = [
|
|
11
|
+
snip("${name} :: ${Type}\n${name} ${args} = ${}", {
|
|
12
|
+
label: "fun",
|
|
13
|
+
detail: "function with signature",
|
|
14
|
+
type: "keyword"
|
|
15
|
+
}),
|
|
16
|
+
snip("${name} ${args}\n\t| ${condition} = ${}\n\t| otherwise = ${}", {
|
|
17
|
+
label: "guard",
|
|
18
|
+
detail: "function with guards",
|
|
19
|
+
type: "keyword"
|
|
20
|
+
}),
|
|
21
|
+
snip("case ${expression} of\n\t${pattern} -> ${}", {
|
|
22
|
+
label: "case",
|
|
23
|
+
detail: "expression",
|
|
24
|
+
type: "keyword"
|
|
25
|
+
}),
|
|
26
|
+
snip("if ${condition} then ${} else ${}", {
|
|
27
|
+
label: "if",
|
|
28
|
+
detail: "then else",
|
|
29
|
+
type: "keyword"
|
|
30
|
+
}),
|
|
31
|
+
snip("let ${name} = ${value} in ${}", {
|
|
32
|
+
label: "let",
|
|
33
|
+
detail: "in",
|
|
34
|
+
type: "keyword"
|
|
35
|
+
}),
|
|
36
|
+
snip("where\n\t${name} = ${}", {
|
|
37
|
+
label: "where",
|
|
38
|
+
detail: "block",
|
|
39
|
+
type: "keyword"
|
|
40
|
+
}),
|
|
41
|
+
snip("do\n\t${}", {
|
|
42
|
+
label: "do",
|
|
43
|
+
detail: "block",
|
|
44
|
+
type: "keyword"
|
|
45
|
+
}),
|
|
46
|
+
snip("\\${x} -> ${}", {
|
|
47
|
+
label: "\\",
|
|
48
|
+
detail: "lambda",
|
|
49
|
+
type: "keyword"
|
|
50
|
+
}),
|
|
51
|
+
snip("[${expression} | ${x} <- ${list}]", {
|
|
52
|
+
label: "[|]",
|
|
53
|
+
detail: "list comprehension",
|
|
54
|
+
type: "keyword"
|
|
55
|
+
}),
|
|
56
|
+
snip("foldr (\\${x} ${acc} -> ${}) ${initial} ${list}", {
|
|
57
|
+
label: "foldr",
|
|
58
|
+
detail: "fold with a lambda",
|
|
59
|
+
type: "keyword"
|
|
60
|
+
}),
|
|
61
|
+
snip("data ${Name} = ${Constructor} deriving (Show, Eq)", {
|
|
62
|
+
label: "data",
|
|
63
|
+
detail: "type definition",
|
|
64
|
+
type: "keyword"
|
|
65
|
+
}),
|
|
66
|
+
snip("data ${Name} = ${Name}\n\t{ ${field} :: ${Type}\n\t} deriving (Show, Eq)", {
|
|
67
|
+
label: "data",
|
|
68
|
+
detail: "record definition",
|
|
69
|
+
type: "keyword"
|
|
70
|
+
}),
|
|
71
|
+
snip("newtype ${Name} = ${Name} ${Type} deriving (Show, Eq)", {
|
|
72
|
+
label: "newtype",
|
|
73
|
+
detail: "definition",
|
|
74
|
+
type: "keyword"
|
|
75
|
+
}),
|
|
76
|
+
snip("type ${Name} = ${Type}", {
|
|
77
|
+
label: "type",
|
|
78
|
+
detail: "synonym",
|
|
79
|
+
type: "keyword"
|
|
80
|
+
}),
|
|
81
|
+
snip("class ${Name} ${a} where\n\t${method} :: ${a} -> ${}", {
|
|
82
|
+
label: "class",
|
|
83
|
+
detail: "definition",
|
|
84
|
+
type: "keyword"
|
|
85
|
+
}),
|
|
86
|
+
snip("instance ${Class} ${Type} where\n\t${method} = ${}", {
|
|
87
|
+
label: "instance",
|
|
88
|
+
detail: "definition",
|
|
89
|
+
type: "keyword"
|
|
90
|
+
}),
|
|
91
|
+
snip("import qualified ${Data.Map} as ${M}", {
|
|
92
|
+
label: "import",
|
|
93
|
+
detail: "qualified",
|
|
94
|
+
type: "keyword"
|
|
95
|
+
}),
|
|
96
|
+
snip("module ${Name} (${exports}) where\n\n${}", {
|
|
97
|
+
label: "module",
|
|
98
|
+
detail: "header",
|
|
99
|
+
type: "keyword"
|
|
100
|
+
})
|
|
101
|
+
];
|
|
102
|
+
/**
|
|
103
|
+
Completes the names declared in the file that are in scope at the cursor:
|
|
104
|
+
top-level functions, types and constructors, parameters, pattern variables,
|
|
105
|
+
and the bindings of `let`, `where` and `do`.
|
|
106
|
+
*/
|
|
107
|
+
declare const localCompletionSource = (context) => {
|
|
108
|
+
var _a, _b;
|
|
109
|
+
const inner = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
110
|
+
if (dontComplete.includes(inner.name))
|
|
111
|
+
return null;
|
|
112
|
+
const word = context.matchBefore(/[\w'\xa1-]+/);
|
|
113
|
+
if (!word && !context.explicit)
|
|
114
|
+
return null;
|
|
115
|
+
// `Map.l` asks for a name out of another module, which this file does not
|
|
116
|
+
// declare.
|
|
117
|
+
const before = context.state.sliceDoc(Math.max(0, ((_a = word === null || word === void 0 ? void 0 : word.from) !== null && _a !== void 0 ? _a : context.pos) - 1), (_b = word === null || word === void 0 ? void 0 : word.from) !== null && _b !== void 0 ? _b : context.pos);
|
|
118
|
+
if (before == ".")
|
|
119
|
+
return null;
|
|
120
|
+
let options = [];
|
|
121
|
+
for (let pos = inner; pos; pos = pos.parent)
|
|
122
|
+
if (ScopeNodes.has(pos.name))
|
|
123
|
+
options = options.concat(getScope(context.state.doc, pos));
|
|
124
|
+
return {
|
|
125
|
+
options,
|
|
126
|
+
from: word ? word.from : context.pos,
|
|
127
|
+
validFor: Identifier
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
declare const haskellLanguage: LRLanguage;
|
|
132
|
+
/**
|
|
133
|
+
Autocompletion for Haskell's keywords, the snippets, and the names the
|
|
134
|
+
Prelude puts in scope whether a file imports anything or not. It offers
|
|
135
|
+
nothing inside strings and comments.
|
|
136
|
+
*/
|
|
137
|
+
declare const haskellCompletion: CompletionSource;
|
|
138
|
+
/**
|
|
139
|
+
Haskell language support, with completion for keywords, snippets, Prelude
|
|
140
|
+
names and the names declared in the file.
|
|
141
|
+
*/
|
|
142
|
+
declare function haskell(): LanguageSupport;
|
|
143
|
+
|
|
144
|
+
export { haskell, haskellCompletion, haskellLanguage, localCompletionSource, parser, snippets };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { LanguageSupport, LRLanguage } from '@codemirror/language';
|
|
3
|
+
import { CompletionSource } from '@codemirror/autocomplete';
|
|
4
|
+
|
|
5
|
+
declare const parser: LRParser
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
Snippets for the constructs people write most often in Haskell.
|
|
9
|
+
*/
|
|
10
|
+
declare const snippets = [
|
|
11
|
+
snip("${name} :: ${Type}\n${name} ${args} = ${}", {
|
|
12
|
+
label: "fun",
|
|
13
|
+
detail: "function with signature",
|
|
14
|
+
type: "keyword"
|
|
15
|
+
}),
|
|
16
|
+
snip("${name} ${args}\n\t| ${condition} = ${}\n\t| otherwise = ${}", {
|
|
17
|
+
label: "guard",
|
|
18
|
+
detail: "function with guards",
|
|
19
|
+
type: "keyword"
|
|
20
|
+
}),
|
|
21
|
+
snip("case ${expression} of\n\t${pattern} -> ${}", {
|
|
22
|
+
label: "case",
|
|
23
|
+
detail: "expression",
|
|
24
|
+
type: "keyword"
|
|
25
|
+
}),
|
|
26
|
+
snip("if ${condition} then ${} else ${}", {
|
|
27
|
+
label: "if",
|
|
28
|
+
detail: "then else",
|
|
29
|
+
type: "keyword"
|
|
30
|
+
}),
|
|
31
|
+
snip("let ${name} = ${value} in ${}", {
|
|
32
|
+
label: "let",
|
|
33
|
+
detail: "in",
|
|
34
|
+
type: "keyword"
|
|
35
|
+
}),
|
|
36
|
+
snip("where\n\t${name} = ${}", {
|
|
37
|
+
label: "where",
|
|
38
|
+
detail: "block",
|
|
39
|
+
type: "keyword"
|
|
40
|
+
}),
|
|
41
|
+
snip("do\n\t${}", {
|
|
42
|
+
label: "do",
|
|
43
|
+
detail: "block",
|
|
44
|
+
type: "keyword"
|
|
45
|
+
}),
|
|
46
|
+
snip("\\${x} -> ${}", {
|
|
47
|
+
label: "\\",
|
|
48
|
+
detail: "lambda",
|
|
49
|
+
type: "keyword"
|
|
50
|
+
}),
|
|
51
|
+
snip("[${expression} | ${x} <- ${list}]", {
|
|
52
|
+
label: "[|]",
|
|
53
|
+
detail: "list comprehension",
|
|
54
|
+
type: "keyword"
|
|
55
|
+
}),
|
|
56
|
+
snip("foldr (\\${x} ${acc} -> ${}) ${initial} ${list}", {
|
|
57
|
+
label: "foldr",
|
|
58
|
+
detail: "fold with a lambda",
|
|
59
|
+
type: "keyword"
|
|
60
|
+
}),
|
|
61
|
+
snip("data ${Name} = ${Constructor} deriving (Show, Eq)", {
|
|
62
|
+
label: "data",
|
|
63
|
+
detail: "type definition",
|
|
64
|
+
type: "keyword"
|
|
65
|
+
}),
|
|
66
|
+
snip("data ${Name} = ${Name}\n\t{ ${field} :: ${Type}\n\t} deriving (Show, Eq)", {
|
|
67
|
+
label: "data",
|
|
68
|
+
detail: "record definition",
|
|
69
|
+
type: "keyword"
|
|
70
|
+
}),
|
|
71
|
+
snip("newtype ${Name} = ${Name} ${Type} deriving (Show, Eq)", {
|
|
72
|
+
label: "newtype",
|
|
73
|
+
detail: "definition",
|
|
74
|
+
type: "keyword"
|
|
75
|
+
}),
|
|
76
|
+
snip("type ${Name} = ${Type}", {
|
|
77
|
+
label: "type",
|
|
78
|
+
detail: "synonym",
|
|
79
|
+
type: "keyword"
|
|
80
|
+
}),
|
|
81
|
+
snip("class ${Name} ${a} where\n\t${method} :: ${a} -> ${}", {
|
|
82
|
+
label: "class",
|
|
83
|
+
detail: "definition",
|
|
84
|
+
type: "keyword"
|
|
85
|
+
}),
|
|
86
|
+
snip("instance ${Class} ${Type} where\n\t${method} = ${}", {
|
|
87
|
+
label: "instance",
|
|
88
|
+
detail: "definition",
|
|
89
|
+
type: "keyword"
|
|
90
|
+
}),
|
|
91
|
+
snip("import qualified ${Data.Map} as ${M}", {
|
|
92
|
+
label: "import",
|
|
93
|
+
detail: "qualified",
|
|
94
|
+
type: "keyword"
|
|
95
|
+
}),
|
|
96
|
+
snip("module ${Name} (${exports}) where\n\n${}", {
|
|
97
|
+
label: "module",
|
|
98
|
+
detail: "header",
|
|
99
|
+
type: "keyword"
|
|
100
|
+
})
|
|
101
|
+
];
|
|
102
|
+
/**
|
|
103
|
+
Completes the names declared in the file that are in scope at the cursor:
|
|
104
|
+
top-level functions, types and constructors, parameters, pattern variables,
|
|
105
|
+
and the bindings of `let`, `where` and `do`.
|
|
106
|
+
*/
|
|
107
|
+
declare const localCompletionSource = (context) => {
|
|
108
|
+
var _a, _b;
|
|
109
|
+
const inner = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
110
|
+
if (dontComplete.includes(inner.name))
|
|
111
|
+
return null;
|
|
112
|
+
const word = context.matchBefore(/[\w'\xa1-]+/);
|
|
113
|
+
if (!word && !context.explicit)
|
|
114
|
+
return null;
|
|
115
|
+
// `Map.l` asks for a name out of another module, which this file does not
|
|
116
|
+
// declare.
|
|
117
|
+
const before = context.state.sliceDoc(Math.max(0, ((_a = word === null || word === void 0 ? void 0 : word.from) !== null && _a !== void 0 ? _a : context.pos) - 1), (_b = word === null || word === void 0 ? void 0 : word.from) !== null && _b !== void 0 ? _b : context.pos);
|
|
118
|
+
if (before == ".")
|
|
119
|
+
return null;
|
|
120
|
+
let options = [];
|
|
121
|
+
for (let pos = inner; pos; pos = pos.parent)
|
|
122
|
+
if (ScopeNodes.has(pos.name))
|
|
123
|
+
options = options.concat(getScope(context.state.doc, pos));
|
|
124
|
+
return {
|
|
125
|
+
options,
|
|
126
|
+
from: word ? word.from : context.pos,
|
|
127
|
+
validFor: Identifier
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
declare const haskellLanguage: LRLanguage;
|
|
132
|
+
/**
|
|
133
|
+
Autocompletion for Haskell's keywords, the snippets, and the names the
|
|
134
|
+
Prelude puts in scope whether a file imports anything or not. It offers
|
|
135
|
+
nothing inside strings and comments.
|
|
136
|
+
*/
|
|
137
|
+
declare const haskellCompletion: CompletionSource;
|
|
138
|
+
/**
|
|
139
|
+
Haskell language support, with completion for keywords, snippets, Prelude
|
|
140
|
+
names and the names declared in the file.
|
|
141
|
+
*/
|
|
142
|
+
declare function haskell(): LanguageSupport;
|
|
143
|
+
|
|
144
|
+
export { haskell, haskellCompletion, haskellLanguage, localCompletionSource, parser, snippets };
|