@exercism/codemirror-lang-pharo-smalltalk 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +106 -2
- package/dist/index.cjs +476 -0
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +467 -0
- package/package.json +51 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2024 by Erik Schierboom <erik_schierboom@hotmail.com> and others
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,107 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Pharo Smalltalk language support for CodeMirror
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This package gives the CodeMirror 6 editor a Lezer grammar for Pharo Smalltalk, with highlighting, indentation, folding and autocompletion.
|
|
6
|
+
Exercism uses it in the in-browser editor for the Pharo Smalltalk track.
|
|
7
|
+
|
|
8
|
+
The grammar reads Tonel, the file format Pharo uses for source code in Git and the one Exercism's solutions are in.
|
|
9
|
+
A Tonel file holds a class definition such as `Class { #name : #Clock, ... }`, followed by methods such as `Clock >> hour [ ^ hour ]`.
|
|
10
|
+
|
|
11
|
+
⚠️ To keep the package working on the Exercism website, don't change the versions of these packages:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
"@codemirror/language": "^6.10.1",
|
|
15
|
+
"@lezer/highlight": "^1.2.0",
|
|
16
|
+
"@lezer/lr": "^1.4.0"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
- NPM: `npm install @exercism/codemirror-lang-pharo-smalltalk`
|
|
22
|
+
- Yarn: `yarn add @exercism/codemirror-lang-pharo-smalltalk`
|
|
23
|
+
- Bun: `bun add @exercism/codemirror-lang-pharo-smalltalk`
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { EditorView, basicSetup } from "codemirror";
|
|
29
|
+
import { pharoSmalltalk } from "@exercism/codemirror-lang-pharo-smalltalk";
|
|
30
|
+
|
|
31
|
+
new EditorView({
|
|
32
|
+
extensions: [basicSetup, pharoSmalltalk()],
|
|
33
|
+
parent: document.body,
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## What it does
|
|
38
|
+
|
|
39
|
+
- It reads class definitions (`Class`, `Trait` and `Extension`), method categories such as `{ #category : #accessing }`, and unary, binary and keyword methods on the instance side and the class side.
|
|
40
|
+
- Inside a method it reads temporaries, pragmas such as `<primitive: 60>`, assignments, returns, unary, binary and keyword messages, cascades, blocks, dynamic arrays and every kind of literal, including literal arrays, byte arrays, radix numbers such as `16r1F` and scaled decimals.
|
|
41
|
+
- It highlights comments, strings, characters, symbols, numbers, pseudo-variables such as `self` and `nil`, class names, method and parameter definitions, message selectors, operators and pragmas.
|
|
42
|
+
- It indents a new line inside a method, a block, a class definition or an array, and folds each of them.
|
|
43
|
+
- Its autocompletion offers:
|
|
44
|
+
- between methods, snippets for a class definition, an extension and a method, and the names of classes.
|
|
45
|
+
- after a receiver, the selectors of the methods in the file, common selectors such as `printString` and `includes:`, and snippets for messages that take blocks, such as `ifTrue:ifFalse:`, `do:`, `collect:`, `select:`, `inject:into:` and `to:do:`.
|
|
46
|
+
- where an expression starts, the names in scope: the method's parameters and temporaries, the parameters and temporaries of the blocks around the cursor, the class's instance and class variables, the classes in the file, common classes such as `OrderedCollection`, and the pseudo-variables.
|
|
47
|
+
|
|
48
|
+
The grammar can't look ahead to spot keywords, so the tokenizer in `src/tokens.ts` reads each name itself.
|
|
49
|
+
It reads `at:` as a keyword, and in `x:=1` it reads the colon as part of the assignment.
|
|
50
|
+
The tokenizer also gives capitalised names their own token, because Smalltalk writes classes and other globals with a capital letter.
|
|
51
|
+
|
|
52
|
+
## Prerequisites
|
|
53
|
+
|
|
54
|
+
- [Bun](https://bun.sh/)
|
|
55
|
+
|
|
56
|
+
## Resources
|
|
57
|
+
|
|
58
|
+
- [CodeMirror](https://codemirror.net/docs/)
|
|
59
|
+
- [Lezer](https://lezer.codemirror.net/docs/guide/)
|
|
60
|
+
- [The Tonel format](https://github.com/pharo-vcs/tonel)
|
|
61
|
+
|
|
62
|
+
## Structure
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
.
|
|
66
|
+
├── src
|
|
67
|
+
│ ├── index.ts (the language, its highlighting, indentation and folding)
|
|
68
|
+
│ ├── complete.ts (the autocompletion)
|
|
69
|
+
│ ├── tokens.ts (the tokenizer for names and keywords)
|
|
70
|
+
│ └── syntax.grammar (the Lezer grammar)
|
|
71
|
+
├── test
|
|
72
|
+
│ ├── cases (grammar test cases)
|
|
73
|
+
│ ├── grammar.test.ts
|
|
74
|
+
│ ├── completion.test.ts
|
|
75
|
+
│ └── editor.test.ts (highlighting, indentation and folding)
|
|
76
|
+
├── index.html (dev server file)
|
|
77
|
+
├── rollup.config.js (bundling config)
|
|
78
|
+
├── tsconfig.json (typescript config)
|
|
79
|
+
└── vite.config.js (vite dev server config)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Setup
|
|
83
|
+
|
|
84
|
+
Run `bun install` to install all dependencies.
|
|
85
|
+
|
|
86
|
+
## Developing
|
|
87
|
+
|
|
88
|
+
Run `bun run dev` to start a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/).
|
|
89
|
+
It renders `index.html`, which shows an editor with some sample code.
|
|
90
|
+
The page reloads whenever the grammar changes.
|
|
91
|
+
|
|
92
|
+
## Building
|
|
93
|
+
|
|
94
|
+
Run `bun run prepare` to build the package into `dist/`.
|
|
95
|
+
It runs Rollup under Bun's runtime, because one of the Rollup plugins doesn't load in recent versions of Node.
|
|
96
|
+
|
|
97
|
+
## Testing
|
|
98
|
+
|
|
99
|
+
Run `bun run test`.
|
|
100
|
+
It builds the package and then runs the tests, because the grammar tests need the built tokenizer.
|
|
101
|
+
|
|
102
|
+
## Publishing
|
|
103
|
+
|
|
104
|
+
To publish a new version, set `version` in `package.json` and commit it.
|
|
105
|
+
Then push a tag made of `v` followed by that version, for example `v1.0.0`.
|
|
106
|
+
The tag starts the Publish workflow, which builds and tests the package and publishes it to npm.
|
|
107
|
+
If the tag differs from `version`, the workflow stops before it publishes.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var lr = require('@lezer/lr');
|
|
4
|
+
var language = require('@codemirror/language');
|
|
5
|
+
var highlight = require('@lezer/highlight');
|
|
6
|
+
var autocomplete = require('@codemirror/autocomplete');
|
|
7
|
+
|
|
8
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
9
|
+
const Identifier = 1,
|
|
10
|
+
GlobalName = 2,
|
|
11
|
+
Keyword = 3;
|
|
12
|
+
|
|
13
|
+
const colon = 58, equals = 61, underscore = 95;
|
|
14
|
+
function isLetter(ch) {
|
|
15
|
+
return (ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122);
|
|
16
|
+
}
|
|
17
|
+
function isIdentChar(ch) {
|
|
18
|
+
return isLetter(ch) || (ch >= 48 && ch <= 57) || ch == underscore;
|
|
19
|
+
}
|
|
20
|
+
// Reads a name. `at:` is a keyword, but in `x:=1` the colon belongs to the
|
|
21
|
+
// assignment, so `x` stays a name. A name that starts with a capital letter,
|
|
22
|
+
// such as `OrderedCollection`, is a global.
|
|
23
|
+
const identifiers = new lr.ExternalTokenizer((input) => {
|
|
24
|
+
const first = input.next;
|
|
25
|
+
if (!isLetter(first) && first != underscore)
|
|
26
|
+
return;
|
|
27
|
+
while (isIdentChar(input.next))
|
|
28
|
+
input.advance();
|
|
29
|
+
if (input.next == colon && input.peek(1) != equals) {
|
|
30
|
+
input.advance();
|
|
31
|
+
input.acceptToken(Keyword);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
input.acceptToken(first >= 65 && first <= 90 ? GlobalName : Identifier);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
39
|
+
const spec_BinaryOp = {__proto__:null,"-":194, ">>":204, "<":210, ">":212};
|
|
40
|
+
const spec_Identifier = {__proto__:null,nil:198, true:200, false:202, self:236, super:238, thisContext:240};
|
|
41
|
+
const parser = lr.LRParser.deserialize({
|
|
42
|
+
version: 14,
|
|
43
|
+
states: "8fQYQROOOeQRO'#CcOpQQO'#CfOxQQO'#CbOOQP'#Cv'#CvOOQP'#E^'#E^OOQP'#Dz'#DzQYQROOO}QRO'#CwOOQP'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R#^!bQ#{!yR$o#{Q#V!]Q$R#RT$U#V$RQ#P![S$O#P$SR$S#SQ#[!`R$W#[Y!v!T!b!g!h$_R#v!vQ#b!gR$]#bY#o!m#q$f$h$uR$d#oQ#r!pR$k#rQ$f#qR$t$fQ$h#qQ$u$fT$w$h$uTUOVR[QQgYQxbQzhV!{!W!|#}RybSn`wS!Pruh!_!T!b!g!h!i!r!v#`#k#n#z$_S#Y!`#[W#g!k#q$b$fQ#x!yR$Z#aSp`w]#j!m#q$c$f$h$uQ!x!TQ#d!gR$s$_R$n#zf!j!T!b!g!h!i!r!v#`#k#n$_R$m#zX#U!]#R#V$RU!w!T!g$_Q#_!bR#e!hY!u!T!b!g!h$_R#u!v[!s!T!b!g!h!v$_Q#f!iQ#s!rR$Y#`c!p!T!b!g!h!i!r!v#`$_b!m!T!b!g!h!i!r!v#`$_R$c#nd!k!T!b!g!h!i!r!v#`#n$_R$b#kR$j#q",
|
|
46
|
+
nodeNames: "⚠ Identifier GlobalName Keyword Comment Program ClassDefinition DefinitionKind } { StonMap StonEntry StonKey Symbol : String Number NegativeNumber BinaryOp ] [ StonList , Nil True False Metadata MethodDefinition MethodClass ClassSide MethodPattern MethodName BinarySelectorName | ParameterName KeywordName MethodBody Pragma PragmaName PragmaKeyword Character ) #( LiteralArray #[ ByteArray ( InnerArray InnerByteArray VariableName Temporaries TemporaryName ReturnStatement ^ Assignment := Cascade Self Super ThisContext Block BlockParameters BlockParameterName DynamicArray ParenthesizedExpression UnarySend UnaryMessage UnarySelector BinarySend BinaryMessage BinarySelector KeywordSend KeywordMessage KeywordSelector ; .",
|
|
47
|
+
maxTerm: 121,
|
|
48
|
+
nodeProps: [
|
|
49
|
+
["openedBy", 8,"{",19,"[ #[",41,"#( ("],
|
|
50
|
+
["closedBy", 9,"}",-2,20,44,"]",-2,42,46,")"]
|
|
51
|
+
],
|
|
52
|
+
skippedNodes: [0,4],
|
|
53
|
+
repeatNodeCount: 15,
|
|
54
|
+
tokenData: "3j~RyX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-{x;'S-i;'S;=`.T<%lO-i~.QP_~wx-i~.WP;=`<%l-i~.`O!O~~.eOy~~.jOf~~.oO!m~~.tV`~!O!P/Z!Q![.o#W#X/u#X#Y/u#e#f/u#f#g0i#g#h0a~/^P!Q![/a~/fT`~!Q![/a#W#X/u#X#Y/u#e#f/u#g#h0a~/xQ}!O0O!Q![0U~0RP!Q![0U~0ZQ`~!Q![0U#g#h0a~0fP`~!Q![0a~0lR!Q![0u!c!}0u#T#o0u~0zZ`~!O!P/Z!Q![0u!c!}0u#T#W0u#W#X1m#X#Y1m#Y#e0u#e#f1m#f#g0u#g#h0u#h#o0u~1r[`~}!O0O!O!P/Z!Q![0u!c!}0u#T#W0u#W#X1m#X#Y1m#Y#e0u#e#f1m#f#g0u#g#h0u#h#o0uR2mP^P!_!`2pQ2uO!XQ~2zO!l~~3POd~~3UOc~~3ZO!V~~3`OX~~3eOq~~3jOW~",
|
|
55
|
+
tokenizers: [identifiers, 0, 1],
|
|
56
|
+
topRules: {"Program":[0,5]},
|
|
57
|
+
specialized: [{term: 18, get: (value) => spec_BinaryOp[value] || -1},{term: 1, get: (value) => spec_Identifier[value] || -1}],
|
|
58
|
+
tokenPrec: 0
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/// Snippets for a class definition and a method, offered between methods.
|
|
62
|
+
const topLevelSnippets = [
|
|
63
|
+
autocomplete.snippetCompletion("Class {\n\t#name : #${Name},\n\t#superclass : #${Object},\n\t#instVars : [\n\t\t'${variable}'\n\t],\n\t#category : #'${Category}'\n}\n", { label: "Class", detail: "class definition", type: "keyword" }),
|
|
64
|
+
autocomplete.snippetCompletion("Extension { #name : #${Class} }\n", {
|
|
65
|
+
label: "Extension",
|
|
66
|
+
detail: "extend a class",
|
|
67
|
+
type: "keyword",
|
|
68
|
+
}),
|
|
69
|
+
autocomplete.snippetCompletion("{ #category : #'${category}' }\n${Class} >> ${selector} [\n\n\t${}\n]\n", {
|
|
70
|
+
label: "method",
|
|
71
|
+
detail: "with category",
|
|
72
|
+
type: "keyword",
|
|
73
|
+
}),
|
|
74
|
+
autocomplete.snippetCompletion("{ #category : #'${category}' }\n${Class} class >> ${selector} [\n\n\t${}\n]\n", {
|
|
75
|
+
label: "class method",
|
|
76
|
+
detail: "with category",
|
|
77
|
+
type: "keyword",
|
|
78
|
+
}),
|
|
79
|
+
autocomplete.snippetCompletion("{ #category : #'${category}' }", {
|
|
80
|
+
label: "category",
|
|
81
|
+
detail: "method metadata",
|
|
82
|
+
type: "keyword",
|
|
83
|
+
}),
|
|
84
|
+
];
|
|
85
|
+
/// Snippets for messages with block arguments, offered after a receiver.
|
|
86
|
+
const selectorSnippets = [
|
|
87
|
+
autocomplete.snippetCompletion("ifTrue: [ ${} ]", { label: "ifTrue:", type: "method" }),
|
|
88
|
+
autocomplete.snippetCompletion("ifFalse: [ ${} ]", { label: "ifFalse:", type: "method" }),
|
|
89
|
+
autocomplete.snippetCompletion("ifTrue: [ ${} ] ifFalse: [ ${} ]", { label: "ifTrue:ifFalse:", type: "method" }),
|
|
90
|
+
autocomplete.snippetCompletion("ifFalse: [ ${} ] ifTrue: [ ${} ]", { label: "ifFalse:ifTrue:", type: "method" }),
|
|
91
|
+
autocomplete.snippetCompletion("ifNil: [ ${} ]", { label: "ifNil:", type: "method" }),
|
|
92
|
+
autocomplete.snippetCompletion("ifNotNil: [ :${it} | ${} ]", { label: "ifNotNil:", type: "method" }),
|
|
93
|
+
autocomplete.snippetCompletion("ifNil: [ ${} ] ifNotNil: [ :${it} | ${} ]", { label: "ifNil:ifNotNil:", type: "method" }),
|
|
94
|
+
autocomplete.snippetCompletion("ifEmpty: [ ${} ]", { label: "ifEmpty:", type: "method" }),
|
|
95
|
+
autocomplete.snippetCompletion("ifEmpty: [ ${} ] ifNotEmpty: [ :${it} | ${} ]", {
|
|
96
|
+
label: "ifEmpty:ifNotEmpty:",
|
|
97
|
+
type: "method",
|
|
98
|
+
}),
|
|
99
|
+
autocomplete.snippetCompletion("and: [ ${} ]", { label: "and:", type: "method" }),
|
|
100
|
+
autocomplete.snippetCompletion("or: [ ${} ]", { label: "or:", type: "method" }),
|
|
101
|
+
autocomplete.snippetCompletion("do: [ :${each} | ${} ]", { label: "do:", type: "method" }),
|
|
102
|
+
autocomplete.snippetCompletion("do: [ :${each} | ${} ] separatedBy: [ ${} ]", { label: "do:separatedBy:", type: "method" }),
|
|
103
|
+
autocomplete.snippetCompletion("doWithIndex: [ :${each} :${index} | ${} ]", { label: "doWithIndex:", type: "method" }),
|
|
104
|
+
autocomplete.snippetCompletion("withIndexDo: [ :${each} :${index} | ${} ]", { label: "withIndexDo:", type: "method" }),
|
|
105
|
+
autocomplete.snippetCompletion("keysAndValuesDo: [ :${key} :${value} | ${} ]", { label: "keysAndValuesDo:", type: "method" }),
|
|
106
|
+
autocomplete.snippetCompletion("reverseDo: [ :${each} | ${} ]", { label: "reverseDo:", type: "method" }),
|
|
107
|
+
autocomplete.snippetCompletion("collect: [ :${each} | ${} ]", { label: "collect:", type: "method" }),
|
|
108
|
+
autocomplete.snippetCompletion("withIndexCollect: [ :${each} :${index} | ${} ]", { label: "withIndexCollect:", type: "method" }),
|
|
109
|
+
autocomplete.snippetCompletion("select: [ :${each} | ${} ]", { label: "select:", type: "method" }),
|
|
110
|
+
autocomplete.snippetCompletion("reject: [ :${each} | ${} ]", { label: "reject:", type: "method" }),
|
|
111
|
+
autocomplete.snippetCompletion("detect: [ :${each} | ${} ]", { label: "detect:", type: "method" }),
|
|
112
|
+
autocomplete.snippetCompletion("detect: [ :${each} | ${} ] ifNone: [ ${} ]", { label: "detect:ifNone:", type: "method" }),
|
|
113
|
+
autocomplete.snippetCompletion("anySatisfy: [ :${each} | ${} ]", { label: "anySatisfy:", type: "method" }),
|
|
114
|
+
autocomplete.snippetCompletion("allSatisfy: [ :${each} | ${} ]", { label: "allSatisfy:", type: "method" }),
|
|
115
|
+
autocomplete.snippetCompletion("count: [ :${each} | ${} ]", { label: "count:", type: "method" }),
|
|
116
|
+
autocomplete.snippetCompletion("inject: ${0} into: [ :${sum} :${each} | ${} ]", { label: "inject:into:", type: "method" }),
|
|
117
|
+
autocomplete.snippetCompletion("sort: [ :${a} :${b} | ${a} < ${b} ]", { label: "sort:", type: "method" }),
|
|
118
|
+
autocomplete.snippetCompletion("sorted: [ :${a} :${b} | ${a} < ${b} ]", { label: "sorted:", type: "method" }),
|
|
119
|
+
autocomplete.snippetCompletion("to: ${end} do: [ :${i} | ${} ]", { label: "to:do:", type: "method" }),
|
|
120
|
+
autocomplete.snippetCompletion("to: ${end} by: ${step} do: [ :${i} | ${} ]", { label: "to:by:do:", type: "method" }),
|
|
121
|
+
autocomplete.snippetCompletion("timesRepeat: [ ${} ]", { label: "timesRepeat:", type: "method" }),
|
|
122
|
+
autocomplete.snippetCompletion("whileTrue: [ ${} ]", { label: "whileTrue:", type: "method" }),
|
|
123
|
+
autocomplete.snippetCompletion("whileFalse: [ ${} ]", { label: "whileFalse:", type: "method" }),
|
|
124
|
+
autocomplete.snippetCompletion("at: ${key} ifAbsent: [ ${} ]", { label: "at:ifAbsent:", type: "method" }),
|
|
125
|
+
autocomplete.snippetCompletion("at: ${key} ifAbsentPut: [ ${} ]", { label: "at:ifAbsentPut:", type: "method" }),
|
|
126
|
+
autocomplete.snippetCompletion("at: ${key} ifPresent: [ :${value} | ${} ]", { label: "at:ifPresent:", type: "method" }),
|
|
127
|
+
autocomplete.snippetCompletion("on: ${Error} do: [ :${error} | ${} ]", { label: "on:do:", type: "method" }),
|
|
128
|
+
autocomplete.snippetCompletion("ensure: [ ${} ]", { label: "ensure:", type: "method" }),
|
|
129
|
+
];
|
|
130
|
+
/// Snippets offered where an expression starts.
|
|
131
|
+
const expressionSnippets = [
|
|
132
|
+
autocomplete.snippetCompletion("[ :${each} | ${} ]", { label: "block", detail: "[ :each | ]", type: "keyword" }),
|
|
133
|
+
autocomplete.snippetCompletion("| ${temp} |", { label: "temps", detail: "| temp |", type: "keyword" }),
|
|
134
|
+
autocomplete.snippetCompletion("String streamContents: [ :${stream} | ${} ]", {
|
|
135
|
+
label: "streamContents:",
|
|
136
|
+
detail: "build a string",
|
|
137
|
+
type: "keyword",
|
|
138
|
+
}),
|
|
139
|
+
];
|
|
140
|
+
/// Snippets for the language's common constructs.
|
|
141
|
+
const snippets = [
|
|
142
|
+
...topLevelSnippets,
|
|
143
|
+
...selectorSnippets,
|
|
144
|
+
...expressionSnippets,
|
|
145
|
+
];
|
|
146
|
+
const pseudoVariables = ["self", "super", "thisContext", "nil", "true", "false"].map((label) => ({ label, type: "keyword" }));
|
|
147
|
+
const classNames = ("Object Boolean True False UndefinedObject Magnitude Number Integer SmallInteger " +
|
|
148
|
+
"LargePositiveInteger Float Fraction ScaledDecimal Character String Symbol " +
|
|
149
|
+
"Collection SequenceableCollection ArrayedCollection Array ByteArray Interval " +
|
|
150
|
+
"OrderedCollection SortedCollection LinkedList Set IdentitySet Bag Dictionary " +
|
|
151
|
+
"IdentityDictionary OrderedDictionary SmallDictionary Association Point Rectangle " +
|
|
152
|
+
"Array2D Matrix Stream ReadStream WriteStream ReadWriteStream Transcript Smalltalk " +
|
|
153
|
+
"Date Time DateAndTime Duration Random Error Exception ZeroDivide DomainError " +
|
|
154
|
+
"NotFound KeyNotFound SubscriptOutOfBounds ArithmeticError MessageNotUnderstood " +
|
|
155
|
+
"Warning AssertionFailure TestCase Generator CharacterSet Color")
|
|
156
|
+
.split(" ")
|
|
157
|
+
.map((label) => ({ label, type: "class" }));
|
|
158
|
+
const unarySelectors = ("new value printString displayString asString asSymbol asNumber asInteger asFloat " +
|
|
159
|
+
"asArray asOrderedCollection asSet asBag asSortedCollection asDictionary asUppercase " +
|
|
160
|
+
"asLowercase asCharacter asCharacterDigit asByteArray size isEmpty notEmpty isNotEmpty " +
|
|
161
|
+
"isEmptyOrNil isNil notNil first last allButFirst allButLast reversed reverse sum max min " +
|
|
162
|
+
"abs negated squared sqrt floor ceiling rounded truncated isZero even odd isPrime " +
|
|
163
|
+
"isInteger isNumber isString isSymbol isCharacter isLetter isDigit isVowel isUppercase " +
|
|
164
|
+
"isLowercase isSeparator digitValue keys values associations key copy yourself hash " +
|
|
165
|
+
"class name trimBoth trimmed lines substrings asSortedCollection anyOne removeFirst " +
|
|
166
|
+
"removeLast sign factorial not signal initialize cr tab space contents readStream " +
|
|
167
|
+
"writeStream upToEnd next atEnd peek skip")
|
|
168
|
+
.split(" ")
|
|
169
|
+
.map((label) => ({ label, type: "method" }));
|
|
170
|
+
const keywordSelectors = ("at: at:put: add: addAll: addFirst: addLast: remove: remove:ifAbsent: removeKey: " +
|
|
171
|
+
"removeAll: includes: includesKey: includesSubstring: indexOf: occurrencesOf: " +
|
|
172
|
+
"copyFrom:to: copyWith: copyWithout: copyReplaceAll:with: , with: with:with: " +
|
|
173
|
+
"with:collect: new: new:withAll: withAll: newFrom: value: value:value: valueWithArguments: " +
|
|
174
|
+
"printOn: printString: printPaddedWith:to: nextPut: nextPutAll: print: join: " +
|
|
175
|
+
"streamContents: splitOn: substrings: raisedTo: gcd: lcm: max: min: between:and: " +
|
|
176
|
+
"isDivisibleBy: \\\\ // rem: quo: bitAnd: bitOr: bitXor: bitAt: bitShift: " +
|
|
177
|
+
"first: last: allButFirst: allButLast: groupedBy: asStringWithCommas " +
|
|
178
|
+
"signal: error: assert: assert:equals: deny: should:raise: format: " +
|
|
179
|
+
"perform: perform:with: respondsTo: isKindOf: isMemberOf: = == ~= ~~ -> " +
|
|
180
|
+
"readFrom: subclass:instanceVariableNames:classVariableNames:package:")
|
|
181
|
+
.split(" ")
|
|
182
|
+
.filter((label) => label.endsWith(":"))
|
|
183
|
+
.map((label) => ({ label, type: "method" }));
|
|
184
|
+
const commonSelectors = [
|
|
185
|
+
...selectorSnippets,
|
|
186
|
+
...unarySelectors,
|
|
187
|
+
...keywordSelectors.filter((option) => !selectorSnippets.some((s) => s.label == option.label)),
|
|
188
|
+
];
|
|
189
|
+
const wordBefore = /[A-Za-z_][A-Za-z0-9_]*$/;
|
|
190
|
+
// Nodes where the name being typed is a new name, or isn't code at all.
|
|
191
|
+
const noCompletion = new Set([
|
|
192
|
+
"Comment",
|
|
193
|
+
"String",
|
|
194
|
+
"Symbol",
|
|
195
|
+
"Character",
|
|
196
|
+
"Number",
|
|
197
|
+
"Temporaries",
|
|
198
|
+
"BlockParameters",
|
|
199
|
+
"MethodPattern",
|
|
200
|
+
"LiteralArray",
|
|
201
|
+
"ByteArray",
|
|
202
|
+
"StonMap",
|
|
203
|
+
]);
|
|
204
|
+
function ancestors(node) {
|
|
205
|
+
const found = [];
|
|
206
|
+
for (let at = node; at; at = at.parent)
|
|
207
|
+
found.push(at);
|
|
208
|
+
return found;
|
|
209
|
+
}
|
|
210
|
+
function text(state, node) {
|
|
211
|
+
return state.sliceDoc(node.from, node.to);
|
|
212
|
+
}
|
|
213
|
+
function childNames(state, parent, container, name) {
|
|
214
|
+
const names = [];
|
|
215
|
+
for (let child = parent.firstChild; child; child = child.nextSibling) {
|
|
216
|
+
if (child.name != container)
|
|
217
|
+
continue;
|
|
218
|
+
for (const node of child.getChildren(name))
|
|
219
|
+
names.push(text(state, node));
|
|
220
|
+
}
|
|
221
|
+
return names;
|
|
222
|
+
}
|
|
223
|
+
const stonNameKeys = /^#(name|instVars|classVars|classInstVars|pools)\s*:?$/;
|
|
224
|
+
/// The class names and the variables declared by the class definitions in the
|
|
225
|
+
/// file. Tonel lists variables as strings, as in `#instVars : [ 'count' ]`.
|
|
226
|
+
function classDeclarations(state) {
|
|
227
|
+
const classes = [];
|
|
228
|
+
const variables = [];
|
|
229
|
+
const top = language.syntaxTree(state).topNode;
|
|
230
|
+
for (const definition of top.getChildren("ClassDefinition")) {
|
|
231
|
+
const map = definition.getChild("StonMap");
|
|
232
|
+
if (!map)
|
|
233
|
+
continue;
|
|
234
|
+
for (const entry of map.getChildren("StonEntry")) {
|
|
235
|
+
const key = entry.getChild("StonKey");
|
|
236
|
+
const keyText = key ? text(state, key) : "";
|
|
237
|
+
const match = stonNameKeys.exec(keyText);
|
|
238
|
+
if (!match)
|
|
239
|
+
continue;
|
|
240
|
+
if (match[1] == "name") {
|
|
241
|
+
const value = entry.lastChild;
|
|
242
|
+
if (value && value != key)
|
|
243
|
+
classes.push(text(state, value).replace(/^#'?|'$/g, ""));
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
const list = entry.getChild("StonList");
|
|
247
|
+
if (!list)
|
|
248
|
+
continue;
|
|
249
|
+
for (const s of list.getChildren("String")) {
|
|
250
|
+
for (const name of text(state, s).slice(1, -1).split(/\s+/))
|
|
251
|
+
if (name)
|
|
252
|
+
variables.push(name);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return { classes, variables };
|
|
258
|
+
}
|
|
259
|
+
/// The selectors of the methods defined in the file, such as `at:put:`.
|
|
260
|
+
function definedSelectors(state) {
|
|
261
|
+
var _a;
|
|
262
|
+
const selectors = new Set();
|
|
263
|
+
const top = language.syntaxTree(state).topNode;
|
|
264
|
+
for (const method of top.getChildren("MethodDefinition")) {
|
|
265
|
+
const pattern = method.getChild("MethodPattern");
|
|
266
|
+
if (!pattern)
|
|
267
|
+
continue;
|
|
268
|
+
const parts = pattern.getChildren("KeywordName").map((node) => text(state, node));
|
|
269
|
+
const name = (_a = pattern.getChild("MethodName")) !== null && _a !== void 0 ? _a : pattern.getChild("BinarySelectorName");
|
|
270
|
+
if (parts.length)
|
|
271
|
+
selectors.add(parts.join(""));
|
|
272
|
+
else if (name)
|
|
273
|
+
selectors.add(text(state, name));
|
|
274
|
+
}
|
|
275
|
+
return [...selectors];
|
|
276
|
+
}
|
|
277
|
+
/// The names in scope at a position inside a method: its parameters, its
|
|
278
|
+
/// temporaries, and the parameters and temporaries of the blocks around it.
|
|
279
|
+
function localNames(state, node) {
|
|
280
|
+
const names = [];
|
|
281
|
+
for (const at of ancestors(node)) {
|
|
282
|
+
if (at.name == "Block") {
|
|
283
|
+
names.push(...childNames(state, at, "BlockParameters", "BlockParameterName"));
|
|
284
|
+
names.push(...childNames(state, at, "Temporaries", "TemporaryName"));
|
|
285
|
+
}
|
|
286
|
+
else if (at.name == "MethodBody") {
|
|
287
|
+
names.push(...childNames(state, at, "Temporaries", "TemporaryName"));
|
|
288
|
+
}
|
|
289
|
+
else if (at.name == "MethodDefinition") {
|
|
290
|
+
const pattern = at.getChild("MethodPattern");
|
|
291
|
+
if (pattern)
|
|
292
|
+
for (const p of pattern.getChildren("ParameterName"))
|
|
293
|
+
names.push(text(state, p));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return names;
|
|
297
|
+
}
|
|
298
|
+
// A word typed straight after a receiver is a message selector, as in
|
|
299
|
+
// `items si‸`. After a keyword, an operator, `:=`, `^`, a period or an opening
|
|
300
|
+
// bracket, it starts an expression.
|
|
301
|
+
function isSelectorPosition(state, from) {
|
|
302
|
+
const before = state.sliceDoc(Math.max(0, from - 200), from).replace(/\s+$/, "");
|
|
303
|
+
if (!before)
|
|
304
|
+
return false;
|
|
305
|
+
const last = before[before.length - 1];
|
|
306
|
+
if (/[A-Za-z0-9_]/.test(last)) {
|
|
307
|
+
const word = /[A-Za-z_][A-Za-z0-9_]*$/.exec(before);
|
|
308
|
+
// `x foo: 3 ba‸` and `^ self ba‸` both follow a receiver, but `ifTrue:` ends
|
|
309
|
+
// in a colon and so does not get here.
|
|
310
|
+
return !(word && /[:#$]$/.test(before.slice(0, before.length - word[0].length)));
|
|
311
|
+
}
|
|
312
|
+
return /['\)\]\}]/.test(last);
|
|
313
|
+
}
|
|
314
|
+
function unique(options) {
|
|
315
|
+
const seen = new Set();
|
|
316
|
+
return options.filter((option) => {
|
|
317
|
+
if (seen.has(option.label))
|
|
318
|
+
return false;
|
|
319
|
+
seen.add(option.label);
|
|
320
|
+
return true;
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
/// Completion between methods: the class definition and method snippets, and
|
|
324
|
+
/// the class names a method header can start with.
|
|
325
|
+
function topLevelCompletionSource(context) {
|
|
326
|
+
const word = context.matchBefore(wordBefore);
|
|
327
|
+
if (!word && !context.explicit)
|
|
328
|
+
return null;
|
|
329
|
+
const inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
330
|
+
const path = ancestors(inner);
|
|
331
|
+
if (path.some((node) => node.name == "MethodBody" || noCompletion.has(node.name)))
|
|
332
|
+
return null;
|
|
333
|
+
const { classes } = classDeclarations(context.state);
|
|
334
|
+
return {
|
|
335
|
+
from: word ? word.from : context.pos,
|
|
336
|
+
options: unique([
|
|
337
|
+
...topLevelSnippets,
|
|
338
|
+
...classes.map((label) => ({ label, type: "class" })),
|
|
339
|
+
...classNames,
|
|
340
|
+
]),
|
|
341
|
+
validFor: /^\w*$/,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
/// Completion for message selectors after a receiver: the selectors defined in
|
|
345
|
+
/// the file, common selectors, and snippets such as `ifTrue:ifFalse:`.
|
|
346
|
+
function selectorCompletionSource(context) {
|
|
347
|
+
const word = context.matchBefore(wordBefore);
|
|
348
|
+
if (!word && !context.explicit)
|
|
349
|
+
return null;
|
|
350
|
+
const from = word ? word.from : context.pos;
|
|
351
|
+
const inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
352
|
+
const path = ancestors(inner);
|
|
353
|
+
if (!path.some((node) => node.name == "MethodBody"))
|
|
354
|
+
return null;
|
|
355
|
+
if (path.some((node) => noCompletion.has(node.name) || node.name == "Pragma"))
|
|
356
|
+
return null;
|
|
357
|
+
if (!isSelectorPosition(context.state, from))
|
|
358
|
+
return null;
|
|
359
|
+
return {
|
|
360
|
+
from,
|
|
361
|
+
options: unique([
|
|
362
|
+
...definedSelectors(context.state).map((label) => ({ label, type: "method" })),
|
|
363
|
+
...commonSelectors,
|
|
364
|
+
]),
|
|
365
|
+
validFor: /^\w*$/,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
/// Completion where an expression starts: the method's parameters and
|
|
369
|
+
/// temporaries, the block parameters and temporaries in scope, the class's
|
|
370
|
+
/// variables, the classes in the file, common classes and the pseudo-variables.
|
|
371
|
+
function localCompletionSource(context) {
|
|
372
|
+
const word = context.matchBefore(wordBefore);
|
|
373
|
+
if (!word && !context.explicit)
|
|
374
|
+
return null;
|
|
375
|
+
const from = word ? word.from : context.pos;
|
|
376
|
+
const inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
377
|
+
const path = ancestors(inner);
|
|
378
|
+
if (!path.some((node) => node.name == "MethodBody"))
|
|
379
|
+
return null;
|
|
380
|
+
if (path.some((node) => noCompletion.has(node.name)))
|
|
381
|
+
return null;
|
|
382
|
+
if (isSelectorPosition(context.state, from))
|
|
383
|
+
return null;
|
|
384
|
+
const { classes, variables } = classDeclarations(context.state);
|
|
385
|
+
return {
|
|
386
|
+
from,
|
|
387
|
+
options: unique([
|
|
388
|
+
...localNames(context.state, inner).map((label) => ({ label, type: "variable" })),
|
|
389
|
+
...variables.map((label) => ({ label, type: "property" })),
|
|
390
|
+
...pseudoVariables,
|
|
391
|
+
...classes.map((label) => ({ label, type: "class" })),
|
|
392
|
+
...classNames,
|
|
393
|
+
...expressionSnippets,
|
|
394
|
+
]),
|
|
395
|
+
validFor: /^\w*$/,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
/// All of the completion sources together.
|
|
399
|
+
function smalltalkCompletion(context) {
|
|
400
|
+
var _a, _b;
|
|
401
|
+
return ((_b = (_a = topLevelCompletionSource(context)) !== null && _a !== void 0 ? _a : selectorCompletionSource(context)) !== null && _b !== void 0 ? _b : localCompletionSource(context));
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const pharoSmalltalkLanguage = language.LRLanguage.define({
|
|
405
|
+
name: "pharo-smalltalk",
|
|
406
|
+
parser: parser.configure({
|
|
407
|
+
props: [
|
|
408
|
+
language.indentNodeProp.add({
|
|
409
|
+
"MethodBody Block": language.delimitedIndent({ closing: "]", align: false }),
|
|
410
|
+
"StonMap DynamicArray": language.delimitedIndent({ closing: "}", align: false }),
|
|
411
|
+
StonList: language.delimitedIndent({ closing: "]", align: false }),
|
|
412
|
+
"LiteralArray InnerArray ParenthesizedExpression": language.delimitedIndent({
|
|
413
|
+
closing: ")",
|
|
414
|
+
align: false,
|
|
415
|
+
}),
|
|
416
|
+
"Cascade KeywordSend": language.continuedIndent(),
|
|
417
|
+
}),
|
|
418
|
+
language.foldNodeProp.add({
|
|
419
|
+
"MethodBody Block StonMap StonList DynamicArray LiteralArray InnerArray": language.foldInside,
|
|
420
|
+
Comment: (node) => ({ from: node.from + 1, to: node.to - 1 }),
|
|
421
|
+
}),
|
|
422
|
+
highlight.styleTags({
|
|
423
|
+
Comment: highlight.tags.comment,
|
|
424
|
+
String: highlight.tags.string,
|
|
425
|
+
Character: highlight.tags.character,
|
|
426
|
+
Symbol: highlight.tags.atom,
|
|
427
|
+
"StonKey/Symbol": highlight.tags.propertyName,
|
|
428
|
+
"Number NegativeNumber": highlight.tags.number,
|
|
429
|
+
"True False": highlight.tags.bool,
|
|
430
|
+
Nil: highlight.tags.null,
|
|
431
|
+
"Self Super ThisContext": highlight.tags.self,
|
|
432
|
+
// The names below wrap a name token, and `/...` passes their tag down
|
|
433
|
+
// to it.
|
|
434
|
+
"DefinitionKind/...": highlight.tags.definitionKeyword,
|
|
435
|
+
"ClassSide/...": highlight.tags.modifier,
|
|
436
|
+
"MethodClass/...": highlight.tags.className,
|
|
437
|
+
"MethodName/... KeywordName/... BinarySelectorName/...": highlight.tags.definition(highlight.tags.function(highlight.tags.variableName)),
|
|
438
|
+
"ParameterName/... TemporaryName/... BlockParameterName/...": highlight.tags.definition(highlight.tags.variableName),
|
|
439
|
+
"UnarySelector/... KeywordSelector/...": highlight.tags.function(highlight.tags.propertyName),
|
|
440
|
+
"BinarySelector/...": highlight.tags.operator,
|
|
441
|
+
"Pragma/...": highlight.tags.meta,
|
|
442
|
+
"VariableName/Identifier": highlight.tags.variableName,
|
|
443
|
+
"VariableName/GlobalName": highlight.tags.className,
|
|
444
|
+
"LiteralArray/Identifier LiteralArray/Keyword InnerArray/Identifier InnerArray/Keyword": highlight.tags.atom,
|
|
445
|
+
"^": highlight.tags.controlKeyword,
|
|
446
|
+
":=": highlight.tags.definitionOperator,
|
|
447
|
+
"; .": highlight.tags.separator,
|
|
448
|
+
"( )": highlight.tags.paren,
|
|
449
|
+
"[ ]": highlight.tags.squareBracket,
|
|
450
|
+
"{ }": highlight.tags.brace,
|
|
451
|
+
"#( #[": highlight.tags.special(highlight.tags.paren),
|
|
452
|
+
}),
|
|
453
|
+
],
|
|
454
|
+
}),
|
|
455
|
+
languageData: {
|
|
456
|
+
commentTokens: { block: { open: '"', close: '"' } },
|
|
457
|
+
closeBrackets: { brackets: ["(", "[", "{", "'", '"'] },
|
|
458
|
+
indentOnInput: /^\s*[\]})]$/,
|
|
459
|
+
},
|
|
460
|
+
});
|
|
461
|
+
/// Pharo Smalltalk support for Tonel files, with completion for snippets,
|
|
462
|
+
/// common classes and selectors, and the names declared in the file.
|
|
463
|
+
function pharoSmalltalk() {
|
|
464
|
+
return new language.LanguageSupport(pharoSmalltalkLanguage, [
|
|
465
|
+
pharoSmalltalkLanguage.data.of({ autocomplete: smalltalkCompletion }),
|
|
466
|
+
]);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
exports.localCompletionSource = localCompletionSource;
|
|
470
|
+
exports.parser = parser;
|
|
471
|
+
exports.pharoSmalltalk = pharoSmalltalk;
|
|
472
|
+
exports.pharoSmalltalkLanguage = pharoSmalltalkLanguage;
|
|
473
|
+
exports.selectorCompletionSource = selectorCompletionSource;
|
|
474
|
+
exports.smalltalkCompletion = smalltalkCompletion;
|
|
475
|
+
exports.snippets = snippets;
|
|
476
|
+
exports.topLevelCompletionSource = topLevelCompletionSource;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { parser } from "./syntax.grammar";
|
|
2
|
+
import { LRLanguage, LanguageSupport } from "@codemirror/language";
|
|
3
|
+
import { Completion, CompletionContext, CompletionResult } from "@codemirror/autocomplete";
|
|
4
|
+
/// Snippets for the language's common constructs.
|
|
5
|
+
declare const snippets: readonly Completion[];
|
|
6
|
+
/// Completion between methods: the class definition and method snippets, and
|
|
7
|
+
/// the class names a method header can start with.
|
|
8
|
+
declare function topLevelCompletionSource(context: CompletionContext): CompletionResult | null;
|
|
9
|
+
/// Completion for message selectors after a receiver: the selectors defined in
|
|
10
|
+
/// the file, common selectors, and snippets such as `ifTrue:ifFalse:`.
|
|
11
|
+
declare function selectorCompletionSource(context: CompletionContext): CompletionResult | null;
|
|
12
|
+
/// Completion where an expression starts: the method's parameters and
|
|
13
|
+
/// temporaries, the block parameters and temporaries in scope, the class's
|
|
14
|
+
/// variables, the classes in the file, common classes and the pseudo-variables.
|
|
15
|
+
declare function localCompletionSource(context: CompletionContext): CompletionResult | null;
|
|
16
|
+
/// All of the completion sources together.
|
|
17
|
+
declare function smalltalkCompletion(context: CompletionContext): CompletionResult | null;
|
|
18
|
+
declare const pharoSmalltalkLanguage: LRLanguage;
|
|
19
|
+
declare function pharoSmalltalk(): LanguageSupport;
|
|
20
|
+
export { pharoSmalltalkLanguage, pharoSmalltalk, parser, snippets, smalltalkCompletion, localCompletionSource, selectorCompletionSource, topLevelCompletionSource };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { parser } from "./syntax.grammar";
|
|
2
|
+
import { LRLanguage, LanguageSupport } from "@codemirror/language";
|
|
3
|
+
import { Completion, CompletionContext, CompletionResult } from "@codemirror/autocomplete";
|
|
4
|
+
/// Snippets for the language's common constructs.
|
|
5
|
+
declare const snippets: readonly Completion[];
|
|
6
|
+
/// Completion between methods: the class definition and method snippets, and
|
|
7
|
+
/// the class names a method header can start with.
|
|
8
|
+
declare function topLevelCompletionSource(context: CompletionContext): CompletionResult | null;
|
|
9
|
+
/// Completion for message selectors after a receiver: the selectors defined in
|
|
10
|
+
/// the file, common selectors, and snippets such as `ifTrue:ifFalse:`.
|
|
11
|
+
declare function selectorCompletionSource(context: CompletionContext): CompletionResult | null;
|
|
12
|
+
/// Completion where an expression starts: the method's parameters and
|
|
13
|
+
/// temporaries, the block parameters and temporaries in scope, the class's
|
|
14
|
+
/// variables, the classes in the file, common classes and the pseudo-variables.
|
|
15
|
+
declare function localCompletionSource(context: CompletionContext): CompletionResult | null;
|
|
16
|
+
/// All of the completion sources together.
|
|
17
|
+
declare function smalltalkCompletion(context: CompletionContext): CompletionResult | null;
|
|
18
|
+
declare const pharoSmalltalkLanguage: LRLanguage;
|
|
19
|
+
declare function pharoSmalltalk(): LanguageSupport;
|
|
20
|
+
export { pharoSmalltalkLanguage, pharoSmalltalk, parser, snippets, smalltalkCompletion, localCompletionSource, selectorCompletionSource, topLevelCompletionSource };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import { ExternalTokenizer, LRParser } from '@lezer/lr';
|
|
2
|
+
import { syntaxTree, LRLanguage, indentNodeProp, continuedIndent, delimitedIndent, foldNodeProp, foldInside, LanguageSupport } from '@codemirror/language';
|
|
3
|
+
import { styleTags, tags } from '@lezer/highlight';
|
|
4
|
+
import { snippetCompletion } from '@codemirror/autocomplete';
|
|
5
|
+
|
|
6
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
7
|
+
const Identifier = 1,
|
|
8
|
+
GlobalName = 2,
|
|
9
|
+
Keyword = 3;
|
|
10
|
+
|
|
11
|
+
const colon = 58, equals = 61, underscore = 95;
|
|
12
|
+
function isLetter(ch) {
|
|
13
|
+
return (ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122);
|
|
14
|
+
}
|
|
15
|
+
function isIdentChar(ch) {
|
|
16
|
+
return isLetter(ch) || (ch >= 48 && ch <= 57) || ch == underscore;
|
|
17
|
+
}
|
|
18
|
+
// Reads a name. `at:` is a keyword, but in `x:=1` the colon belongs to the
|
|
19
|
+
// assignment, so `x` stays a name. A name that starts with a capital letter,
|
|
20
|
+
// such as `OrderedCollection`, is a global.
|
|
21
|
+
const identifiers = new ExternalTokenizer((input) => {
|
|
22
|
+
const first = input.next;
|
|
23
|
+
if (!isLetter(first) && first != underscore)
|
|
24
|
+
return;
|
|
25
|
+
while (isIdentChar(input.next))
|
|
26
|
+
input.advance();
|
|
27
|
+
if (input.next == colon && input.peek(1) != equals) {
|
|
28
|
+
input.advance();
|
|
29
|
+
input.acceptToken(Keyword);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
input.acceptToken(first >= 65 && first <= 90 ? GlobalName : Identifier);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
37
|
+
const spec_BinaryOp = {__proto__:null,"-":194, ">>":204, "<":210, ">":212};
|
|
38
|
+
const spec_Identifier = {__proto__:null,nil:198, true:200, false:202, self:236, super:238, thisContext:240};
|
|
39
|
+
const parser = LRParser.deserialize({
|
|
40
|
+
version: 14,
|
|
41
|
+
states: "8fQYQROOOeQRO'#CcOpQQO'#CfOxQQO'#CbOOQP'#Cv'#CvOOQP'#E^'#E^OOQP'#Dz'#DzQYQROOO}QRO'#CwOOQP'#Ch'#ChO!zQRO'#CgO#RQQO'#E_O#ZQQO,59QOOQP,58|,58|OOQP-E7x-E7xOOQO'#Cy'#CyO#`QRO,59cO$QQQO,59cO$VQRO'#CqOOQP'#Cs'#CsOOQP'#Ct'#CtOOQP'#Cu'#CuOOQO'#E`'#E`OOQO,59R,59RO!VQRO,59RO$^QQO'#CmO$cQQO,5:yO$kQQO,5:yOOQP1G.l1G.lOOQP'#Eg'#EgOOQO'#C{'#C{OOQP'#Eh'#EhOOQP'#C|'#C|OOQP'#DP'#DPO$sQRO'#D}O${QRO'#CzOOQO'#Cz'#CzO$sQRO'#CzO%TQQO1G.}O#`QRO1G.}O%YQQO'#EbO%bQQO,59]OOQO1G.m1G.mOOQP,59X,59XOOQO,5:h,5:hO%gQQO1G0eOOQO-E7z-E7zOOQP'#DO'#DOOOQ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!g!h!i!r!v#`$_R$c#nd!k!T!b!g!h!i!r!v#`#n$_R$b#kR$j#q",
|
|
44
|
+
nodeNames: "⚠ Identifier GlobalName Keyword Comment Program ClassDefinition DefinitionKind } { StonMap StonEntry StonKey Symbol : String Number NegativeNumber BinaryOp ] [ StonList , Nil True False Metadata MethodDefinition MethodClass ClassSide MethodPattern MethodName BinarySelectorName | ParameterName KeywordName MethodBody Pragma PragmaName PragmaKeyword Character ) #( LiteralArray #[ ByteArray ( InnerArray InnerByteArray VariableName Temporaries TemporaryName ReturnStatement ^ Assignment := Cascade Self Super ThisContext Block BlockParameters BlockParameterName DynamicArray ParenthesizedExpression UnarySend UnaryMessage UnarySelector BinarySend BinaryMessage BinarySelector KeywordSend KeywordMessage KeywordSelector ; .",
|
|
45
|
+
maxTerm: 121,
|
|
46
|
+
nodeProps: [
|
|
47
|
+
["openedBy", 8,"{",19,"[ #[",41,"#( ("],
|
|
48
|
+
["closedBy", 9,"}",-2,20,44,"]",-2,42,46,")"]
|
|
49
|
+
],
|
|
50
|
+
skippedNodes: [0,4],
|
|
51
|
+
repeatNodeCount: 15,
|
|
52
|
+
tokenData: "3j~RyX^#rpq#rqr$grs%hst&Vtu-Ouv$gvw$gwx-ixy.Zyz.`z{$g{|$g|}.e}!O$g!O!P.j!P!Q$g!Q![.o![!]2h!]!^2u!^!_$g!_!`$g!`!a$g!a!b$g!b!c$g!}#O2z#O#P$g#P#Q3P#Q#R3U#o#p3Z#p#q3`#q#r3e#r#s$g#y#z#r$f$g#r#BY#BZ#r$IS$I_#r$I|$JO#r$JT$JU#r$KV$KW#r&FU&FV#r~#wY#P~X^#rpq#r#y#z#r$f$g#r#BY#BZ#r$IS$I_#r$I|$JO#r$JT$JU#r$KV$KW#r&FU&FV#r~$l^b~qr$guv$gvw$gz{$g{|$g}!O$g!P!Q$g!^!_$g!_!`$g!`!a$g!a!b$g!b!c$g#O#P$g#r#s$g~%kTOr%hrs%zs;'S%h;'S;=`&P<%lO%h~&POS~~&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O!l~~3POd~~3UOc~~3ZO!V~~3`OX~~3eOq~~3jOW~",
|
|
53
|
+
tokenizers: [identifiers, 0, 1],
|
|
54
|
+
topRules: {"Program":[0,5]},
|
|
55
|
+
specialized: [{term: 18, get: (value) => spec_BinaryOp[value] || -1},{term: 1, get: (value) => spec_Identifier[value] || -1}],
|
|
56
|
+
tokenPrec: 0
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/// Snippets for a class definition and a method, offered between methods.
|
|
60
|
+
const topLevelSnippets = [
|
|
61
|
+
snippetCompletion("Class {\n\t#name : #${Name},\n\t#superclass : #${Object},\n\t#instVars : [\n\t\t'${variable}'\n\t],\n\t#category : #'${Category}'\n}\n", { label: "Class", detail: "class definition", type: "keyword" }),
|
|
62
|
+
snippetCompletion("Extension { #name : #${Class} }\n", {
|
|
63
|
+
label: "Extension",
|
|
64
|
+
detail: "extend a class",
|
|
65
|
+
type: "keyword",
|
|
66
|
+
}),
|
|
67
|
+
snippetCompletion("{ #category : #'${category}' }\n${Class} >> ${selector} [\n\n\t${}\n]\n", {
|
|
68
|
+
label: "method",
|
|
69
|
+
detail: "with category",
|
|
70
|
+
type: "keyword",
|
|
71
|
+
}),
|
|
72
|
+
snippetCompletion("{ #category : #'${category}' }\n${Class} class >> ${selector} [\n\n\t${}\n]\n", {
|
|
73
|
+
label: "class method",
|
|
74
|
+
detail: "with category",
|
|
75
|
+
type: "keyword",
|
|
76
|
+
}),
|
|
77
|
+
snippetCompletion("{ #category : #'${category}' }", {
|
|
78
|
+
label: "category",
|
|
79
|
+
detail: "method metadata",
|
|
80
|
+
type: "keyword",
|
|
81
|
+
}),
|
|
82
|
+
];
|
|
83
|
+
/// Snippets for messages with block arguments, offered after a receiver.
|
|
84
|
+
const selectorSnippets = [
|
|
85
|
+
snippetCompletion("ifTrue: [ ${} ]", { label: "ifTrue:", type: "method" }),
|
|
86
|
+
snippetCompletion("ifFalse: [ ${} ]", { label: "ifFalse:", type: "method" }),
|
|
87
|
+
snippetCompletion("ifTrue: [ ${} ] ifFalse: [ ${} ]", { label: "ifTrue:ifFalse:", type: "method" }),
|
|
88
|
+
snippetCompletion("ifFalse: [ ${} ] ifTrue: [ ${} ]", { label: "ifFalse:ifTrue:", type: "method" }),
|
|
89
|
+
snippetCompletion("ifNil: [ ${} ]", { label: "ifNil:", type: "method" }),
|
|
90
|
+
snippetCompletion("ifNotNil: [ :${it} | ${} ]", { label: "ifNotNil:", type: "method" }),
|
|
91
|
+
snippetCompletion("ifNil: [ ${} ] ifNotNil: [ :${it} | ${} ]", { label: "ifNil:ifNotNil:", type: "method" }),
|
|
92
|
+
snippetCompletion("ifEmpty: [ ${} ]", { label: "ifEmpty:", type: "method" }),
|
|
93
|
+
snippetCompletion("ifEmpty: [ ${} ] ifNotEmpty: [ :${it} | ${} ]", {
|
|
94
|
+
label: "ifEmpty:ifNotEmpty:",
|
|
95
|
+
type: "method",
|
|
96
|
+
}),
|
|
97
|
+
snippetCompletion("and: [ ${} ]", { label: "and:", type: "method" }),
|
|
98
|
+
snippetCompletion("or: [ ${} ]", { label: "or:", type: "method" }),
|
|
99
|
+
snippetCompletion("do: [ :${each} | ${} ]", { label: "do:", type: "method" }),
|
|
100
|
+
snippetCompletion("do: [ :${each} | ${} ] separatedBy: [ ${} ]", { label: "do:separatedBy:", type: "method" }),
|
|
101
|
+
snippetCompletion("doWithIndex: [ :${each} :${index} | ${} ]", { label: "doWithIndex:", type: "method" }),
|
|
102
|
+
snippetCompletion("withIndexDo: [ :${each} :${index} | ${} ]", { label: "withIndexDo:", type: "method" }),
|
|
103
|
+
snippetCompletion("keysAndValuesDo: [ :${key} :${value} | ${} ]", { label: "keysAndValuesDo:", type: "method" }),
|
|
104
|
+
snippetCompletion("reverseDo: [ :${each} | ${} ]", { label: "reverseDo:", type: "method" }),
|
|
105
|
+
snippetCompletion("collect: [ :${each} | ${} ]", { label: "collect:", type: "method" }),
|
|
106
|
+
snippetCompletion("withIndexCollect: [ :${each} :${index} | ${} ]", { label: "withIndexCollect:", type: "method" }),
|
|
107
|
+
snippetCompletion("select: [ :${each} | ${} ]", { label: "select:", type: "method" }),
|
|
108
|
+
snippetCompletion("reject: [ :${each} | ${} ]", { label: "reject:", type: "method" }),
|
|
109
|
+
snippetCompletion("detect: [ :${each} | ${} ]", { label: "detect:", type: "method" }),
|
|
110
|
+
snippetCompletion("detect: [ :${each} | ${} ] ifNone: [ ${} ]", { label: "detect:ifNone:", type: "method" }),
|
|
111
|
+
snippetCompletion("anySatisfy: [ :${each} | ${} ]", { label: "anySatisfy:", type: "method" }),
|
|
112
|
+
snippetCompletion("allSatisfy: [ :${each} | ${} ]", { label: "allSatisfy:", type: "method" }),
|
|
113
|
+
snippetCompletion("count: [ :${each} | ${} ]", { label: "count:", type: "method" }),
|
|
114
|
+
snippetCompletion("inject: ${0} into: [ :${sum} :${each} | ${} ]", { label: "inject:into:", type: "method" }),
|
|
115
|
+
snippetCompletion("sort: [ :${a} :${b} | ${a} < ${b} ]", { label: "sort:", type: "method" }),
|
|
116
|
+
snippetCompletion("sorted: [ :${a} :${b} | ${a} < ${b} ]", { label: "sorted:", type: "method" }),
|
|
117
|
+
snippetCompletion("to: ${end} do: [ :${i} | ${} ]", { label: "to:do:", type: "method" }),
|
|
118
|
+
snippetCompletion("to: ${end} by: ${step} do: [ :${i} | ${} ]", { label: "to:by:do:", type: "method" }),
|
|
119
|
+
snippetCompletion("timesRepeat: [ ${} ]", { label: "timesRepeat:", type: "method" }),
|
|
120
|
+
snippetCompletion("whileTrue: [ ${} ]", { label: "whileTrue:", type: "method" }),
|
|
121
|
+
snippetCompletion("whileFalse: [ ${} ]", { label: "whileFalse:", type: "method" }),
|
|
122
|
+
snippetCompletion("at: ${key} ifAbsent: [ ${} ]", { label: "at:ifAbsent:", type: "method" }),
|
|
123
|
+
snippetCompletion("at: ${key} ifAbsentPut: [ ${} ]", { label: "at:ifAbsentPut:", type: "method" }),
|
|
124
|
+
snippetCompletion("at: ${key} ifPresent: [ :${value} | ${} ]", { label: "at:ifPresent:", type: "method" }),
|
|
125
|
+
snippetCompletion("on: ${Error} do: [ :${error} | ${} ]", { label: "on:do:", type: "method" }),
|
|
126
|
+
snippetCompletion("ensure: [ ${} ]", { label: "ensure:", type: "method" }),
|
|
127
|
+
];
|
|
128
|
+
/// Snippets offered where an expression starts.
|
|
129
|
+
const expressionSnippets = [
|
|
130
|
+
snippetCompletion("[ :${each} | ${} ]", { label: "block", detail: "[ :each | ]", type: "keyword" }),
|
|
131
|
+
snippetCompletion("| ${temp} |", { label: "temps", detail: "| temp |", type: "keyword" }),
|
|
132
|
+
snippetCompletion("String streamContents: [ :${stream} | ${} ]", {
|
|
133
|
+
label: "streamContents:",
|
|
134
|
+
detail: "build a string",
|
|
135
|
+
type: "keyword",
|
|
136
|
+
}),
|
|
137
|
+
];
|
|
138
|
+
/// Snippets for the language's common constructs.
|
|
139
|
+
const snippets = [
|
|
140
|
+
...topLevelSnippets,
|
|
141
|
+
...selectorSnippets,
|
|
142
|
+
...expressionSnippets,
|
|
143
|
+
];
|
|
144
|
+
const pseudoVariables = ["self", "super", "thisContext", "nil", "true", "false"].map((label) => ({ label, type: "keyword" }));
|
|
145
|
+
const classNames = ("Object Boolean True False UndefinedObject Magnitude Number Integer SmallInteger " +
|
|
146
|
+
"LargePositiveInteger Float Fraction ScaledDecimal Character String Symbol " +
|
|
147
|
+
"Collection SequenceableCollection ArrayedCollection Array ByteArray Interval " +
|
|
148
|
+
"OrderedCollection SortedCollection LinkedList Set IdentitySet Bag Dictionary " +
|
|
149
|
+
"IdentityDictionary OrderedDictionary SmallDictionary Association Point Rectangle " +
|
|
150
|
+
"Array2D Matrix Stream ReadStream WriteStream ReadWriteStream Transcript Smalltalk " +
|
|
151
|
+
"Date Time DateAndTime Duration Random Error Exception ZeroDivide DomainError " +
|
|
152
|
+
"NotFound KeyNotFound SubscriptOutOfBounds ArithmeticError MessageNotUnderstood " +
|
|
153
|
+
"Warning AssertionFailure TestCase Generator CharacterSet Color")
|
|
154
|
+
.split(" ")
|
|
155
|
+
.map((label) => ({ label, type: "class" }));
|
|
156
|
+
const unarySelectors = ("new value printString displayString asString asSymbol asNumber asInteger asFloat " +
|
|
157
|
+
"asArray asOrderedCollection asSet asBag asSortedCollection asDictionary asUppercase " +
|
|
158
|
+
"asLowercase asCharacter asCharacterDigit asByteArray size isEmpty notEmpty isNotEmpty " +
|
|
159
|
+
"isEmptyOrNil isNil notNil first last allButFirst allButLast reversed reverse sum max min " +
|
|
160
|
+
"abs negated squared sqrt floor ceiling rounded truncated isZero even odd isPrime " +
|
|
161
|
+
"isInteger isNumber isString isSymbol isCharacter isLetter isDigit isVowel isUppercase " +
|
|
162
|
+
"isLowercase isSeparator digitValue keys values associations key copy yourself hash " +
|
|
163
|
+
"class name trimBoth trimmed lines substrings asSortedCollection anyOne removeFirst " +
|
|
164
|
+
"removeLast sign factorial not signal initialize cr tab space contents readStream " +
|
|
165
|
+
"writeStream upToEnd next atEnd peek skip")
|
|
166
|
+
.split(" ")
|
|
167
|
+
.map((label) => ({ label, type: "method" }));
|
|
168
|
+
const keywordSelectors = ("at: at:put: add: addAll: addFirst: addLast: remove: remove:ifAbsent: removeKey: " +
|
|
169
|
+
"removeAll: includes: includesKey: includesSubstring: indexOf: occurrencesOf: " +
|
|
170
|
+
"copyFrom:to: copyWith: copyWithout: copyReplaceAll:with: , with: with:with: " +
|
|
171
|
+
"with:collect: new: new:withAll: withAll: newFrom: value: value:value: valueWithArguments: " +
|
|
172
|
+
"printOn: printString: printPaddedWith:to: nextPut: nextPutAll: print: join: " +
|
|
173
|
+
"streamContents: splitOn: substrings: raisedTo: gcd: lcm: max: min: between:and: " +
|
|
174
|
+
"isDivisibleBy: \\\\ // rem: quo: bitAnd: bitOr: bitXor: bitAt: bitShift: " +
|
|
175
|
+
"first: last: allButFirst: allButLast: groupedBy: asStringWithCommas " +
|
|
176
|
+
"signal: error: assert: assert:equals: deny: should:raise: format: " +
|
|
177
|
+
"perform: perform:with: respondsTo: isKindOf: isMemberOf: = == ~= ~~ -> " +
|
|
178
|
+
"readFrom: subclass:instanceVariableNames:classVariableNames:package:")
|
|
179
|
+
.split(" ")
|
|
180
|
+
.filter((label) => label.endsWith(":"))
|
|
181
|
+
.map((label) => ({ label, type: "method" }));
|
|
182
|
+
const commonSelectors = [
|
|
183
|
+
...selectorSnippets,
|
|
184
|
+
...unarySelectors,
|
|
185
|
+
...keywordSelectors.filter((option) => !selectorSnippets.some((s) => s.label == option.label)),
|
|
186
|
+
];
|
|
187
|
+
const wordBefore = /[A-Za-z_][A-Za-z0-9_]*$/;
|
|
188
|
+
// Nodes where the name being typed is a new name, or isn't code at all.
|
|
189
|
+
const noCompletion = new Set([
|
|
190
|
+
"Comment",
|
|
191
|
+
"String",
|
|
192
|
+
"Symbol",
|
|
193
|
+
"Character",
|
|
194
|
+
"Number",
|
|
195
|
+
"Temporaries",
|
|
196
|
+
"BlockParameters",
|
|
197
|
+
"MethodPattern",
|
|
198
|
+
"LiteralArray",
|
|
199
|
+
"ByteArray",
|
|
200
|
+
"StonMap",
|
|
201
|
+
]);
|
|
202
|
+
function ancestors(node) {
|
|
203
|
+
const found = [];
|
|
204
|
+
for (let at = node; at; at = at.parent)
|
|
205
|
+
found.push(at);
|
|
206
|
+
return found;
|
|
207
|
+
}
|
|
208
|
+
function text(state, node) {
|
|
209
|
+
return state.sliceDoc(node.from, node.to);
|
|
210
|
+
}
|
|
211
|
+
function childNames(state, parent, container, name) {
|
|
212
|
+
const names = [];
|
|
213
|
+
for (let child = parent.firstChild; child; child = child.nextSibling) {
|
|
214
|
+
if (child.name != container)
|
|
215
|
+
continue;
|
|
216
|
+
for (const node of child.getChildren(name))
|
|
217
|
+
names.push(text(state, node));
|
|
218
|
+
}
|
|
219
|
+
return names;
|
|
220
|
+
}
|
|
221
|
+
const stonNameKeys = /^#(name|instVars|classVars|classInstVars|pools)\s*:?$/;
|
|
222
|
+
/// The class names and the variables declared by the class definitions in the
|
|
223
|
+
/// file. Tonel lists variables as strings, as in `#instVars : [ 'count' ]`.
|
|
224
|
+
function classDeclarations(state) {
|
|
225
|
+
const classes = [];
|
|
226
|
+
const variables = [];
|
|
227
|
+
const top = syntaxTree(state).topNode;
|
|
228
|
+
for (const definition of top.getChildren("ClassDefinition")) {
|
|
229
|
+
const map = definition.getChild("StonMap");
|
|
230
|
+
if (!map)
|
|
231
|
+
continue;
|
|
232
|
+
for (const entry of map.getChildren("StonEntry")) {
|
|
233
|
+
const key = entry.getChild("StonKey");
|
|
234
|
+
const keyText = key ? text(state, key) : "";
|
|
235
|
+
const match = stonNameKeys.exec(keyText);
|
|
236
|
+
if (!match)
|
|
237
|
+
continue;
|
|
238
|
+
if (match[1] == "name") {
|
|
239
|
+
const value = entry.lastChild;
|
|
240
|
+
if (value && value != key)
|
|
241
|
+
classes.push(text(state, value).replace(/^#'?|'$/g, ""));
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
const list = entry.getChild("StonList");
|
|
245
|
+
if (!list)
|
|
246
|
+
continue;
|
|
247
|
+
for (const s of list.getChildren("String")) {
|
|
248
|
+
for (const name of text(state, s).slice(1, -1).split(/\s+/))
|
|
249
|
+
if (name)
|
|
250
|
+
variables.push(name);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return { classes, variables };
|
|
256
|
+
}
|
|
257
|
+
/// The selectors of the methods defined in the file, such as `at:put:`.
|
|
258
|
+
function definedSelectors(state) {
|
|
259
|
+
var _a;
|
|
260
|
+
const selectors = new Set();
|
|
261
|
+
const top = syntaxTree(state).topNode;
|
|
262
|
+
for (const method of top.getChildren("MethodDefinition")) {
|
|
263
|
+
const pattern = method.getChild("MethodPattern");
|
|
264
|
+
if (!pattern)
|
|
265
|
+
continue;
|
|
266
|
+
const parts = pattern.getChildren("KeywordName").map((node) => text(state, node));
|
|
267
|
+
const name = (_a = pattern.getChild("MethodName")) !== null && _a !== void 0 ? _a : pattern.getChild("BinarySelectorName");
|
|
268
|
+
if (parts.length)
|
|
269
|
+
selectors.add(parts.join(""));
|
|
270
|
+
else if (name)
|
|
271
|
+
selectors.add(text(state, name));
|
|
272
|
+
}
|
|
273
|
+
return [...selectors];
|
|
274
|
+
}
|
|
275
|
+
/// The names in scope at a position inside a method: its parameters, its
|
|
276
|
+
/// temporaries, and the parameters and temporaries of the blocks around it.
|
|
277
|
+
function localNames(state, node) {
|
|
278
|
+
const names = [];
|
|
279
|
+
for (const at of ancestors(node)) {
|
|
280
|
+
if (at.name == "Block") {
|
|
281
|
+
names.push(...childNames(state, at, "BlockParameters", "BlockParameterName"));
|
|
282
|
+
names.push(...childNames(state, at, "Temporaries", "TemporaryName"));
|
|
283
|
+
}
|
|
284
|
+
else if (at.name == "MethodBody") {
|
|
285
|
+
names.push(...childNames(state, at, "Temporaries", "TemporaryName"));
|
|
286
|
+
}
|
|
287
|
+
else if (at.name == "MethodDefinition") {
|
|
288
|
+
const pattern = at.getChild("MethodPattern");
|
|
289
|
+
if (pattern)
|
|
290
|
+
for (const p of pattern.getChildren("ParameterName"))
|
|
291
|
+
names.push(text(state, p));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return names;
|
|
295
|
+
}
|
|
296
|
+
// A word typed straight after a receiver is a message selector, as in
|
|
297
|
+
// `items si‸`. After a keyword, an operator, `:=`, `^`, a period or an opening
|
|
298
|
+
// bracket, it starts an expression.
|
|
299
|
+
function isSelectorPosition(state, from) {
|
|
300
|
+
const before = state.sliceDoc(Math.max(0, from - 200), from).replace(/\s+$/, "");
|
|
301
|
+
if (!before)
|
|
302
|
+
return false;
|
|
303
|
+
const last = before[before.length - 1];
|
|
304
|
+
if (/[A-Za-z0-9_]/.test(last)) {
|
|
305
|
+
const word = /[A-Za-z_][A-Za-z0-9_]*$/.exec(before);
|
|
306
|
+
// `x foo: 3 ba‸` and `^ self ba‸` both follow a receiver, but `ifTrue:` ends
|
|
307
|
+
// in a colon and so does not get here.
|
|
308
|
+
return !(word && /[:#$]$/.test(before.slice(0, before.length - word[0].length)));
|
|
309
|
+
}
|
|
310
|
+
return /['\)\]\}]/.test(last);
|
|
311
|
+
}
|
|
312
|
+
function unique(options) {
|
|
313
|
+
const seen = new Set();
|
|
314
|
+
return options.filter((option) => {
|
|
315
|
+
if (seen.has(option.label))
|
|
316
|
+
return false;
|
|
317
|
+
seen.add(option.label);
|
|
318
|
+
return true;
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
/// Completion between methods: the class definition and method snippets, and
|
|
322
|
+
/// the class names a method header can start with.
|
|
323
|
+
function topLevelCompletionSource(context) {
|
|
324
|
+
const word = context.matchBefore(wordBefore);
|
|
325
|
+
if (!word && !context.explicit)
|
|
326
|
+
return null;
|
|
327
|
+
const inner = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
328
|
+
const path = ancestors(inner);
|
|
329
|
+
if (path.some((node) => node.name == "MethodBody" || noCompletion.has(node.name)))
|
|
330
|
+
return null;
|
|
331
|
+
const { classes } = classDeclarations(context.state);
|
|
332
|
+
return {
|
|
333
|
+
from: word ? word.from : context.pos,
|
|
334
|
+
options: unique([
|
|
335
|
+
...topLevelSnippets,
|
|
336
|
+
...classes.map((label) => ({ label, type: "class" })),
|
|
337
|
+
...classNames,
|
|
338
|
+
]),
|
|
339
|
+
validFor: /^\w*$/,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
/// Completion for message selectors after a receiver: the selectors defined in
|
|
343
|
+
/// the file, common selectors, and snippets such as `ifTrue:ifFalse:`.
|
|
344
|
+
function selectorCompletionSource(context) {
|
|
345
|
+
const word = context.matchBefore(wordBefore);
|
|
346
|
+
if (!word && !context.explicit)
|
|
347
|
+
return null;
|
|
348
|
+
const from = word ? word.from : context.pos;
|
|
349
|
+
const inner = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
350
|
+
const path = ancestors(inner);
|
|
351
|
+
if (!path.some((node) => node.name == "MethodBody"))
|
|
352
|
+
return null;
|
|
353
|
+
if (path.some((node) => noCompletion.has(node.name) || node.name == "Pragma"))
|
|
354
|
+
return null;
|
|
355
|
+
if (!isSelectorPosition(context.state, from))
|
|
356
|
+
return null;
|
|
357
|
+
return {
|
|
358
|
+
from,
|
|
359
|
+
options: unique([
|
|
360
|
+
...definedSelectors(context.state).map((label) => ({ label, type: "method" })),
|
|
361
|
+
...commonSelectors,
|
|
362
|
+
]),
|
|
363
|
+
validFor: /^\w*$/,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/// Completion where an expression starts: the method's parameters and
|
|
367
|
+
/// temporaries, the block parameters and temporaries in scope, the class's
|
|
368
|
+
/// variables, the classes in the file, common classes and the pseudo-variables.
|
|
369
|
+
function localCompletionSource(context) {
|
|
370
|
+
const word = context.matchBefore(wordBefore);
|
|
371
|
+
if (!word && !context.explicit)
|
|
372
|
+
return null;
|
|
373
|
+
const from = word ? word.from : context.pos;
|
|
374
|
+
const inner = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
375
|
+
const path = ancestors(inner);
|
|
376
|
+
if (!path.some((node) => node.name == "MethodBody"))
|
|
377
|
+
return null;
|
|
378
|
+
if (path.some((node) => noCompletion.has(node.name)))
|
|
379
|
+
return null;
|
|
380
|
+
if (isSelectorPosition(context.state, from))
|
|
381
|
+
return null;
|
|
382
|
+
const { classes, variables } = classDeclarations(context.state);
|
|
383
|
+
return {
|
|
384
|
+
from,
|
|
385
|
+
options: unique([
|
|
386
|
+
...localNames(context.state, inner).map((label) => ({ label, type: "variable" })),
|
|
387
|
+
...variables.map((label) => ({ label, type: "property" })),
|
|
388
|
+
...pseudoVariables,
|
|
389
|
+
...classes.map((label) => ({ label, type: "class" })),
|
|
390
|
+
...classNames,
|
|
391
|
+
...expressionSnippets,
|
|
392
|
+
]),
|
|
393
|
+
validFor: /^\w*$/,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
/// All of the completion sources together.
|
|
397
|
+
function smalltalkCompletion(context) {
|
|
398
|
+
var _a, _b;
|
|
399
|
+
return ((_b = (_a = topLevelCompletionSource(context)) !== null && _a !== void 0 ? _a : selectorCompletionSource(context)) !== null && _b !== void 0 ? _b : localCompletionSource(context));
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const pharoSmalltalkLanguage = LRLanguage.define({
|
|
403
|
+
name: "pharo-smalltalk",
|
|
404
|
+
parser: parser.configure({
|
|
405
|
+
props: [
|
|
406
|
+
indentNodeProp.add({
|
|
407
|
+
"MethodBody Block": delimitedIndent({ closing: "]", align: false }),
|
|
408
|
+
"StonMap DynamicArray": delimitedIndent({ closing: "}", align: false }),
|
|
409
|
+
StonList: delimitedIndent({ closing: "]", align: false }),
|
|
410
|
+
"LiteralArray InnerArray ParenthesizedExpression": delimitedIndent({
|
|
411
|
+
closing: ")",
|
|
412
|
+
align: false,
|
|
413
|
+
}),
|
|
414
|
+
"Cascade KeywordSend": continuedIndent(),
|
|
415
|
+
}),
|
|
416
|
+
foldNodeProp.add({
|
|
417
|
+
"MethodBody Block StonMap StonList DynamicArray LiteralArray InnerArray": foldInside,
|
|
418
|
+
Comment: (node) => ({ from: node.from + 1, to: node.to - 1 }),
|
|
419
|
+
}),
|
|
420
|
+
styleTags({
|
|
421
|
+
Comment: tags.comment,
|
|
422
|
+
String: tags.string,
|
|
423
|
+
Character: tags.character,
|
|
424
|
+
Symbol: tags.atom,
|
|
425
|
+
"StonKey/Symbol": tags.propertyName,
|
|
426
|
+
"Number NegativeNumber": tags.number,
|
|
427
|
+
"True False": tags.bool,
|
|
428
|
+
Nil: tags.null,
|
|
429
|
+
"Self Super ThisContext": tags.self,
|
|
430
|
+
// The names below wrap a name token, and `/...` passes their tag down
|
|
431
|
+
// to it.
|
|
432
|
+
"DefinitionKind/...": tags.definitionKeyword,
|
|
433
|
+
"ClassSide/...": tags.modifier,
|
|
434
|
+
"MethodClass/...": tags.className,
|
|
435
|
+
"MethodName/... KeywordName/... BinarySelectorName/...": tags.definition(tags.function(tags.variableName)),
|
|
436
|
+
"ParameterName/... TemporaryName/... BlockParameterName/...": tags.definition(tags.variableName),
|
|
437
|
+
"UnarySelector/... KeywordSelector/...": tags.function(tags.propertyName),
|
|
438
|
+
"BinarySelector/...": tags.operator,
|
|
439
|
+
"Pragma/...": tags.meta,
|
|
440
|
+
"VariableName/Identifier": tags.variableName,
|
|
441
|
+
"VariableName/GlobalName": tags.className,
|
|
442
|
+
"LiteralArray/Identifier LiteralArray/Keyword InnerArray/Identifier InnerArray/Keyword": tags.atom,
|
|
443
|
+
"^": tags.controlKeyword,
|
|
444
|
+
":=": tags.definitionOperator,
|
|
445
|
+
"; .": tags.separator,
|
|
446
|
+
"( )": tags.paren,
|
|
447
|
+
"[ ]": tags.squareBracket,
|
|
448
|
+
"{ }": tags.brace,
|
|
449
|
+
"#( #[": tags.special(tags.paren),
|
|
450
|
+
}),
|
|
451
|
+
],
|
|
452
|
+
}),
|
|
453
|
+
languageData: {
|
|
454
|
+
commentTokens: { block: { open: '"', close: '"' } },
|
|
455
|
+
closeBrackets: { brackets: ["(", "[", "{", "'", '"'] },
|
|
456
|
+
indentOnInput: /^\s*[\]})]$/,
|
|
457
|
+
},
|
|
458
|
+
});
|
|
459
|
+
/// Pharo Smalltalk support for Tonel files, with completion for snippets,
|
|
460
|
+
/// common classes and selectors, and the names declared in the file.
|
|
461
|
+
function pharoSmalltalk() {
|
|
462
|
+
return new LanguageSupport(pharoSmalltalkLanguage, [
|
|
463
|
+
pharoSmalltalkLanguage.data.of({ autocomplete: smalltalkCompletion }),
|
|
464
|
+
]);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export { localCompletionSource, parser, pharoSmalltalk, pharoSmalltalkLanguage, selectorCompletionSource, smalltalkCompletion, snippets, topLevelCompletionSource };
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exercism/codemirror-lang-pharo-smalltalk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Pharo Smalltalk language support for CodeMirror",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"prepare": "bun --bun rollup -c",
|
|
7
|
+
"test": "bun run prepare && bun test",
|
|
8
|
+
"dev": "vite"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "dist/index.cjs",
|
|
12
|
+
"module": "dist/index.js",
|
|
13
|
+
"exports": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@codemirror/autocomplete": "^6.18.0",
|
|
24
|
+
"@codemirror/language": "^6.10.1",
|
|
25
|
+
"@codemirror/state": "^6.4.0",
|
|
26
|
+
"@lezer/common": "^1.2.0",
|
|
27
|
+
"@lezer/highlight": "^1.2.0",
|
|
28
|
+
"@lezer/lr": "^1.4.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@lezer/generator": "^1.7.0",
|
|
32
|
+
"@types/bun": "^1.1.14",
|
|
33
|
+
"codemirror": "^6.0.1",
|
|
34
|
+
"rollup": "^4.18.0",
|
|
35
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
36
|
+
"rollup-plugin-ts": "^3.4.5",
|
|
37
|
+
"typescript": "^5.4.5",
|
|
38
|
+
"unplugin-lezer": "^1.0.1",
|
|
39
|
+
"vite": "^5.4.11"
|
|
40
|
+
},
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/exercism/codemirror-lang-pharo-smalltalk.git"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/exercism/codemirror-lang-pharo-smalltalk#readme",
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/exercism/codemirror-lang-pharo-smalltalk/issues"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist"
|
|
52
|
+
]
|
|
53
|
+
}
|