@algosail/lsp 0.1.8 → 0.1.10
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/debug.js +69 -0
- package/lib/completion.js +82 -75
- package/lib/validate.js +0 -1
- package/package.json +2 -2
package/debug.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createParser } from '@algosail/parser'
|
|
3
|
+
import { readFile } from 'node:fs/promises'
|
|
4
|
+
import { pathToFileURL } from 'node:url'
|
|
5
|
+
import { resolve } from 'node:path'
|
|
6
|
+
|
|
7
|
+
const filePath = process.argv[2]
|
|
8
|
+
|
|
9
|
+
if (!filePath) {
|
|
10
|
+
console.error('Usage: node debug.js <path-to-file.sail>')
|
|
11
|
+
process.exit(1)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const absPath = resolve(filePath)
|
|
15
|
+
const uri = pathToFileURL(absPath).href
|
|
16
|
+
const text = await readFile(absPath, 'utf8')
|
|
17
|
+
|
|
18
|
+
console.log(`\n=== Parsing: ${absPath} ===\n`)
|
|
19
|
+
|
|
20
|
+
const parser = await createParser()
|
|
21
|
+
const result = await parser.parseSail(uri, text)
|
|
22
|
+
|
|
23
|
+
console.log('--- errors ---')
|
|
24
|
+
if (result.errors.length === 0) {
|
|
25
|
+
console.log('(none)')
|
|
26
|
+
} else {
|
|
27
|
+
for (const err of result.errors) {
|
|
28
|
+
const { row, column } = err.startPosition
|
|
29
|
+
console.log(` [${row}:${column}] ${err.type}: ${JSON.stringify(err.text)}`)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
console.log('\n--- groups ---')
|
|
34
|
+
if (Object.keys(result.groups).length === 0) {
|
|
35
|
+
console.log('(none)')
|
|
36
|
+
} else {
|
|
37
|
+
for (const [name, group] of Object.entries(result.groups)) {
|
|
38
|
+
const tags = group.tags.map((t) => t.name).join(', ')
|
|
39
|
+
console.log(` &${name} tags: [${tags}] doc: ${group.doc ?? '—'}`)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
console.log('\n--- maps ---')
|
|
44
|
+
if (Object.keys(result.maps).length === 0) {
|
|
45
|
+
console.log('(none)')
|
|
46
|
+
} else {
|
|
47
|
+
for (const [name, map] of Object.entries(result.maps)) {
|
|
48
|
+
const fields = map.fields.map((f) => `.${f.name}`).join(', ')
|
|
49
|
+
console.log(` $${name} fields: [${fields}] doc: ${map.doc ?? '—'}`)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.log('\n--- words ---')
|
|
54
|
+
if (result.words.length === 0) {
|
|
55
|
+
console.log('(none)')
|
|
56
|
+
} else {
|
|
57
|
+
for (const word of result.words) {
|
|
58
|
+
console.log(` @${word.name} sig: ${word.sig ?? '—'}`)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
console.log('\n--- modules ---')
|
|
63
|
+
if (Object.keys(result.modules).length === 0) {
|
|
64
|
+
console.log('(none)')
|
|
65
|
+
} else {
|
|
66
|
+
for (const [alias, mod] of Object.entries(result.modules)) {
|
|
67
|
+
console.log(` ~${alias} uri: ${mod.uri}`)
|
|
68
|
+
}
|
|
69
|
+
}
|
package/lib/completion.js
CHANGED
|
@@ -2,7 +2,18 @@ import { CompletionItemKind } from 'vscode-languageserver'
|
|
|
2
2
|
import { MarkupKind } from 'vscode-languageserver-types'
|
|
3
3
|
import { builtinWords } from '@algosail/builtins'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
function item(label, kind, detail, doc) {
|
|
6
|
+
return {
|
|
7
|
+
label,
|
|
8
|
+
insertText: label.slice(1),
|
|
9
|
+
filterText: label,
|
|
10
|
+
kind,
|
|
11
|
+
detail,
|
|
12
|
+
documentation: doc ? { kind: MarkupKind.Markdown, value: doc } : undefined,
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getCompletionItems(parser, uri) {
|
|
6
17
|
const items = []
|
|
7
18
|
|
|
8
19
|
for (const b of Object.values(builtinWords)) {
|
|
@@ -15,110 +26,106 @@ export function getCompletionItems(connection, parser, uri) {
|
|
|
15
26
|
}
|
|
16
27
|
|
|
17
28
|
const ast = parser.getAST(uri)
|
|
18
|
-
connection.console.error(`[sail-lsp] Failed to parse ${uri}: ${ast}`)
|
|
19
|
-
|
|
20
29
|
if (!ast) return items
|
|
21
30
|
|
|
22
31
|
for (const [key, module] of Object.entries(ast.modules)) {
|
|
23
32
|
for (const group of Object.values(module.groups)) {
|
|
24
|
-
items.push(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
items.push(
|
|
34
|
+
item(
|
|
35
|
+
`~${key}&${group.name}`,
|
|
36
|
+
CompletionItemKind.Enum,
|
|
37
|
+
`Group of tags ${group.tags.map((t) => t.name).join(', ')}`,
|
|
38
|
+
group.doc,
|
|
39
|
+
),
|
|
40
|
+
)
|
|
30
41
|
}
|
|
31
42
|
|
|
32
43
|
for (const tag of Object.values(module.tags)) {
|
|
33
|
-
items.push(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
items.push(
|
|
45
|
+
item(
|
|
46
|
+
`~${key}#${tag.name}`,
|
|
47
|
+
CompletionItemKind.EnumMember,
|
|
48
|
+
`Tag constructor in ~${key}&${tag.group.name}`,
|
|
49
|
+
tag.doc,
|
|
50
|
+
),
|
|
51
|
+
)
|
|
52
|
+
items.push(
|
|
53
|
+
item(
|
|
54
|
+
`~${key}_${tag.name}`,
|
|
55
|
+
CompletionItemKind.EnumMember,
|
|
56
|
+
`Tag pattern in ~${key}&${tag.group.name}`,
|
|
57
|
+
tag.doc,
|
|
58
|
+
),
|
|
59
|
+
)
|
|
45
60
|
}
|
|
46
61
|
|
|
47
62
|
for (const map of Object.values(module.maps)) {
|
|
48
|
-
items.push(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
detail: `Map $${map.name}`,
|
|
52
|
-
documentation: map.doc ? { kind: MarkupKind.Markdown, value: map.doc } : undefined,
|
|
53
|
-
})
|
|
63
|
+
items.push(
|
|
64
|
+
item(`~${key}$${map.name}`, CompletionItemKind.Struct, `Map $${map.name}`, map.doc),
|
|
65
|
+
)
|
|
54
66
|
for (const field of map.fields) {
|
|
55
|
-
items.push(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
items.push(
|
|
68
|
+
item(
|
|
69
|
+
`~${key}$${map.name}.${field.name}`,
|
|
70
|
+
CompletionItemKind.Field,
|
|
71
|
+
`Field .${field.name}${field.type ? ` (${field.type.kind})` : ''} of ~${key}$${map.name}`,
|
|
72
|
+
field.doc,
|
|
73
|
+
),
|
|
74
|
+
)
|
|
61
75
|
}
|
|
62
76
|
}
|
|
63
77
|
|
|
64
78
|
for (const word of module.words) {
|
|
65
|
-
items.push({
|
|
66
|
-
label: `~${key}/${word.name}`,
|
|
67
|
-
kind: CompletionItemKind.Function,
|
|
68
|
-
detail: word.sig,
|
|
69
|
-
documentation: word.doc ? { kind: MarkupKind.Markdown, value: word.doc } : undefined,
|
|
70
|
-
})
|
|
79
|
+
items.push(item(`~${key}/${word.name}`, CompletionItemKind.Function, word.sig, word.doc))
|
|
71
80
|
}
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
for (const group of Object.values(ast.groups)) {
|
|
75
|
-
items.push(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
items.push(
|
|
85
|
+
item(
|
|
86
|
+
`&${group.name}`,
|
|
87
|
+
CompletionItemKind.Enum,
|
|
88
|
+
`Group of tags ${group.tags.map((t) => t.name).join(', ')}`,
|
|
89
|
+
group.doc,
|
|
90
|
+
),
|
|
91
|
+
)
|
|
81
92
|
}
|
|
82
93
|
|
|
83
94
|
for (const tag of Object.values(ast.tags)) {
|
|
84
|
-
items.push(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
items.push(
|
|
96
|
+
item(
|
|
97
|
+
`#${tag.name}`,
|
|
98
|
+
CompletionItemKind.EnumMember,
|
|
99
|
+
`Tag constructor in &${tag.group.name}`,
|
|
100
|
+
tag.doc,
|
|
101
|
+
),
|
|
102
|
+
)
|
|
103
|
+
items.push(
|
|
104
|
+
item(
|
|
105
|
+
`_${tag.name}`,
|
|
106
|
+
CompletionItemKind.EnumMember,
|
|
107
|
+
`Tag pattern in &${tag.group.name}`,
|
|
108
|
+
tag.doc,
|
|
109
|
+
),
|
|
110
|
+
)
|
|
96
111
|
}
|
|
97
112
|
|
|
98
113
|
for (const map of Object.values(ast.maps)) {
|
|
99
|
-
items.push({
|
|
100
|
-
label: `$${map.name}`,
|
|
101
|
-
kind: CompletionItemKind.Struct,
|
|
102
|
-
detail: `Map $${map.name}`,
|
|
103
|
-
documentation: map.doc ? { kind: MarkupKind.Markdown, value: map.doc } : undefined,
|
|
104
|
-
})
|
|
114
|
+
items.push(item(`$${map.name}`, CompletionItemKind.Struct, `Map $${map.name}`, map.doc))
|
|
105
115
|
for (const field of map.fields) {
|
|
106
|
-
items.push(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
items.push(
|
|
117
|
+
item(
|
|
118
|
+
`$${map.name}.${field.name}`,
|
|
119
|
+
CompletionItemKind.Field,
|
|
120
|
+
`Field .${field.name}${field.type ? ` (${field.type.kind})` : ''} of $${map.name}`,
|
|
121
|
+
field.doc,
|
|
122
|
+
),
|
|
123
|
+
)
|
|
112
124
|
}
|
|
113
125
|
}
|
|
114
126
|
|
|
115
127
|
for (const word of ast.words) {
|
|
116
|
-
items.push({
|
|
117
|
-
label: `/${word.name}`,
|
|
118
|
-
kind: CompletionItemKind.Function,
|
|
119
|
-
detail: word.sig,
|
|
120
|
-
documentation: word.doc ? { kind: MarkupKind.Markdown, value: word.doc } : undefined,
|
|
121
|
-
})
|
|
128
|
+
items.push(item(`/${word.name}`, CompletionItemKind.Function, word.sig, word.doc))
|
|
122
129
|
}
|
|
123
130
|
|
|
124
131
|
return items
|
package/lib/validate.js
CHANGED
|
@@ -3,7 +3,6 @@ import { DiagnosticSeverity } from 'vscode-languageserver'
|
|
|
3
3
|
export const validateDocument = async (connection, parser, uri, text) => {
|
|
4
4
|
try {
|
|
5
5
|
const res = await parser.parseSail(uri, text)
|
|
6
|
-
connection.console.error(`[sail-lsp] Failed to parse ${uri}: ${res}`)
|
|
7
6
|
|
|
8
7
|
const diagnostics = res.errors.map((err) => ({
|
|
9
8
|
severity: DiagnosticSeverity.Error,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algosail/lsp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@algosail/builtins": "^0.0.1",
|
|
11
|
-
"@algosail/parser": "^0.0.
|
|
11
|
+
"@algosail/parser": "^0.0.8",
|
|
12
12
|
"vscode-languageserver": "^9.0.1",
|
|
13
13
|
"vscode-languageserver-textdocument": "^1.0.11"
|
|
14
14
|
}
|