@stillwind/language-server 0.0.0-stage → 0.1.0-rc.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/LICENSE +21 -0
- package/README.md +11 -2
- package/dist/browser.d.ts +20 -0
- package/dist/browser.js +37 -0
- package/dist/browser.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/node.d.ts +9 -0
- package/dist/node.js +25 -0
- package/dist/node.js.map +1 -0
- package/dist/server-p2n04Evx.js +658 -0
- package/dist/server-p2n04Evx.js.map +1 -0
- package/dist/server-pVyUFO88.d.ts +49 -0
- package/package.json +48 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Stillwind contributors
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @stillwind/language-server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Stillwind compiles Tailwind CSS v4 utilities into component props and static CSS.
|
|
4
|
+
It uses theme rules and compiler checks to keep styling code in order, even when
|
|
5
|
+
AI agents write much of it.
|
|
6
|
+
|
|
7
|
+
`@stillwind/language-server` provides Stillwind's Language Server Protocol
|
|
8
|
+
handlers and Node/browser transports. The CLI and VS Code extension use these
|
|
9
|
+
services for diagnostics and editor queries.
|
|
10
|
+
|
|
11
|
+
See [Embedding the language server](https://github.com/SegaraRai/stillwind/blob/main/docs/standalone-analysis.md#embedding-the-language-server)
|
|
12
|
+
for connection ownership and analysis providers.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { t as LanguageServerOptions } from "./server-pVyUFO88.js";
|
|
2
|
+
import { BrowserMessageReader } from "vscode-languageserver/browser";
|
|
3
|
+
/**
|
|
4
|
+
* Starts LSP message transport using analysis services supplied by the embedding application.
|
|
5
|
+
*
|
|
6
|
+
* @param port - Worker or MessagePort supported by the browser LSP message reader and writer.
|
|
7
|
+
* @param options - Workspace factory and optional exit handler. The factory supplies browser
|
|
8
|
+
* compiler and module services independently of the CLI.
|
|
9
|
+
* @returns Cleanup for analysis services and the connection's reader and writer.
|
|
10
|
+
*/
|
|
11
|
+
export declare function startBrowserLanguageServer(port: ConstructorParameters<typeof BrowserMessageReader>[0], options: LanguageServerOptions): {
|
|
12
|
+
/**
|
|
13
|
+
* Closes analysis services and disposes transport resources even if service cleanup fails.
|
|
14
|
+
*
|
|
15
|
+
* @returns A promise that resolves after cleanup.
|
|
16
|
+
* @throws If analysis service cleanup fails.
|
|
17
|
+
*/
|
|
18
|
+
dispose(): Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=browser.d.ts.map
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { t as createLanguageServer } from "./server-p2n04Evx.js";
|
|
2
|
+
import { BrowserMessageReader, BrowserMessageWriter, ProposedFeatures, createConnection } from "vscode-languageserver/browser";
|
|
3
|
+
// src/browser.ts
|
|
4
|
+
/**
|
|
5
|
+
* Starts LSP message transport using analysis services supplied by the embedding application.
|
|
6
|
+
*
|
|
7
|
+
* @param port - Worker or MessagePort supported by the browser LSP message reader and writer.
|
|
8
|
+
* @param options - Workspace factory and optional exit handler. The factory supplies browser
|
|
9
|
+
* compiler and module services independently of the CLI.
|
|
10
|
+
* @returns Cleanup for analysis services and the connection's reader and writer.
|
|
11
|
+
*/
|
|
12
|
+
function startBrowserLanguageServer(port, options) {
|
|
13
|
+
const reader = new BrowserMessageReader(port);
|
|
14
|
+
const writer = new BrowserMessageWriter(port);
|
|
15
|
+
const connection = createConnection(ProposedFeatures.all, reader, writer);
|
|
16
|
+
const server = createLanguageServer(connection, options);
|
|
17
|
+
connection.listen();
|
|
18
|
+
return {
|
|
19
|
+
/**
|
|
20
|
+
* Closes analysis before releasing the connection, reader, and writer in the cleanup block.
|
|
21
|
+
*
|
|
22
|
+
* @returns Completion of service and transport cleanup.
|
|
23
|
+
* @throws If service cleanup fails, after transport resources have been released.
|
|
24
|
+
*/
|
|
25
|
+
async dispose() {
|
|
26
|
+
try {
|
|
27
|
+
await server.dispose();
|
|
28
|
+
} finally {
|
|
29
|
+
connection.dispose();
|
|
30
|
+
reader.dispose();
|
|
31
|
+
writer.dispose();
|
|
32
|
+
}
|
|
33
|
+
} };
|
|
34
|
+
}
|
|
35
|
+
export { startBrowserLanguageServer };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","names":[],"sources":["../src/browser.ts"],"sourcesContent":["import {\n BrowserMessageReader,\n BrowserMessageWriter,\n createConnection,\n ProposedFeatures,\n} from \"vscode-languageserver/browser\";\n\nimport { createLanguageServer, type LanguageServerOptions } from \"./server.ts\";\n\n/**\n * Starts LSP message transport using analysis services supplied by the embedding application.\n *\n * @param port - Worker or MessagePort supported by the browser LSP message reader and writer.\n * @param options - Workspace factory and optional exit handler. The factory supplies browser\n * compiler and module services independently of the CLI.\n * @returns Cleanup for analysis services and the connection's reader and writer.\n */\nexport function startBrowserLanguageServer(\n port: ConstructorParameters<typeof BrowserMessageReader>[0],\n options: LanguageServerOptions,\n): {\n /**\n * Closes analysis services and disposes transport resources even if service cleanup fails.\n *\n * @returns A promise that resolves after cleanup.\n * @throws If analysis service cleanup fails.\n */\n dispose(): Promise<void>;\n} {\n const reader = new BrowserMessageReader(port);\n const writer = new BrowserMessageWriter(port);\n const connection = createConnection(ProposedFeatures.all, reader, writer);\n const server = createLanguageServer(connection, options);\n connection.listen();\n\n return {\n /**\n * Closes analysis before releasing the connection, reader, and writer in the cleanup block.\n *\n * @returns Completion of service and transport cleanup.\n * @throws If service cleanup fails, after transport resources have been released.\n */\n async dispose() {\n try {\n await server.dispose();\n } finally {\n connection.dispose();\n reader.dispose();\n writer.dispose();\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;;AAiBA,SAAgB,2BACd,MACA,SASA;CACA,MAAM,SAAS,IAAI,qBAAqB,IAAI;CAC5C,MAAM,SAAS,IAAI,qBAAqB,IAAI;CAC5C,MAAM,aAAa,iBAAiB,iBAAiB,KAAK,QAAQ,MAAM;CACxE,MAAM,SAAS,qBAAqB,YAAY,OAAO;CACvD,WAAW,OAAO;CAElB,OAAO;;;;;;;AAOL,MAAM,UAAU;EACd,IAAI;GACF,MAAM,OAAO,QAAQ;EACvB,UAAU;GACR,WAAW,QAAQ;GACnB,OAAO,QAAQ;GACf,OAAO,QAAQ;EACjB;CACF,EACF;AACF"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as createLanguageServer } from "./server-p2n04Evx.js";
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starts a stdio LSP connection with isolated Node analysis processes.
|
|
3
|
+
*
|
|
4
|
+
* @param config - Explicit configuration path, resolved from the process working directory.
|
|
5
|
+
* Omission discovers configurations from client workspace folders, or the working directory.
|
|
6
|
+
* The process exits with code 0 after shutdown followed by exit, or code 1 after exit alone.
|
|
7
|
+
*/
|
|
8
|
+
export declare function startLanguageServer(config?: string): void;
|
|
9
|
+
//# sourceMappingURL=node.d.ts.map
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { t as createLanguageServer } from "./server-p2n04Evx.js";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { openNodeWorkspaces } from "@stillwind/analysis/node";
|
|
4
|
+
import { ProposedFeatures, createConnection } from "vscode-languageserver/node";
|
|
5
|
+
// src/node.ts
|
|
6
|
+
/**
|
|
7
|
+
* Starts a stdio LSP connection with isolated Node analysis processes.
|
|
8
|
+
*
|
|
9
|
+
* @param config - Explicit configuration path, resolved from the process working directory.
|
|
10
|
+
* Omission discovers configurations from client workspace folders, or the working directory.
|
|
11
|
+
* The process exits with code 0 after shutdown followed by exit, or code 1 after exit alone.
|
|
12
|
+
*/
|
|
13
|
+
function startLanguageServer(config) {
|
|
14
|
+
const connection = createConnection(ProposedFeatures.all, process.stdin, process.stdout);
|
|
15
|
+
createLanguageServer(connection, {
|
|
16
|
+
openWorkspaces: (context) => openNodeWorkspaces(context, config),
|
|
17
|
+
onExit: (shutdown) => {
|
|
18
|
+
process.exit(shutdown ? 0 : 1);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
connection.listen();
|
|
22
|
+
}
|
|
23
|
+
export { startLanguageServer };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","names":[],"sources":["../src/node.ts"],"sourcesContent":["import process from \"node:process\";\n\nimport { openNodeWorkspaces } from \"@stillwind/analysis/node\";\nimport { createConnection, ProposedFeatures } from \"vscode-languageserver/node\";\n\nimport { createLanguageServer } from \"./server.ts\";\n\n/**\n * Starts a stdio LSP connection with isolated Node analysis processes.\n *\n * @param config - Explicit configuration path, resolved from the process working directory.\n * Omission discovers configurations from client workspace folders, or the working directory.\n * The process exits with code 0 after shutdown followed by exit, or code 1 after exit alone.\n */\nexport function startLanguageServer(config?: string): void {\n const connection = createConnection(ProposedFeatures.all, process.stdin, process.stdout);\n createLanguageServer(connection, {\n openWorkspaces: (context) => openNodeWorkspaces(context, config),\n onExit: (shutdown) => {\n process.exit(shutdown ? 0 : 1);\n },\n });\n connection.listen();\n}\n"],"mappings":";;;;;;;;;;;;AAcA,SAAgB,oBAAoB,QAAuB;CACzD,MAAM,aAAa,iBAAiB,iBAAiB,KAAK,QAAQ,OAAO,QAAQ,MAAM;CACvF,qBAAqB,YAAY;EAC/B,iBAAiB,YAAY,mBAAmB,SAAS,MAAM;EAC/D,SAAS,aAAa;GACpB,QAAQ,KAAK,WAAW,IAAI,CAAC;EAC/B;CACF,CAAC;CACD,WAAW,OAAO;AACpB"}
|
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
import { CodeActionKind, CompletionItemKind, DiagnosticSeverity, DidChangeWatchedFilesNotification, InsertTextFormat, MarkupKind, TextDocumentSyncKind, TextDocuments } from "vscode-languageserver";
|
|
2
|
+
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
3
|
+
// src/editor.ts
|
|
4
|
+
const sortKind = "source.sort.stillwind";
|
|
5
|
+
const fixAllKind = "source.fixAll.stillwind";
|
|
6
|
+
/** Source actions advertised in fix-all order followed by utility sorting. */
|
|
7
|
+
const editorCodeActionKinds = [fixAllKind, sortKind];
|
|
8
|
+
/**
|
|
9
|
+
* Registers hover, definitions, completion, colors, plugin links, and source actions.
|
|
10
|
+
*
|
|
11
|
+
* @param connection - Caller-owned connection on which handlers are installed.
|
|
12
|
+
* @param documents - Open original buffers used to convert UTF-16 offsets to LSP positions.
|
|
13
|
+
* @param query - Query implementation that rejects obsolete results and honors cancellation.
|
|
14
|
+
*/
|
|
15
|
+
function registerEditorFeatures(connection, documents, query) {
|
|
16
|
+
connection.onDefinition(async (params, token) => {
|
|
17
|
+
const document = documents.get(params.textDocument.uri);
|
|
18
|
+
if (!document) return [];
|
|
19
|
+
const definitions = (await query(document.uri, {
|
|
20
|
+
kind: "definition",
|
|
21
|
+
offset: document.offsetAt(params.position)
|
|
22
|
+
}, token)).flatMap((entry) => entry.result.definitions ?? []);
|
|
23
|
+
return definitions.filter((definition, index) => definitions.findIndex((other) => JSON.stringify(other) === JSON.stringify(definition)) === index).map((definition) => ({
|
|
24
|
+
uri: definition.uri,
|
|
25
|
+
range: {
|
|
26
|
+
start: {
|
|
27
|
+
line: definition.startLine,
|
|
28
|
+
character: definition.startColumn
|
|
29
|
+
},
|
|
30
|
+
end: {
|
|
31
|
+
line: definition.endLine,
|
|
32
|
+
character: definition.endColumn
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
});
|
|
37
|
+
connection.onDocumentLinks(async (params, token) => {
|
|
38
|
+
const document = documents.get(params.textDocument.uri);
|
|
39
|
+
if (!document) return [];
|
|
40
|
+
const links = (await query(document.uri, { kind: "links" }, token)).flatMap((entry) => entry.result.links ?? []);
|
|
41
|
+
return links.filter((link, index) => link.target && links.findIndex((other) => other.start === link.start && other.end === link.end && other.target === link.target) === index && !links.some((other) => other.start === link.start && other.end === link.end && other.target !== link.target)).map((link) => ({
|
|
42
|
+
range: offsets(document, link),
|
|
43
|
+
target: link.target
|
|
44
|
+
}));
|
|
45
|
+
});
|
|
46
|
+
connection.onHover(async (params, token) => {
|
|
47
|
+
const document = documents.get(params.textDocument.uri);
|
|
48
|
+
if (!document) return null;
|
|
49
|
+
const answers = (await query(document.uri, {
|
|
50
|
+
kind: "hover",
|
|
51
|
+
offset: document.offsetAt(params.position)
|
|
52
|
+
}, token)).filter((entry) => entry.result.hover);
|
|
53
|
+
if (!answers.length) return null;
|
|
54
|
+
const seen = /* @__PURE__ */ new Set();
|
|
55
|
+
const contents = answers.flatMap((entry) => {
|
|
56
|
+
const hover = entry.result.hover;
|
|
57
|
+
const key = JSON.stringify(hover);
|
|
58
|
+
if (seen.has(key)) return [];
|
|
59
|
+
seen.add(key);
|
|
60
|
+
return [`${answers.length > 1 ? `${entry.config} · project ${entry.project + 1}\n\n` : ""}${hoverMarkdown(hover)}`];
|
|
61
|
+
}).join("\n\n");
|
|
62
|
+
return {
|
|
63
|
+
contents: {
|
|
64
|
+
kind: MarkupKind.Markdown,
|
|
65
|
+
value: contents
|
|
66
|
+
},
|
|
67
|
+
range: offsets(document, answers[0].result.hover)
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
connection.onCompletion(async (params, token) => {
|
|
71
|
+
const document = documents.get(params.textDocument.uri);
|
|
72
|
+
if (!document) return [];
|
|
73
|
+
const version = document.version;
|
|
74
|
+
const items = (await query(document.uri, {
|
|
75
|
+
kind: "completion",
|
|
76
|
+
offset: document.offsetAt(params.position)
|
|
77
|
+
}, token)).flatMap((entry) => (entry.result.completions ?? []).map((item) => ({
|
|
78
|
+
label: item.label,
|
|
79
|
+
detail: item.detail,
|
|
80
|
+
sortText: item.sortText,
|
|
81
|
+
insertTextFormat: item.snippet ? InsertTextFormat.Snippet : void 0,
|
|
82
|
+
command: item.retrigger ? {
|
|
83
|
+
title: "Continue completion",
|
|
84
|
+
command: "editor.action.triggerSuggest"
|
|
85
|
+
} : void 0,
|
|
86
|
+
kind: item.keyword ? CompletionItemKind.Keyword : item.category === "directory" ? CompletionItemKind.Folder : item.category === "file" ? CompletionItemKind.File : item.category === "module" || item.variant || item.candidate.endsWith(":") ? CompletionItemKind.Module : item.marker ? CompletionItemKind.Class : CompletionItemKind.Value,
|
|
87
|
+
textEdit: {
|
|
88
|
+
range: offsets(document, item),
|
|
89
|
+
newText: item.snippet ?? item.newText
|
|
90
|
+
},
|
|
91
|
+
data: {
|
|
92
|
+
uri: document.uri,
|
|
93
|
+
version,
|
|
94
|
+
revision: entry.result.revision,
|
|
95
|
+
candidate: item.candidate,
|
|
96
|
+
input: item.input,
|
|
97
|
+
snapshot: item.snapshot,
|
|
98
|
+
project: entry.project,
|
|
99
|
+
config: entry.config
|
|
100
|
+
}
|
|
101
|
+
})));
|
|
102
|
+
return items.filter((item, index) => items.findIndex((other) => other.label === item.label && JSON.stringify(other.textEdit) === JSON.stringify(item.textEdit)) === index);
|
|
103
|
+
});
|
|
104
|
+
connection.onCompletionResolve(async (item, token) => {
|
|
105
|
+
const detail = item.detail;
|
|
106
|
+
delete item.documentation;
|
|
107
|
+
delete item.detail;
|
|
108
|
+
const data = item.data;
|
|
109
|
+
if (!data || typeof data.uri !== "string" || typeof data.candidate !== "string" || typeof data.input !== "number" || typeof data.snapshot !== "string" || documents.get(data.uri)?.version !== data.version) return item;
|
|
110
|
+
const answer = (await query(data.uri, {
|
|
111
|
+
kind: "resolve",
|
|
112
|
+
candidate: data.candidate,
|
|
113
|
+
input: data.input,
|
|
114
|
+
snapshot: data.snapshot
|
|
115
|
+
}, token)).find((entry) => entry.project === data.project && entry.config === data.config && entry.result.revision === data.revision)?.result.hover;
|
|
116
|
+
if (answer) {
|
|
117
|
+
item.detail = answer.detail ?? detail;
|
|
118
|
+
item.documentation = {
|
|
119
|
+
kind: MarkupKind.Markdown,
|
|
120
|
+
value: hoverMarkdown(answer)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return item;
|
|
124
|
+
});
|
|
125
|
+
connection.onDocumentColor(async (params, token) => {
|
|
126
|
+
const document = documents.get(params.textDocument.uri);
|
|
127
|
+
if (!document) return [];
|
|
128
|
+
const colors = (await query(document.uri, { kind: "colors" }, token)).flatMap((entry) => entry.result.colors ?? []);
|
|
129
|
+
return colors.filter((color, index) => colors.findIndex((other) => JSON.stringify(other) === JSON.stringify(color)) === index && !colors.some((other) => other.start === color.start && other.end === color.end && JSON.stringify(other) !== JSON.stringify(color))).map((color) => ({
|
|
130
|
+
range: offsets(document, color),
|
|
131
|
+
color: {
|
|
132
|
+
red: color.red,
|
|
133
|
+
green: color.green,
|
|
134
|
+
blue: color.blue,
|
|
135
|
+
alpha: color.alpha
|
|
136
|
+
}
|
|
137
|
+
}));
|
|
138
|
+
});
|
|
139
|
+
connection.onColorPresentation(async (params, token) => {
|
|
140
|
+
const document = documents.get(params.textDocument.uri);
|
|
141
|
+
if (!document) return [];
|
|
142
|
+
return (await query(document.uri, {
|
|
143
|
+
kind: "colorPresentation",
|
|
144
|
+
start: document.offsetAt(params.range.start),
|
|
145
|
+
end: document.offsetAt(params.range.end),
|
|
146
|
+
color: params.color
|
|
147
|
+
}, token)).flatMap((entry) => (entry.result.edits ?? []).map((edit) => ({
|
|
148
|
+
label: edit.newText,
|
|
149
|
+
textEdit: {
|
|
150
|
+
range: offsets(document, edit),
|
|
151
|
+
newText: edit.newText
|
|
152
|
+
}
|
|
153
|
+
}))).filter((item, index, items) => items.findIndex((other) => JSON.stringify(item) === JSON.stringify(other)) === index);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Formats CSS previews and dialect documentation, and explains authored runtime key expressions.
|
|
158
|
+
* Expression line breaks become spaces, and code-span delimiters exceed every authored
|
|
159
|
+
* backtick run so expressions remain literal Markdown. The supplied hover remains unchanged.
|
|
160
|
+
*
|
|
161
|
+
* @param hover - CSS preview and optional authored expressions for runtime view-transition names.
|
|
162
|
+
* @returns Markdown with CSS first and expression notes in their supplied order.
|
|
163
|
+
*/
|
|
164
|
+
function hoverMarkdown(hover) {
|
|
165
|
+
const notes = (hover.runtimeNames ?? []).map((expression) => {
|
|
166
|
+
const text = expression.replace(/\r\n?|\n/g, " ");
|
|
167
|
+
const ticks = "`".repeat(Math.max(0, ...[...text.matchAll(/`+/g)].map((match) => match[0].length)) + 1);
|
|
168
|
+
return `view-transition-name is computed at runtime from ${ticks} ${text} ${ticks}.`;
|
|
169
|
+
});
|
|
170
|
+
return [
|
|
171
|
+
hover.css ? `\`\`\`css\n${hover.css}\n\`\`\`` : void 0,
|
|
172
|
+
hover.documentation,
|
|
173
|
+
...notes
|
|
174
|
+
].filter(Boolean).join("\n\n");
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Builds versioned source actions for each project and removes actions with identical edits.
|
|
178
|
+
* Each action contains one project's edits, so differing project results remain separate.
|
|
179
|
+
*
|
|
180
|
+
* @param document - Open original buffer that the query reads and the returned edits target.
|
|
181
|
+
* @param only - Requested source kinds or their prefixes. Omission or an empty list produces no actions.
|
|
182
|
+
* @param token - Cancellation forwarded to each query.
|
|
183
|
+
* @param query - Query implementation that discards changed buffers and cancelled requests.
|
|
184
|
+
* @returns Fix-all actions followed by sort actions, preserving project order within each kind.
|
|
185
|
+
* @throws If a query rejects.
|
|
186
|
+
*/
|
|
187
|
+
async function sourceActions(document, only, token, query) {
|
|
188
|
+
const actions = [];
|
|
189
|
+
for (const [kind, operation, title] of [[
|
|
190
|
+
fixAllKind,
|
|
191
|
+
"fixes",
|
|
192
|
+
"Fix all Stillwind lint findings"
|
|
193
|
+
], [
|
|
194
|
+
sortKind,
|
|
195
|
+
"sort",
|
|
196
|
+
"Sort Stillwind utilities"
|
|
197
|
+
]]) {
|
|
198
|
+
if (!only?.some((requested) => kind === requested || kind.startsWith(`${requested}.`))) continue;
|
|
199
|
+
const entries = await query(document.uri, { kind: operation }, token);
|
|
200
|
+
for (const entry of entries) {
|
|
201
|
+
if (!entry.result.edits?.length) continue;
|
|
202
|
+
const edit = { documentChanges: [{
|
|
203
|
+
textDocument: {
|
|
204
|
+
uri: document.uri,
|
|
205
|
+
version: document.version
|
|
206
|
+
},
|
|
207
|
+
edits: entry.result.edits.map((edit) => ({
|
|
208
|
+
range: offsets(document, edit),
|
|
209
|
+
newText: edit.newText
|
|
210
|
+
}))
|
|
211
|
+
}] };
|
|
212
|
+
if (actions.some((action) => action.kind === kind && JSON.stringify(action.edit) === JSON.stringify(edit))) continue;
|
|
213
|
+
actions.push({
|
|
214
|
+
title: `${title}${entries.length > 1 ? ` (${entry.config}, project ${entry.project + 1})` : ""}`,
|
|
215
|
+
kind,
|
|
216
|
+
edit
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return actions;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Converts original UTF-16 offsets to positions using the open document's line table.
|
|
224
|
+
*
|
|
225
|
+
* @param document - Document containing the text from which the offsets were measured.
|
|
226
|
+
* @param range - Half-open UTF-16 range. TextDocument clamps offsets outside the document.
|
|
227
|
+
* @returns LSP positions with zero-based lines and UTF-16 character offsets.
|
|
228
|
+
*/
|
|
229
|
+
function offsets(document, range) {
|
|
230
|
+
return {
|
|
231
|
+
start: document.positionAt(range.start),
|
|
232
|
+
end: document.positionAt(range.end)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
// src/server.ts
|
|
236
|
+
/**
|
|
237
|
+
* Registers synchronization, diagnostics, fixes, hover, completion, colors, and sorting.
|
|
238
|
+
* Analysis uses captured buffers and suppresses obsolete results. Quick fixes require every edited
|
|
239
|
+
* document to be open and to match the report's source fingerprint.
|
|
240
|
+
*
|
|
241
|
+
* @param connection - Caller-owned connection. Call listen after registration and dispose the
|
|
242
|
+
* transport when finished. Diagnostic locations must use original documents and UTF-16 positions.
|
|
243
|
+
* @param options - Workspace factory and optional exit handler. This server owns the opened services.
|
|
244
|
+
* @returns Cleanup for the analysis services. It does not dispose the connection or its transport.
|
|
245
|
+
*/
|
|
246
|
+
function createLanguageServer(connection, options) {
|
|
247
|
+
const documents = new TextDocuments(TextDocument);
|
|
248
|
+
const workspaces = /* @__PURE__ */ new Map();
|
|
249
|
+
const errors = /* @__PURE__ */ new Map();
|
|
250
|
+
const cache = /* @__PURE__ */ new Map();
|
|
251
|
+
const published = /* @__PURE__ */ new Set();
|
|
252
|
+
let roots = [];
|
|
253
|
+
let initializationOptions;
|
|
254
|
+
let registryDirectives = false;
|
|
255
|
+
let snippets = false;
|
|
256
|
+
let generation = 0;
|
|
257
|
+
let controls = Promise.resolve();
|
|
258
|
+
let timer;
|
|
259
|
+
let shutdown = false;
|
|
260
|
+
let foldersSupported = false;
|
|
261
|
+
let dynamicWatch = false;
|
|
262
|
+
let active;
|
|
263
|
+
let disposal;
|
|
264
|
+
/**
|
|
265
|
+
* Invalidates current results and serializes a workspace or document mutation.
|
|
266
|
+
* Callback failures are logged and absorbed so subsequent mutations can run.
|
|
267
|
+
*
|
|
268
|
+
* @param action - Mutation to execute after previous control work. Shutdown skips registration.
|
|
269
|
+
*/
|
|
270
|
+
const control = (action) => {
|
|
271
|
+
if (shutdown) return;
|
|
272
|
+
active?.abort();
|
|
273
|
+
generation++;
|
|
274
|
+
cache.clear();
|
|
275
|
+
controls = controls.then(action).catch((error) => {
|
|
276
|
+
connection.console.error(String(error));
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* Closes existing services, opens the current roots, and replays every open buffer.
|
|
281
|
+
*
|
|
282
|
+
* @returns Completion of service replacement and buffer replay.
|
|
283
|
+
* @throws If service closure, the workspace factory, or buffer replay fails.
|
|
284
|
+
*/
|
|
285
|
+
const open = async () => {
|
|
286
|
+
await Promise.all([...workspaces.values()].map((workspace) => workspace.close()));
|
|
287
|
+
workspaces.clear();
|
|
288
|
+
errors.clear();
|
|
289
|
+
const opened = await options.openWorkspaces({
|
|
290
|
+
workspaceFolders: roots,
|
|
291
|
+
initializationOptions
|
|
292
|
+
});
|
|
293
|
+
for (const [id, error] of opened.errors ?? []) errors.set(id, error);
|
|
294
|
+
for (const [id, workspace] of opened.workspaces) {
|
|
295
|
+
workspaces.set(id, workspace);
|
|
296
|
+
for (const document of documents.all()) await workspace.update(document.uri, document.getText(), document.version);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* Sends deduplicated cached diagnostics and workspace errors, then records their document URIs.
|
|
301
|
+
* Empty notifications clear diagnostics for previously published or currently open documents.
|
|
302
|
+
*/
|
|
303
|
+
const publish = () => {
|
|
304
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
305
|
+
const seen = /* @__PURE__ */ new Set();
|
|
306
|
+
/**
|
|
307
|
+
* Appends a diagnostic only once for its document and complete serialized value.
|
|
308
|
+
*
|
|
309
|
+
* @param uri - Original document URI used to group publication.
|
|
310
|
+
* @param diagnostic - Diagnostic with original LSP positions.
|
|
311
|
+
*/
|
|
312
|
+
const add = (uri, diagnostic) => {
|
|
313
|
+
const key = JSON.stringify([uri, diagnostic]);
|
|
314
|
+
if (!seen.has(key)) {
|
|
315
|
+
seen.add(key);
|
|
316
|
+
const list = grouped.get(uri) ?? [];
|
|
317
|
+
list.push(diagnostic);
|
|
318
|
+
grouped.set(uri, list);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
for (const [uri, results] of cache) for (const entry of results) {
|
|
322
|
+
const source = `stillwind:${entry.config}:${entry.project + 1}`;
|
|
323
|
+
for (const report of entry.result.reports) {
|
|
324
|
+
const location = report.primary.location;
|
|
325
|
+
add(location.uri, {
|
|
326
|
+
range: range(location),
|
|
327
|
+
severity: report.severity === "error" ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning,
|
|
328
|
+
source,
|
|
329
|
+
code: report.code,
|
|
330
|
+
message: [report.message, ...report.notes].join("\n"),
|
|
331
|
+
relatedInformation: report.related.map((label) => ({
|
|
332
|
+
location: {
|
|
333
|
+
uri: label.location.uri,
|
|
334
|
+
range: range(label.location)
|
|
335
|
+
},
|
|
336
|
+
message: label.message ?? report.message
|
|
337
|
+
}))
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
if (entry.result.status === "incomplete") {
|
|
341
|
+
const missing = entry.result.dependencies?.filter((dependency) => dependency.status === "unresolved" || dependency.status === "unsupported").map((dependency) => `${dependency.status}: ${dependency.specifier} from ${dependency.importer}`) ?? [];
|
|
342
|
+
add(uri, {
|
|
343
|
+
range: range(),
|
|
344
|
+
severity: entry.result.error ? DiagnosticSeverity.Error : DiagnosticSeverity.Information,
|
|
345
|
+
source,
|
|
346
|
+
code: entry.result.error ? "SW_HOST" : "SW_UNVERIFIED",
|
|
347
|
+
message: [
|
|
348
|
+
entry.result.error ?? "Stillwind analysis is incomplete",
|
|
349
|
+
...missing,
|
|
350
|
+
...(entry.result.unverified ?? []).map((item) => `${item.moduleId}: ${item.reason}`)
|
|
351
|
+
].join("\n")
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
for (const document of documents.all()) for (const [file, error] of errors) add(document.uri, {
|
|
356
|
+
range: range(),
|
|
357
|
+
severity: DiagnosticSeverity.Error,
|
|
358
|
+
source: "stillwind",
|
|
359
|
+
code: "SW_HOST",
|
|
360
|
+
message: `${file}: ${error}`
|
|
361
|
+
});
|
|
362
|
+
for (const uri of /* @__PURE__ */ new Set([
|
|
363
|
+
...published,
|
|
364
|
+
...grouped.keys(),
|
|
365
|
+
...documents.all().map((document) => document.uri)
|
|
366
|
+
])) connection.sendDiagnostics({
|
|
367
|
+
uri,
|
|
368
|
+
version: documents.get(uri)?.version,
|
|
369
|
+
diagnostics: grouped.get(uri) ?? []
|
|
370
|
+
});
|
|
371
|
+
published.clear();
|
|
372
|
+
for (const uri of grouped.keys()) published.add(uri);
|
|
373
|
+
};
|
|
374
|
+
/**
|
|
375
|
+
* Analyzes open buffers after queued mutations and publishes only a current, non-stale batch.
|
|
376
|
+
* Service failures become workspace errors. An obsolete or cancelled batch leaves the cache unchanged.
|
|
377
|
+
*
|
|
378
|
+
* @param revision - Control generation captured when analysis was scheduled.
|
|
379
|
+
* @returns Completion of the analysis pass or its early discard.
|
|
380
|
+
*/
|
|
381
|
+
const analyze = async (revision) => {
|
|
382
|
+
await controls;
|
|
383
|
+
if (shutdown || revision !== generation) return;
|
|
384
|
+
const cancellation = new AbortController();
|
|
385
|
+
active = cancellation;
|
|
386
|
+
const next = /* @__PURE__ */ new Map();
|
|
387
|
+
for (const [file, workspace] of workspaces) {
|
|
388
|
+
try {
|
|
389
|
+
await workspace.prepare?.(documents.all().map((document) => document.uri), cancellation.signal);
|
|
390
|
+
} catch (error) {
|
|
391
|
+
errors.set(file, String(error));
|
|
392
|
+
}
|
|
393
|
+
if (revision !== generation || shutdown) return;
|
|
394
|
+
}
|
|
395
|
+
for (const document of documents.all()) {
|
|
396
|
+
const results = [];
|
|
397
|
+
for (const [file, workspace] of workspaces) try {
|
|
398
|
+
results.push(...await workspace.analyze(document.uri, cancellation.signal));
|
|
399
|
+
errors.delete(file);
|
|
400
|
+
} catch (error) {
|
|
401
|
+
errors.set(file, String(error));
|
|
402
|
+
}
|
|
403
|
+
if (revision !== generation || shutdown) return;
|
|
404
|
+
if (results.some(({ result }) => result.status === "stale" || result.status === "cancelled")) return;
|
|
405
|
+
next.set(document.uri, results);
|
|
406
|
+
}
|
|
407
|
+
if (revision === generation) {
|
|
408
|
+
cache.clear();
|
|
409
|
+
for (const [uri, result] of next) cache.set(uri, result);
|
|
410
|
+
publish();
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
/** Replaces the pending 40 ms timer with an analysis pass for the current control generation. */
|
|
414
|
+
const schedule = () => {
|
|
415
|
+
if (timer) clearTimeout(timer);
|
|
416
|
+
const revision = generation;
|
|
417
|
+
timer = setTimeout(() => {
|
|
418
|
+
analyze(revision).catch((error) => {
|
|
419
|
+
connection.console.error(String(error));
|
|
420
|
+
});
|
|
421
|
+
}, 40);
|
|
422
|
+
};
|
|
423
|
+
/**
|
|
424
|
+
* Queries services after queued mutations and checks document versions and source fingerprints.
|
|
425
|
+
* Query failures are logged, and the cancellation subscription is released after the request.
|
|
426
|
+
*
|
|
427
|
+
* @param uri - URI of the open original document.
|
|
428
|
+
* @param request - Editor operation expressed in that document's UTF-16 coordinates.
|
|
429
|
+
* @param token - LSP cancellation forwarded through an AbortSignal.
|
|
430
|
+
* @returns Current project results, or an empty list after changes, cancellation, or failure.
|
|
431
|
+
*/
|
|
432
|
+
const query = async (uri, request, token) => {
|
|
433
|
+
await controls;
|
|
434
|
+
if (request.kind === "completion" || request.kind === "resolve") request = {
|
|
435
|
+
...request,
|
|
436
|
+
registryDirectives,
|
|
437
|
+
snippets
|
|
438
|
+
};
|
|
439
|
+
const document = documents.get(uri);
|
|
440
|
+
if (!document || shutdown || token.isCancellationRequested) return [];
|
|
441
|
+
const version = document.version;
|
|
442
|
+
const revision = generation;
|
|
443
|
+
const controller = new AbortController();
|
|
444
|
+
const subscription = token.onCancellationRequested(() => controller.abort());
|
|
445
|
+
const results = [];
|
|
446
|
+
try {
|
|
447
|
+
for (const workspace of workspaces.values()) if (workspace.query) results.push(...await workspace.query(uri, request, controller.signal));
|
|
448
|
+
if (token.isCancellationRequested || revision !== generation || documents.get(uri)?.version !== version) return [];
|
|
449
|
+
const { fingerprint } = await import("@stillwind/native");
|
|
450
|
+
return results.filter((entry) => entry.result.revision === fingerprint(document.getText()));
|
|
451
|
+
} catch (error) {
|
|
452
|
+
connection.console.error(String(error));
|
|
453
|
+
return [];
|
|
454
|
+
} finally {
|
|
455
|
+
subscription.dispose();
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
registerEditorFeatures(connection, documents, query);
|
|
459
|
+
connection.onInitialize(async (params) => {
|
|
460
|
+
initializationOptions = params.initializationOptions;
|
|
461
|
+
registryDirectives = completionRegistrySetting(initializationOptions) ?? false;
|
|
462
|
+
snippets = params.capabilities.textDocument?.completion?.completionItem?.snippetSupport === true;
|
|
463
|
+
foldersSupported = params.capabilities.workspace?.workspaceFolders === true;
|
|
464
|
+
dynamicWatch = params.capabilities.workspace?.didChangeWatchedFiles?.dynamicRegistration === true;
|
|
465
|
+
roots = params.workspaceFolders?.map((folder) => folder.uri) ?? (params.rootUri ? [params.rootUri] : []);
|
|
466
|
+
await open();
|
|
467
|
+
const editor = [...workspaces.values()].some((workspace) => workspace.query != null);
|
|
468
|
+
return {
|
|
469
|
+
capabilities: {
|
|
470
|
+
textDocumentSync: TextDocumentSyncKind.Incremental,
|
|
471
|
+
codeActionProvider: { codeActionKinds: [CodeActionKind.QuickFix, ...editor ? editorCodeActionKinds : []] },
|
|
472
|
+
hoverProvider: editor,
|
|
473
|
+
definitionProvider: editor,
|
|
474
|
+
completionProvider: editor ? {
|
|
475
|
+
resolveProvider: true,
|
|
476
|
+
triggerCharacters: [
|
|
477
|
+
"@",
|
|
478
|
+
":",
|
|
479
|
+
"-",
|
|
480
|
+
"/",
|
|
481
|
+
"[",
|
|
482
|
+
"(",
|
|
483
|
+
" "
|
|
484
|
+
]
|
|
485
|
+
} : void 0,
|
|
486
|
+
colorProvider: editor,
|
|
487
|
+
documentLinkProvider: editor ? { resolveProvider: false } : void 0,
|
|
488
|
+
workspace: { workspaceFolders: {
|
|
489
|
+
supported: true,
|
|
490
|
+
changeNotifications: true
|
|
491
|
+
} }
|
|
492
|
+
},
|
|
493
|
+
serverInfo: { name: "Stillwind" }
|
|
494
|
+
};
|
|
495
|
+
});
|
|
496
|
+
connection.onInitialized(async () => {
|
|
497
|
+
if (foldersSupported) connection.workspace.onDidChangeWorkspaceFolders(({ added, removed }) => {
|
|
498
|
+
const deleted = new Set(removed.map((folder) => folder.uri));
|
|
499
|
+
roots = [...roots.filter((root) => !deleted.has(root)), ...added.map((folder) => folder.uri)];
|
|
500
|
+
control(open);
|
|
501
|
+
schedule();
|
|
502
|
+
});
|
|
503
|
+
if (dynamicWatch) await connection.client.register(DidChangeWatchedFilesNotification.type, { watchers: [{ globPattern: "**/*" }] });
|
|
504
|
+
schedule();
|
|
505
|
+
});
|
|
506
|
+
documents.onDidChangeContent(({ document }) => {
|
|
507
|
+
control(async () => {
|
|
508
|
+
if (documents.get(document.uri)?.version !== document.version) return;
|
|
509
|
+
for (const workspace of workspaces.values()) await workspace.update(document.uri, document.getText(), document.version);
|
|
510
|
+
});
|
|
511
|
+
schedule();
|
|
512
|
+
});
|
|
513
|
+
documents.onDidClose(({ document }) => {
|
|
514
|
+
control(async () => {
|
|
515
|
+
for (const workspace of workspaces.values()) await workspace.closeDocument(document.uri);
|
|
516
|
+
});
|
|
517
|
+
schedule();
|
|
518
|
+
});
|
|
519
|
+
/**
|
|
520
|
+
* Reopens the workspaces if any service cannot reuse its current buffers after a save or file change.
|
|
521
|
+
*
|
|
522
|
+
* @param uris - Document URIs from the save or watch notification.
|
|
523
|
+
* @returns Completion of the checks and any required workspace replacement.
|
|
524
|
+
* @throws If a service check or workspace replacement fails.
|
|
525
|
+
*/
|
|
526
|
+
const refresh = async (uris) => {
|
|
527
|
+
for (const workspace of workspaces.values()) if (!await workspace.refresh?.(uris)) {
|
|
528
|
+
await open();
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
documents.onDidSave(({ document }) => {
|
|
533
|
+
control(() => refresh([document.uri]));
|
|
534
|
+
schedule();
|
|
535
|
+
});
|
|
536
|
+
connection.onDidChangeWatchedFiles(({ changes }) => {
|
|
537
|
+
control(() => refresh(changes.map((change) => change.uri)));
|
|
538
|
+
schedule();
|
|
539
|
+
});
|
|
540
|
+
connection.onDidChangeConfiguration(({ settings }) => {
|
|
541
|
+
control(async () => {
|
|
542
|
+
registryDirectives = completionRegistrySetting(settings?.stillwind ?? settings) ?? registryDirectives;
|
|
543
|
+
await open();
|
|
544
|
+
});
|
|
545
|
+
schedule();
|
|
546
|
+
});
|
|
547
|
+
connection.onCodeAction(async (params, token) => {
|
|
548
|
+
const document = documents.get(params.textDocument.uri);
|
|
549
|
+
const result = document ? await sourceActions(document, params.context.only, token, query) : [];
|
|
550
|
+
if (params.context.only && !params.context.only.some((kind) => CodeActionKind.QuickFix === kind || CodeActionKind.QuickFix.startsWith(`${kind}.`))) return result;
|
|
551
|
+
if (token.isCancellationRequested) return result;
|
|
552
|
+
const { fingerprint } = await import("@stillwind/native");
|
|
553
|
+
if (token.isCancellationRequested) return result;
|
|
554
|
+
for (const entries of cache.values()) for (const entry of entries) for (const report of entry.result.reports) {
|
|
555
|
+
const primary = report.primary.location;
|
|
556
|
+
if (primary.uri !== params.textDocument.uri || primary.endLine < params.range.start.line || primary.startLine > params.range.end.line) continue;
|
|
557
|
+
if (document && (primary.endUtf16 < document.offsetAt(params.range.start) || primary.startUtf16 > document.offsetAt(params.range.end))) continue;
|
|
558
|
+
for (const action of report.actions) {
|
|
559
|
+
const changes = /* @__PURE__ */ new Map();
|
|
560
|
+
let valid = true;
|
|
561
|
+
for (const edit of action.edits) {
|
|
562
|
+
const document = documents.get(edit.location.uri);
|
|
563
|
+
if (!document || fingerprint(document.getText()) !== edit.location.revision) {
|
|
564
|
+
valid = false;
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
const change = changes.get(document.uri) ?? {
|
|
568
|
+
textDocument: {
|
|
569
|
+
uri: document.uri,
|
|
570
|
+
version: document.version
|
|
571
|
+
},
|
|
572
|
+
edits: []
|
|
573
|
+
};
|
|
574
|
+
change.edits.push({
|
|
575
|
+
range: range(edit.location),
|
|
576
|
+
newText: edit.replacement
|
|
577
|
+
});
|
|
578
|
+
changes.set(document.uri, change);
|
|
579
|
+
}
|
|
580
|
+
if (valid && changes.size) result.push({
|
|
581
|
+
title: action.title,
|
|
582
|
+
kind: CodeActionKind.QuickFix,
|
|
583
|
+
edit: { documentChanges: [...changes.values()] }
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return result.filter((action, index) => result.findIndex((candidate) => JSON.stringify(candidate) === JSON.stringify(action)) === index);
|
|
588
|
+
});
|
|
589
|
+
/**
|
|
590
|
+
* Stops publication and closes all services after the control queue settles.
|
|
591
|
+
*
|
|
592
|
+
* @returns A shared cleanup promise, including on repeated calls.
|
|
593
|
+
* @throws An AggregateError containing every service closure failure.
|
|
594
|
+
*/
|
|
595
|
+
const dispose = () => {
|
|
596
|
+
disposal ??= (async () => {
|
|
597
|
+
shutdown = true;
|
|
598
|
+
active?.abort();
|
|
599
|
+
generation++;
|
|
600
|
+
cache.clear();
|
|
601
|
+
if (timer) clearTimeout(timer);
|
|
602
|
+
await controls;
|
|
603
|
+
const closed = await Promise.allSettled([...workspaces.values()].map((workspace) => workspace.close()));
|
|
604
|
+
workspaces.clear();
|
|
605
|
+
const failed = closed.filter((result) => result.status === "rejected");
|
|
606
|
+
if (failed.length) throw new AggregateError(failed.map((result) => result.reason), "Failed to close language server analysis services");
|
|
607
|
+
})();
|
|
608
|
+
return disposal;
|
|
609
|
+
};
|
|
610
|
+
connection.onShutdown(dispose);
|
|
611
|
+
connection.onExit(() => {
|
|
612
|
+
options.onExit?.(shutdown);
|
|
613
|
+
});
|
|
614
|
+
documents.listen(connection);
|
|
615
|
+
return {
|
|
616
|
+
ready: () => controls,
|
|
617
|
+
reload: async () => {
|
|
618
|
+
control(open);
|
|
619
|
+
schedule();
|
|
620
|
+
await controls;
|
|
621
|
+
},
|
|
622
|
+
dispose
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Reads the editor-only completion field from initialization options or configuration settings.
|
|
627
|
+
*
|
|
628
|
+
* @param value - A protocol object that may contain `completion.registryDirectives`.
|
|
629
|
+
* @returns The boolean setting, or undefined when the field is absent or invalid.
|
|
630
|
+
*/
|
|
631
|
+
function completionRegistrySetting(value) {
|
|
632
|
+
if (!value || typeof value !== "object") return;
|
|
633
|
+
const completion = value.completion;
|
|
634
|
+
if (!completion || typeof completion !== "object") return;
|
|
635
|
+
const registry = completion.registryDirectives;
|
|
636
|
+
return typeof registry === "boolean" ? registry : void 0;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Copies a native diagnostic location into LSP positions.
|
|
640
|
+
*
|
|
641
|
+
* @param location - Original document positions with zero-based lines and UTF-16 columns.
|
|
642
|
+
* @returns The half-open range, or an empty range at document start when no location is supplied.
|
|
643
|
+
*/
|
|
644
|
+
function range(location) {
|
|
645
|
+
return {
|
|
646
|
+
start: {
|
|
647
|
+
line: location?.startLine ?? 0,
|
|
648
|
+
character: location?.startColumn ?? 0
|
|
649
|
+
},
|
|
650
|
+
end: {
|
|
651
|
+
line: location?.endLine ?? 0,
|
|
652
|
+
character: location?.endColumn ?? 0
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
export { createLanguageServer as t };
|
|
657
|
+
|
|
658
|
+
//# sourceMappingURL=server-p2n04Evx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-p2n04Evx.js","names":[],"sources":["../src/editor.ts","../src/server.ts"],"sourcesContent":["import type { EditorRequest, WorkspaceEditorResult } from \"@stillwind/analysis\";\nimport {\n CompletionItemKind,\n InsertTextFormat,\n MarkupKind,\n type CancellationToken,\n type CodeAction,\n type CompletionItem,\n type Connection,\n type TextDocuments,\n} from \"vscode-languageserver\";\nimport type { TextDocument } from \"vscode-languageserver-textdocument\";\n\nconst sortKind = \"source.sort.stillwind\";\nconst fixAllKind = \"source.fixAll.stillwind\";\n\n/** Source actions advertised in fix-all order followed by utility sorting. */\nexport const editorCodeActionKinds = [fixAllKind, sortKind];\n\n/**\n * Queries the current original buffer and discards results after a document change or cancellation.\n *\n * @param uri - URI of an open original document.\n * @param request - Editor operation with offsets in that document's UTF-16 text.\n * @param token - Cancellation for this request.\n * @returns Results whose source fingerprints match the current document.\n */\nexport type EditorQuery = (\n uri: string,\n request: EditorRequest,\n token: CancellationToken,\n) => Promise<WorkspaceEditorResult[]>;\n\n/**\n * Registers hover, definitions, completion, colors, plugin links, and source actions.\n *\n * @param connection - Caller-owned connection on which handlers are installed.\n * @param documents - Open original buffers used to convert UTF-16 offsets to LSP positions.\n * @param query - Query implementation that rejects obsolete results and honors cancellation.\n */\nexport function registerEditorFeatures(\n connection: Connection,\n documents: TextDocuments<TextDocument>,\n query: EditorQuery,\n): void {\n connection.onDefinition(async (params, token) => {\n const document = documents.get(params.textDocument.uri);\n if (!document) {\n return [];\n }\n const entries = await query(\n document.uri,\n {\n kind: \"definition\",\n offset: document.offsetAt(params.position),\n },\n token,\n );\n const definitions = entries.flatMap((entry) => entry.result.definitions ?? []);\n return definitions\n .filter(\n (definition, index) =>\n definitions.findIndex((other) => JSON.stringify(other) === JSON.stringify(definition)) ===\n index,\n )\n .map((definition) => ({\n uri: definition.uri,\n range: {\n start: {\n line: definition.startLine,\n character: definition.startColumn,\n },\n end: {\n line: definition.endLine,\n character: definition.endColumn,\n },\n },\n }));\n });\n connection.onDocumentLinks(async (params, token) => {\n const document = documents.get(params.textDocument.uri);\n if (!document) {\n return [];\n }\n const entries = await query(\n document.uri,\n {\n kind: \"links\",\n },\n token,\n );\n const links = entries.flatMap((entry) => entry.result.links ?? []);\n return links\n .filter(\n (link, index) =>\n link.target &&\n links.findIndex(\n (other) =>\n other.start === link.start && other.end === link.end && other.target === link.target,\n ) === index &&\n !links.some(\n (other) =>\n other.start === link.start && other.end === link.end && other.target !== link.target,\n ),\n )\n .map((link) => ({\n range: offsets(document, link),\n target: link.target,\n }));\n });\n connection.onHover(async (params, token) => {\n const document = documents.get(params.textDocument.uri);\n if (!document) {\n return null;\n }\n\n const entries = await query(\n document.uri,\n {\n kind: \"hover\",\n offset: document.offsetAt(params.position),\n },\n token,\n );\n const answers = entries.filter((entry) => entry.result.hover);\n if (!answers.length) {\n return null;\n }\n\n const seen = new Set<string>();\n const contents = answers\n .flatMap((entry) => {\n const hover = entry.result.hover!;\n const key = JSON.stringify(hover);\n if (seen.has(key)) {\n return [];\n }\n seen.add(key);\n return [\n `${answers.length > 1 ? `${entry.config} · project ${entry.project + 1}\\n\\n` : \"\"}${hoverMarkdown(hover)}`,\n ];\n })\n .join(\"\\n\\n\");\n return {\n contents: {\n kind: MarkupKind.Markdown,\n value: contents,\n },\n range: offsets(document, answers[0].result.hover!),\n };\n });\n\n connection.onCompletion(async (params, token) => {\n const document = documents.get(params.textDocument.uri);\n if (!document) {\n return [];\n }\n\n const version = document.version;\n const entries = await query(\n document.uri,\n {\n kind: \"completion\",\n offset: document.offsetAt(params.position),\n },\n token,\n );\n const items: CompletionItem[] = entries.flatMap((entry) =>\n (entry.result.completions ?? []).map((item) => ({\n label: item.label,\n detail: item.detail,\n sortText: item.sortText,\n insertTextFormat: item.snippet ? InsertTextFormat.Snippet : undefined,\n command: item.retrigger\n ? { title: \"Continue completion\", command: \"editor.action.triggerSuggest\" }\n : undefined,\n kind: item.keyword\n ? CompletionItemKind.Keyword\n : item.category === \"directory\"\n ? CompletionItemKind.Folder\n : item.category === \"file\"\n ? CompletionItemKind.File\n : item.category === \"module\" || item.variant || item.candidate.endsWith(\":\")\n ? CompletionItemKind.Module\n : item.marker\n ? CompletionItemKind.Class\n : CompletionItemKind.Value,\n textEdit: {\n range: offsets(document, item),\n newText: item.snippet ?? item.newText,\n },\n data: {\n uri: document.uri,\n version,\n revision: entry.result.revision,\n candidate: item.candidate,\n input: item.input,\n snapshot: item.snapshot,\n project: entry.project,\n config: entry.config,\n },\n })),\n );\n return items.filter(\n (item, index) =>\n items.findIndex(\n (other) =>\n other.label === item.label &&\n JSON.stringify(other.textEdit) === JSON.stringify(item.textEdit),\n ) === index,\n );\n });\n\n connection.onCompletionResolve(async (item, token) => {\n const detail = item.detail;\n delete item.documentation;\n delete item.detail;\n const data = item.data as\n | {\n /** Original document URI captured when completion was requested. */\n uri?: unknown;\n /** Document version that must still match the open buffer. */\n version?: unknown;\n /** Full completion candidate, including surrounding variants. */\n candidate?: unknown;\n /** Configuration identity used to select the same project result. */\n config?: unknown;\n /** Zero-based project index within the configuration. */\n project?: unknown;\n /** Source fingerprint that must match the resolved result. */\n revision?: unknown;\n /** Original UTF-16 offset that identifies the completion's utility input. */\n input?: unknown;\n /** Graph and configuration fingerprint required by the resolve request. */\n snapshot?: unknown;\n }\n | undefined;\n if (\n !data ||\n typeof data.uri !== \"string\" ||\n typeof data.candidate !== \"string\" ||\n typeof data.input !== \"number\" ||\n typeof data.snapshot !== \"string\" ||\n documents.get(data.uri)?.version !== data.version\n ) {\n return item;\n }\n\n const entries = await query(\n data.uri,\n {\n kind: \"resolve\",\n candidate: data.candidate,\n input: data.input,\n snapshot: data.snapshot,\n },\n token,\n );\n const answer = entries.find(\n (entry) =>\n entry.project === data.project &&\n entry.config === data.config &&\n entry.result.revision === data.revision,\n )?.result.hover;\n if (answer) {\n item.detail = answer.detail ?? detail;\n item.documentation = {\n kind: MarkupKind.Markdown,\n value: hoverMarkdown(answer),\n };\n }\n return item;\n });\n\n connection.onDocumentColor(async (params, token) => {\n const document = documents.get(params.textDocument.uri);\n if (!document) {\n return [];\n }\n\n const entries = await query(\n document.uri,\n {\n kind: \"colors\",\n },\n token,\n );\n const colors = entries.flatMap((entry) => entry.result.colors ?? []);\n return colors\n .filter(\n (color, index) =>\n colors.findIndex((other) => JSON.stringify(other) === JSON.stringify(color)) === index &&\n !colors.some(\n (other) =>\n other.start === color.start &&\n other.end === color.end &&\n JSON.stringify(other) !== JSON.stringify(color),\n ),\n )\n .map((color) => ({\n range: offsets(document, color),\n color: {\n red: color.red,\n green: color.green,\n blue: color.blue,\n alpha: color.alpha,\n },\n }));\n });\n\n connection.onColorPresentation(async (params, token) => {\n const document = documents.get(params.textDocument.uri);\n if (!document) {\n return [];\n }\n\n const entries = await query(\n document.uri,\n {\n kind: \"colorPresentation\",\n start: document.offsetAt(params.range.start),\n end: document.offsetAt(params.range.end),\n color: params.color,\n },\n token,\n );\n return entries\n .flatMap((entry) =>\n (entry.result.edits ?? []).map((edit) => ({\n label: edit.newText,\n textEdit: {\n range: offsets(document, edit),\n newText: edit.newText,\n },\n })),\n )\n .filter(\n (item, index, items) =>\n items.findIndex((other) => JSON.stringify(item) === JSON.stringify(other)) === index,\n );\n });\n}\n\n/**\n * Formats CSS previews and dialect documentation, and explains authored runtime key expressions.\n * Expression line breaks become spaces, and code-span delimiters exceed every authored\n * backtick run so expressions remain literal Markdown. The supplied hover remains unchanged.\n *\n * @param hover - CSS preview and optional authored expressions for runtime view-transition names.\n * @returns Markdown with CSS first and expression notes in their supplied order.\n */\nfunction hoverMarkdown(hover: {\n /** Formatted generated CSS included verbatim inside the CSS fence. */\n css: string;\n /** Markdown describing authored CSS syntax or theme semantics. */\n documentation?: string;\n /** Authored expressions in the order in which their notes should appear. */\n runtimeNames?: string[];\n}): string {\n const notes = (hover.runtimeNames ?? []).map((expression) => {\n const text = expression.replace(/\\r\\n?|\\n/g, \" \");\n const ticks = \"`\".repeat(\n Math.max(0, ...[...text.matchAll(/`+/g)].map((match) => match[0].length)) + 1,\n );\n return `view-transition-name is computed at runtime from ${ticks} ${text} ${ticks}.`;\n });\n return [hover.css ? `\\`\\`\\`css\\n${hover.css}\\n\\`\\`\\`` : undefined, hover.documentation, ...notes]\n .filter(Boolean)\n .join(\"\\n\\n\");\n}\n\n/**\n * Builds versioned source actions for each project and removes actions with identical edits.\n * Each action contains one project's edits, so differing project results remain separate.\n *\n * @param document - Open original buffer that the query reads and the returned edits target.\n * @param only - Requested source kinds or their prefixes. Omission or an empty list produces no actions.\n * @param token - Cancellation forwarded to each query.\n * @param query - Query implementation that discards changed buffers and cancelled requests.\n * @returns Fix-all actions followed by sort actions, preserving project order within each kind.\n * @throws If a query rejects.\n */\nexport async function sourceActions(\n document: TextDocument,\n only: readonly string[] | undefined,\n token: CancellationToken,\n query: EditorQuery,\n): Promise<CodeAction[]> {\n const actions: CodeAction[] = [];\n for (const [kind, operation, title] of [\n [fixAllKind, \"fixes\", \"Fix all Stillwind lint findings\"],\n [sortKind, \"sort\", \"Sort Stillwind utilities\"],\n ] as const) {\n if (!only?.some((requested) => kind === requested || kind.startsWith(`${requested}.`))) {\n continue;\n }\n const entries = await query(\n document.uri,\n {\n kind: operation,\n },\n token,\n );\n for (const entry of entries) {\n if (!entry.result.edits?.length) {\n continue;\n }\n const edit = {\n documentChanges: [\n {\n textDocument: {\n uri: document.uri,\n version: document.version,\n },\n edits: entry.result.edits.map((edit) => ({\n range: offsets(document, edit),\n newText: edit.newText,\n })),\n },\n ],\n };\n if (\n actions.some(\n (action) => action.kind === kind && JSON.stringify(action.edit) === JSON.stringify(edit),\n )\n ) {\n continue;\n }\n actions.push({\n title: `${title}${entries.length > 1 ? ` (${entry.config}, project ${entry.project + 1})` : \"\"}`,\n kind,\n edit,\n });\n }\n }\n return actions;\n}\n\n/**\n * Converts original UTF-16 offsets to positions using the open document's line table.\n *\n * @param document - Document containing the text from which the offsets were measured.\n * @param range - Half-open UTF-16 range. TextDocument clamps offsets outside the document.\n * @returns LSP positions with zero-based lines and UTF-16 character offsets.\n */\nfunction offsets(\n document: TextDocument,\n range: {\n /** Inclusive UTF-16 offset in the original document. */\n start: number;\n /** Exclusive UTF-16 offset in the original document. */\n end: number;\n },\n) {\n return {\n start: document.positionAt(range.start),\n end: document.positionAt(range.end),\n };\n}\n","import type {\n AnalysisWorkspaceService,\n OpenWorkspaces,\n WorkspaceEditorResult,\n WorkspaceResult,\n} from \"@stillwind/analysis\";\nimport {\n CodeActionKind,\n DiagnosticSeverity,\n DidChangeWatchedFilesNotification,\n TextDocuments,\n TextDocumentSyncKind,\n type CancellationToken,\n type CodeAction,\n type Connection,\n type Diagnostic,\n type InitializeParams,\n type TextDocumentEdit,\n} from \"vscode-languageserver\";\nimport { TextDocument } from \"vscode-languageserver-textdocument\";\n\nimport {\n editorCodeActionKinds,\n registerEditorFeatures,\n sourceActions,\n type EditorQuery,\n} from \"./editor.ts\";\n\n/** Supplies analysis services and delegates transport exit to the embedding application. */\nexport interface LanguageServerOptions {\n /**\n * Opens services at initialization and after saves, watched file changes, configuration changes,\n * or workspace folder changes. Previous services are closed first. Open buffers are replayed.\n */\n openWorkspaces: OpenWorkspaces;\n /**\n * Handles the LSP exit notification using the embedding's transport or process policy.\n *\n * @param shutdown - Whether shutdown or explicit disposal was requested before exit.\n */\n onExit?(shutdown: boolean): void;\n}\n\n/**\n * Registers synchronization, diagnostics, fixes, hover, completion, colors, and sorting.\n * Analysis uses captured buffers and suppresses obsolete results. Quick fixes require every edited\n * document to be open and to match the report's source fingerprint.\n *\n * @param connection - Caller-owned connection. Call listen after registration and dispose the\n * transport when finished. Diagnostic locations must use original documents and UTF-16 positions.\n * @param options - Workspace factory and optional exit handler. This server owns the opened services.\n * @returns Cleanup for the analysis services. It does not dispose the connection or its transport.\n */\nexport function createLanguageServer(\n connection: Connection,\n options: LanguageServerOptions,\n): {\n /**\n * Waits for document and workspace changes already queued by the server.\n *\n * @returns The current control queue's completion promise. Queued failures are logged.\n */\n ready(): Promise<void>;\n /**\n * Reopens workspace configuration and files, replays current buffers, and schedules analysis.\n *\n * @returns Completion of the queued reload. Reload failures are logged, and analysis runs separately.\n */\n reload(): Promise<void>;\n /**\n * Stops scheduling analysis, cancels publication, and closes services after queued control work.\n *\n * @returns The same cleanup promise on repeated calls.\n * @throws An AggregateError if any service fails to close.\n */\n dispose(): Promise<void>;\n} {\n const documents = new TextDocuments(TextDocument);\n const workspaces = new Map<string, AnalysisWorkspaceService>();\n const errors = new Map<string, string>();\n const cache = new Map<string, WorkspaceResult[]>();\n const published = new Set<string>();\n\n let roots: string[] = [];\n let initializationOptions: unknown;\n let registryDirectives = false;\n let snippets = false;\n let generation = 0;\n let controls = Promise.resolve();\n let timer: ReturnType<typeof setTimeout> | undefined;\n let shutdown = false;\n let foldersSupported = false;\n let dynamicWatch = false;\n let active: AbortController | undefined;\n let disposal: Promise<void> | undefined;\n\n /**\n * Invalidates current results and serializes a workspace or document mutation.\n * Callback failures are logged and absorbed so subsequent mutations can run.\n *\n * @param action - Mutation to execute after previous control work. Shutdown skips registration.\n */\n const control = (action: () => Promise<void>) => {\n if (shutdown) {\n return;\n }\n active?.abort();\n generation++;\n cache.clear();\n controls = controls.then(action).catch((error: unknown) => {\n connection.console.error(String(error));\n });\n };\n\n /**\n * Closes existing services, opens the current roots, and replays every open buffer.\n *\n * @returns Completion of service replacement and buffer replay.\n * @throws If service closure, the workspace factory, or buffer replay fails.\n */\n const open = async () => {\n await Promise.all([...workspaces.values()].map((workspace) => workspace.close()));\n workspaces.clear();\n errors.clear();\n const opened = await options.openWorkspaces({\n workspaceFolders: roots,\n initializationOptions,\n });\n for (const [id, error] of opened.errors ?? []) {\n errors.set(id, error);\n }\n for (const [id, workspace] of opened.workspaces) {\n workspaces.set(id, workspace);\n for (const document of documents.all()) {\n await workspace.update(document.uri, document.getText(), document.version);\n }\n }\n };\n\n /**\n * Sends deduplicated cached diagnostics and workspace errors, then records their document URIs.\n * Empty notifications clear diagnostics for previously published or currently open documents.\n */\n const publish = () => {\n const grouped = new Map<string, Diagnostic[]>();\n const seen = new Set<string>();\n /**\n * Appends a diagnostic only once for its document and complete serialized value.\n *\n * @param uri - Original document URI used to group publication.\n * @param diagnostic - Diagnostic with original LSP positions.\n */\n const add = (uri: string, diagnostic: Diagnostic) => {\n const key = JSON.stringify([uri, diagnostic]);\n if (!seen.has(key)) {\n seen.add(key);\n const list = grouped.get(uri) ?? [];\n list.push(diagnostic);\n grouped.set(uri, list);\n }\n };\n for (const [uri, results] of cache) {\n for (const entry of results) {\n const source = `stillwind:${entry.config}:${entry.project + 1}`;\n for (const report of entry.result.reports) {\n const location = report.primary.location;\n add(location.uri, {\n range: range(location),\n severity:\n report.severity === \"error\" ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning,\n source,\n code: report.code,\n message: [report.message, ...report.notes].join(\"\\n\"),\n relatedInformation: report.related.map((label) => ({\n location: {\n uri: label.location.uri,\n range: range(label.location),\n },\n message: label.message ?? report.message,\n })),\n });\n }\n if (entry.result.status === \"incomplete\") {\n const missing =\n entry.result.dependencies\n ?.filter(\n (dependency) =>\n dependency.status === \"unresolved\" || dependency.status === \"unsupported\",\n )\n .map(\n (dependency) =>\n `${dependency.status}: ${dependency.specifier} from ${dependency.importer}`,\n ) ?? [];\n add(uri, {\n range: range(),\n severity: entry.result.error\n ? DiagnosticSeverity.Error\n : DiagnosticSeverity.Information,\n source,\n code: entry.result.error ? \"SW_HOST\" : \"SW_UNVERIFIED\",\n message: [\n entry.result.error ?? \"Stillwind analysis is incomplete\",\n ...missing,\n ...(entry.result.unverified ?? []).map((item) => `${item.moduleId}: ${item.reason}`),\n ].join(\"\\n\"),\n });\n }\n }\n }\n for (const document of documents.all()) {\n for (const [file, error] of errors) {\n add(document.uri, {\n range: range(),\n severity: DiagnosticSeverity.Error,\n source: \"stillwind\",\n code: \"SW_HOST\",\n message: `${file}: ${error}`,\n });\n }\n }\n for (const uri of new Set([\n ...published,\n ...grouped.keys(),\n ...documents.all().map((document) => document.uri),\n ])) {\n void connection.sendDiagnostics({\n uri,\n version: documents.get(uri)?.version,\n diagnostics: grouped.get(uri) ?? [],\n });\n }\n published.clear();\n for (const uri of grouped.keys()) {\n published.add(uri);\n }\n };\n\n /**\n * Analyzes open buffers after queued mutations and publishes only a current, non-stale batch.\n * Service failures become workspace errors. An obsolete or cancelled batch leaves the cache unchanged.\n *\n * @param revision - Control generation captured when analysis was scheduled.\n * @returns Completion of the analysis pass or its early discard.\n */\n const analyze = async (revision: number) => {\n await controls;\n if (shutdown || revision !== generation) {\n return;\n }\n const cancellation = new AbortController();\n active = cancellation;\n const next = new Map<string, WorkspaceResult[]>();\n for (const [file, workspace] of workspaces) {\n try {\n await workspace.prepare?.(\n documents.all().map((document) => document.uri),\n cancellation.signal,\n );\n } catch (error) {\n errors.set(file, String(error));\n }\n if (revision !== generation || shutdown) {\n return;\n }\n }\n for (const document of documents.all()) {\n const results: WorkspaceResult[] = [];\n for (const [file, workspace] of workspaces) {\n try {\n results.push(...(await workspace.analyze(document.uri, cancellation.signal)));\n errors.delete(file);\n } catch (error) {\n errors.set(file, String(error));\n }\n }\n if (revision !== generation || shutdown) {\n return;\n }\n if (\n results.some(({ result }) => result.status === \"stale\" || result.status === \"cancelled\")\n ) {\n return;\n }\n next.set(document.uri, results);\n }\n if (revision === generation) {\n cache.clear();\n for (const [uri, result] of next) {\n cache.set(uri, result);\n }\n publish();\n }\n };\n\n /** Replaces the pending 40 ms timer with an analysis pass for the current control generation. */\n const schedule = () => {\n if (timer) {\n clearTimeout(timer);\n }\n const revision = generation;\n timer = setTimeout(() => {\n void analyze(revision).catch((error: unknown) => {\n connection.console.error(String(error));\n });\n }, 40);\n };\n\n /**\n * Queries services after queued mutations and checks document versions and source fingerprints.\n * Query failures are logged, and the cancellation subscription is released after the request.\n *\n * @param uri - URI of the open original document.\n * @param request - Editor operation expressed in that document's UTF-16 coordinates.\n * @param token - LSP cancellation forwarded through an AbortSignal.\n * @returns Current project results, or an empty list after changes, cancellation, or failure.\n */\n const query: EditorQuery = async (uri, request, token: CancellationToken) => {\n await controls;\n if (request.kind === \"completion\" || request.kind === \"resolve\") {\n request = {\n ...request,\n registryDirectives,\n snippets,\n };\n }\n const document = documents.get(uri);\n if (!document || shutdown || token.isCancellationRequested) {\n return [];\n }\n const version = document.version;\n const revision = generation;\n const controller = new AbortController();\n const subscription = token.onCancellationRequested(() => controller.abort());\n const results: WorkspaceEditorResult[] = [];\n try {\n for (const workspace of workspaces.values()) {\n if (workspace.query) {\n results.push(...(await workspace.query(uri, request, controller.signal)));\n }\n }\n if (\n token.isCancellationRequested ||\n revision !== generation ||\n documents.get(uri)?.version !== version\n ) {\n return [];\n }\n const { fingerprint } = await import(\"@stillwind/native\");\n return results.filter((entry) => entry.result.revision === fingerprint(document.getText()));\n } catch (error) {\n connection.console.error(String(error));\n return [];\n } finally {\n subscription.dispose();\n }\n };\n registerEditorFeatures(connection, documents, query);\n\n connection.onInitialize(async (params: InitializeParams) => {\n initializationOptions = params.initializationOptions;\n registryDirectives = completionRegistrySetting(initializationOptions) ?? false;\n snippets =\n params.capabilities.textDocument?.completion?.completionItem?.snippetSupport === true;\n foldersSupported = params.capabilities.workspace?.workspaceFolders === true;\n dynamicWatch =\n params.capabilities.workspace?.didChangeWatchedFiles?.dynamicRegistration === true;\n roots =\n params.workspaceFolders?.map((folder) => folder.uri) ??\n (params.rootUri ? [params.rootUri] : []);\n await open();\n const editor = [...workspaces.values()].some((workspace) => workspace.query != null);\n return {\n capabilities: {\n textDocumentSync: TextDocumentSyncKind.Incremental,\n codeActionProvider: {\n codeActionKinds: [CodeActionKind.QuickFix, ...(editor ? editorCodeActionKinds : [])],\n },\n hoverProvider: editor,\n definitionProvider: editor,\n completionProvider: editor\n ? {\n resolveProvider: true,\n triggerCharacters: [\"@\", \":\", \"-\", \"/\", \"[\", \"(\", \" \"],\n }\n : undefined,\n colorProvider: editor,\n documentLinkProvider: editor\n ? {\n resolveProvider: false,\n }\n : undefined,\n workspace: {\n workspaceFolders: {\n supported: true,\n changeNotifications: true,\n },\n },\n },\n serverInfo: {\n name: \"Stillwind\",\n },\n };\n });\n connection.onInitialized(async () => {\n if (foldersSupported) {\n connection.workspace.onDidChangeWorkspaceFolders(({ added, removed }) => {\n const deleted = new Set(removed.map((folder) => folder.uri));\n roots = [\n ...roots.filter((root) => !deleted.has(root)),\n ...added.map((folder) => folder.uri),\n ];\n control(open);\n schedule();\n });\n }\n if (dynamicWatch) {\n await connection.client.register(DidChangeWatchedFilesNotification.type, {\n watchers: [\n {\n globPattern: \"**/*\",\n },\n ],\n });\n }\n schedule();\n });\n documents.onDidChangeContent(({ document }) => {\n control(async () => {\n if (documents.get(document.uri)?.version !== document.version) {\n return;\n }\n for (const workspace of workspaces.values()) {\n await workspace.update(document.uri, document.getText(), document.version);\n }\n });\n schedule();\n });\n documents.onDidClose(({ document }) => {\n control(async () => {\n for (const workspace of workspaces.values()) {\n await workspace.closeDocument(document.uri);\n }\n });\n schedule();\n });\n /**\n * Reopens the workspaces if any service cannot reuse its current buffers after a save or file change.\n *\n * @param uris - Document URIs from the save or watch notification.\n * @returns Completion of the checks and any required workspace replacement.\n * @throws If a service check or workspace replacement fails.\n */\n const refresh = async (uris: readonly string[]) => {\n for (const workspace of workspaces.values()) {\n if (!(await workspace.refresh?.(uris))) {\n await open();\n break;\n }\n }\n };\n documents.onDidSave(({ document }) => {\n control(() => refresh([document.uri]));\n schedule();\n });\n connection.onDidChangeWatchedFiles(({ changes }) => {\n control(() => refresh(changes.map((change) => change.uri)));\n schedule();\n });\n connection.onDidChangeConfiguration(({ settings }) => {\n control(async () => {\n registryDirectives =\n completionRegistrySetting(settings?.stillwind ?? settings) ?? registryDirectives;\n await open();\n });\n schedule();\n });\n connection.onCodeAction(async (params, token) => {\n const document = documents.get(params.textDocument.uri);\n const result: CodeAction[] = document\n ? await sourceActions(document, params.context.only, token, query)\n : [];\n if (\n params.context.only &&\n !params.context.only.some(\n (kind) =>\n CodeActionKind.QuickFix === kind || CodeActionKind.QuickFix.startsWith(`${kind}.`),\n )\n ) {\n return result;\n }\n if (token.isCancellationRequested) {\n return result;\n }\n const { fingerprint } = await import(\"@stillwind/native\");\n if (token.isCancellationRequested) {\n return result;\n }\n for (const entries of cache.values()) {\n for (const entry of entries) {\n for (const report of entry.result.reports) {\n const primary = report.primary.location;\n if (\n primary.uri !== params.textDocument.uri ||\n primary.endLine < params.range.start.line ||\n primary.startLine > params.range.end.line\n ) {\n continue;\n }\n if (\n document &&\n (primary.endUtf16 < document.offsetAt(params.range.start) ||\n primary.startUtf16 > document.offsetAt(params.range.end))\n ) {\n continue;\n }\n for (const action of report.actions) {\n const changes = new Map<string, TextDocumentEdit>();\n let valid = true;\n for (const edit of action.edits) {\n const document = documents.get(edit.location.uri);\n if (!document || fingerprint(document.getText()) !== edit.location.revision) {\n valid = false;\n break;\n }\n const change = changes.get(document.uri) ?? {\n textDocument: {\n uri: document.uri,\n version: document.version,\n },\n edits: [],\n };\n change.edits.push({\n range: range(edit.location),\n newText: edit.replacement,\n });\n changes.set(document.uri, change);\n }\n if (valid && changes.size) {\n result.push({\n title: action.title,\n kind: CodeActionKind.QuickFix,\n edit: {\n documentChanges: [...changes.values()],\n },\n });\n }\n }\n }\n }\n }\n return result.filter(\n (action, index) =>\n result.findIndex((candidate) => JSON.stringify(candidate) === JSON.stringify(action)) ===\n index,\n );\n });\n /**\n * Stops publication and closes all services after the control queue settles.\n *\n * @returns A shared cleanup promise, including on repeated calls.\n * @throws An AggregateError containing every service closure failure.\n */\n const dispose = (): Promise<void> => {\n disposal ??= (async () => {\n shutdown = true;\n active?.abort();\n generation++;\n cache.clear();\n if (timer) {\n clearTimeout(timer);\n }\n await controls;\n const closed = await Promise.allSettled(\n [...workspaces.values()].map((workspace) => workspace.close()),\n );\n workspaces.clear();\n const failed = closed.filter((result) => result.status === \"rejected\");\n if (failed.length) {\n throw new AggregateError(\n failed.map((result) => result.reason),\n \"Failed to close language server analysis services\",\n );\n }\n })();\n return disposal;\n };\n connection.onShutdown(dispose);\n connection.onExit(() => {\n options.onExit?.(shutdown);\n });\n documents.listen(connection);\n return {\n ready: () => controls,\n reload: async () => {\n control(open);\n schedule();\n await controls;\n },\n dispose,\n };\n}\n\n/**\n * Reads the editor-only completion field from initialization options or configuration settings.\n *\n * @param value - A protocol object that may contain `completion.registryDirectives`.\n * @returns The boolean setting, or undefined when the field is absent or invalid.\n */\nfunction completionRegistrySetting(value: unknown): boolean | undefined {\n if (!value || typeof value !== \"object\") {\n return undefined;\n }\n const completion = (value as Record<string, unknown>).completion;\n if (!completion || typeof completion !== \"object\") {\n return undefined;\n }\n const registry = (completion as Record<string, unknown>).registryDirectives;\n return typeof registry === \"boolean\" ? registry : undefined;\n}\n\n/**\n * Copies a native diagnostic location into LSP positions.\n *\n * @param location - Original document positions with zero-based lines and UTF-16 columns.\n * @returns The half-open range, or an empty range at document start when no location is supplied.\n */\nfunction range(location?: {\n /** Zero-based line containing the inclusive start. */\n startLine: number;\n /** UTF-16 column of the inclusive start. */\n startColumn: number;\n /** Zero-based line containing the exclusive end. */\n endLine: number;\n /** UTF-16 column of the exclusive end. */\n endColumn: number;\n}) {\n return {\n start: {\n line: location?.startLine ?? 0,\n character: location?.startColumn ?? 0,\n },\n end: {\n line: location?.endLine ?? 0,\n character: location?.endColumn ?? 0,\n },\n };\n}\n"],"mappings":";;;AAaA,MAAM,WAAW;AACjB,MAAM,aAAa;;AAGnB,MAAa,wBAAwB,CAAC,YAAY,QAAQ;;;;;;;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,MAAM,GACpC,mDACF;EAEJ,EAAA,CAAG;EACH,OAAO;CACT;CACA,WAAW,WAAW,OAAO;CAC7B,WAAW,aAAa;EACtB,QAAQ,SAAS,QAAQ;CAC3B,CAAC;CACD,UAAU,OAAO,UAAU;CAC3B,OAAO;EACL,aAAa;EACb,QAAQ,YAAY;GAClB,QAAQ,IAAI;GACZ,SAAS;GACT,MAAM;EACR;EACA;CACF;AACF;;;;;;;AAQA,SAAS,0BAA0B,OAAqC;CACtE,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B;CAEF,MAAM,aAAc,MAAkC;CACtD,IAAI,CAAC,cAAc,OAAO,eAAe,UACvC;CAEF,MAAM,WAAY,WAAuC;CACzD,OAAO,OAAO,aAAa,YAAY,WAAW,KAAA;AACpD;;;;;;;AAQA,SAAS,MAAM,UASZ;CACD,OAAO;EACL,OAAO;GACL,MAAM,UAAU,aAAa;GAC7B,WAAW,UAAU,eAAe;EACtC;EACA,KAAK;GACH,MAAM,UAAU,WAAW;GAC3B,WAAW,UAAU,aAAa;EACpC;CACF;AACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Connection } from "vscode-languageserver";
|
|
2
|
+
import { OpenWorkspaces } from "@stillwind/analysis";
|
|
3
|
+
/** Supplies analysis services and delegates transport exit to the embedding application. */
|
|
4
|
+
interface LanguageServerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Opens services at initialization and after saves, watched file changes, configuration changes,
|
|
7
|
+
* or workspace folder changes. Previous services are closed first. Open buffers are replayed.
|
|
8
|
+
*/
|
|
9
|
+
openWorkspaces: OpenWorkspaces;
|
|
10
|
+
/**
|
|
11
|
+
* Handles the LSP exit notification using the embedding's transport or process policy.
|
|
12
|
+
*
|
|
13
|
+
* @param shutdown - Whether shutdown or explicit disposal was requested before exit.
|
|
14
|
+
*/
|
|
15
|
+
onExit?(shutdown: boolean): void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Registers synchronization, diagnostics, fixes, hover, completion, colors, and sorting.
|
|
19
|
+
* Analysis uses captured buffers and suppresses obsolete results. Quick fixes require every edited
|
|
20
|
+
* document to be open and to match the report's source fingerprint.
|
|
21
|
+
*
|
|
22
|
+
* @param connection - Caller-owned connection. Call listen after registration and dispose the
|
|
23
|
+
* transport when finished. Diagnostic locations must use original documents and UTF-16 positions.
|
|
24
|
+
* @param options - Workspace factory and optional exit handler. This server owns the opened services.
|
|
25
|
+
* @returns Cleanup for the analysis services. It does not dispose the connection or its transport.
|
|
26
|
+
*/
|
|
27
|
+
declare function createLanguageServer(connection: Connection, options: LanguageServerOptions): {
|
|
28
|
+
/**
|
|
29
|
+
* Waits for document and workspace changes already queued by the server.
|
|
30
|
+
*
|
|
31
|
+
* @returns The current control queue's completion promise. Queued failures are logged.
|
|
32
|
+
*/
|
|
33
|
+
ready(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Reopens workspace configuration and files, replays current buffers, and schedules analysis.
|
|
36
|
+
*
|
|
37
|
+
* @returns Completion of the queued reload. Reload failures are logged, and analysis runs separately.
|
|
38
|
+
*/
|
|
39
|
+
reload(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Stops scheduling analysis, cancels publication, and closes services after queued control work.
|
|
42
|
+
*
|
|
43
|
+
* @returns The same cleanup promise on repeated calls.
|
|
44
|
+
* @throws An AggregateError if any service fails to close.
|
|
45
|
+
*/
|
|
46
|
+
dispose(): Promise<void>;
|
|
47
|
+
};
|
|
48
|
+
export { createLanguageServer as n, LanguageServerOptions as t };
|
|
49
|
+
//# sourceMappingURL=server-pVyUFO88.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stillwind/language-server",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-rc.0",
|
|
4
|
+
"description": "Stillwind language server for Node and browser transports",
|
|
5
|
+
"homepage": "https://stillwind.dev/",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/SegaraRai/stillwind/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/SegaraRai/stillwind.git",
|
|
13
|
+
"directory": "packages/language-server"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./browser": {
|
|
25
|
+
"types": "./dist/browser.d.ts",
|
|
26
|
+
"default": "./dist/browser.js"
|
|
27
|
+
},
|
|
28
|
+
"./node": {
|
|
29
|
+
"types": "./dist/node.d.ts",
|
|
30
|
+
"default": "./dist/node.js"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@stillwind/analysis": "0.1.0-rc.0",
|
|
39
|
+
"@stillwind/native": "0.1.0-rc.0",
|
|
40
|
+
"vscode-languageserver": "^11.0.0",
|
|
41
|
+
"vscode-languageserver-textdocument": "^1.0.16"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@stillwind-internal/tools-workspace": "0.0.0",
|
|
45
|
+
"@types/node": "^26.6.5",
|
|
46
|
+
"rolldown": "^1.2.15",
|
|
47
|
+
"stillwind": "0.1.0-rc.0",
|
|
48
|
+
"typescript": "^6.0.3",
|
|
49
|
+
"vite-plus": "1.4.0"
|
|
50
|
+
}
|
|
6
51
|
}
|