@gi-tcg/gts-language-server 0.3.1 → 0.3.2

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.
@@ -1,320 +0,0 @@
1
- // packages/language-server/src/browser.ts
2
- import {
3
- createConnection,
4
- createServer,
5
- createTypeScriptProject,
6
- loadTsdkByUrl
7
- } from "@volar/language-server/browser.js";
8
- import { createGtsLanguagePlugin } from "@gi-tcg/gts-language-plugin";
9
- import path from "path-browserify-esm";
10
-
11
- // packages/language-server/src/diagnostics.ts
12
- import {
13
- DiagnosticSeverity
14
- } from "@volar/language-server";
15
-
16
- // packages/language-server/src/utils.ts
17
- import { URI } from "vscode-uri";
18
- import { GtsVirtualCode } from "@gi-tcg/gts-language-plugin";
19
- function getVirtualCode(document, context) {
20
- const uri = URI.parse(document.uri);
21
- const decoded = context.decodeEmbeddedDocumentUri(uri);
22
- const [sourceUri, virtualCodeId] = decoded;
23
- const sourceScript = context.language.scripts.get(sourceUri);
24
- const virtualCode = sourceScript?.generated?.embeddedCodes.get(virtualCodeId);
25
- if (!virtualCode) {
26
- return [null, sourceUri];
27
- }
28
- if (!(virtualCode instanceof GtsVirtualCode)) {
29
- return [null, sourceUri];
30
- }
31
- return [virtualCode, sourceUri];
32
- }
33
-
34
- // packages/language-server/src/diagnostics.ts
35
- var createDiagnosticsPlugin = () => {
36
- return {
37
- name: "gts-diagnostics",
38
- capabilities: {
39
- diagnosticProvider: {
40
- interFileDependencies: false,
41
- workspaceDiagnostics: false
42
- }
43
- },
44
- create: (context) => {
45
- return {
46
- provideDiagnostics: (document) => {
47
- try {
48
- const [virtualCode] = getVirtualCode(document, context);
49
- if (!virtualCode) {
50
- return;
51
- }
52
- return virtualCode.errors.map((err) => {
53
- const loc = err.position ?? {
54
- start: { line: 1, column: 0 },
55
- end: { line: 1, column: 1 }
56
- };
57
- const range = {
58
- start: {
59
- line: loc.start.line - 1,
60
- character: loc.start.column
61
- },
62
- end: { line: loc.end.line - 1, character: loc.end.column }
63
- };
64
- return {
65
- severity: DiagnosticSeverity.Error,
66
- range,
67
- message: err.message,
68
- source: "gts-transpiler",
69
- code: "gts-transpiler-error"
70
- };
71
- });
72
- } catch (e) {
73
- console.error(e);
74
- return;
75
- }
76
- }
77
- };
78
- }
79
- };
80
- };
81
-
82
- // packages/language-server/src/typescript.ts
83
- import { create } from "volar-service-typescript";
84
- function createTypeScriptServices(ts) {
85
- const services = create(ts);
86
- const semanticService = services.find((service) => service.name === "typescript-semantic");
87
- if (semanticService?.capabilities.signatureHelpProvider?.triggerCharacters) {
88
- semanticService.capabilities.signatureHelpProvider.triggerCharacters.push(" ");
89
- }
90
- return services;
91
- }
92
-
93
- // packages/language-server/src/completion.ts
94
- var createCompletionPlugin = () => {
95
- return {
96
- name: "gts-completion",
97
- capabilities: {
98
- completionProvider: {
99
- triggerCharacters: [":"]
100
- }
101
- },
102
- create: (context) => {
103
- let originalProvideCompletionItems;
104
- for (const [plugin, instance] of context.plugins) {
105
- if (plugin.name === "typescript-semantic") {
106
- originalProvideCompletionItems = instance.provideCompletionItems;
107
- }
108
- }
109
- if (!originalProvideCompletionItems) {
110
- console.warn(`TS's original provideCompletionItems not found`);
111
- return {};
112
- }
113
- return {
114
- provideCompletionItems: async (document, position, context2, token) => {
115
- if (context2.triggerCharacter === ":") {
116
- context2.triggerCharacter = ".";
117
- const response = await originalProvideCompletionItems(document, position, context2, token);
118
- return response;
119
- }
120
- return null;
121
- }
122
- };
123
- }
124
- };
125
- };
126
-
127
- // packages/language-server/src/browser.ts
128
- import { fs as memfs } from "@zenfs/core";
129
-
130
- // packages/language-server/src/zen_fs_provider.ts
131
- function zenFsProvider(fs) {
132
- return {
133
- stat(uri) {
134
- try {
135
- const stats = fs.statSync(uri.path);
136
- console.log("stat", uri.path, stats);
137
- return {
138
- type: stats.isFile() ? 1 : stats.isDirectory() ? 2 : stats.isSymbolicLink() ? 64 : 0,
139
- ctime: stats.ctimeMs,
140
- mtime: stats.mtimeMs,
141
- size: stats.size
142
- };
143
- } catch {
144
- return;
145
- }
146
- },
147
- readFile(uri, encoding) {
148
- try {
149
- console.log("readFile", uri.path);
150
- return fs.readFileSync(uri.path, {
151
- encoding: encoding ?? "utf-8"
152
- });
153
- } catch {
154
- return;
155
- }
156
- },
157
- readDirectory(uri) {
158
- try {
159
- const files = fs.readdirSync(uri.path, { withFileTypes: true });
160
- console.log("readDirectory", uri.path, files.map((f) => f.name));
161
- return files.map((file) => {
162
- return [
163
- file.name,
164
- file.isFile() ? 1 : file.isDirectory() ? 2 : file.isSymbolicLink() ? 64 : 0
165
- ];
166
- });
167
- } catch {
168
- return [];
169
- }
170
- }
171
- };
172
- }
173
-
174
- // packages/language-server/src/browser.ts
175
- var connection = createConnection();
176
- var server = createServer(connection);
177
- server.fileSystem.install("file", zenFsProvider(memfs));
178
- connection.listen();
179
- connection.onInitialize(async (params) => {
180
- const {
181
- tsdkUrl = "https://cdn.jsdelivr.net/npm/typescript@latest/lib",
182
- fs = {},
183
- inlineGtsConfig = {},
184
- inlineCompilerOptions = {}
185
- } = params.initializationOptions ?? {};
186
- const tsdk = await loadTsdkByUrl(tsdkUrl, params.locale);
187
- await loadLibs(tsdkUrl);
188
- for (const [filepath, content] of Object.entries(fs)) {
189
- memfs.mkdirSync(path.dirname(filepath), { recursive: true });
190
- memfs.writeFileSync(filepath, content);
191
- }
192
- return server.initialize(params, createTypeScriptProject(tsdk.typescript, tsdk.diagnosticMessages, ({ env }) => {
193
- return {
194
- languagePlugins: [
195
- createGtsLanguagePlugin(tsdk.typescript, inlineGtsConfig)
196
- ]
197
- };
198
- }), [
199
- ...createTypeScriptServices(tsdk.typescript),
200
- createDiagnosticsPlugin(),
201
- createCompletionPlugin()
202
- ]);
203
- });
204
- connection.onInitialized(server.initialized);
205
- connection.onShutdown(server.shutdown);
206
- self.addEventListener("error", (event) => {
207
- console.error("Uncaught exception:", event.error);
208
- });
209
- self.addEventListener("unhandledrejection", (event) => {
210
- console.error("Unhandled rejection at:", event.promise, "reason:", event.reason);
211
- });
212
- async function loadLibs(tsdkUrl) {
213
- memfs.mkdirSync("/node_modules/typescript/lib", { recursive: true });
214
- const libs = await Promise.all(ALL_LIBS.map((lib) => fetch(`${tsdkUrl}/${lib}`).then((res) => res.text()).then((content) => [lib, content])));
215
- for (const [lib, content] of libs) {
216
- memfs.writeFileSync(`/node_modules/typescript/lib/${lib}`, content);
217
- }
218
- }
219
- var ALL_LIBS = [
220
- "lib.d.ts",
221
- "lib.decorators.d.ts",
222
- "lib.decorators.legacy.d.ts",
223
- "lib.dom.asynciterable.d.ts",
224
- "lib.dom.d.ts",
225
- "lib.dom.iterable.d.ts",
226
- "lib.es2015.collection.d.ts",
227
- "lib.es2015.core.d.ts",
228
- "lib.es2015.d.ts",
229
- "lib.es2015.generator.d.ts",
230
- "lib.es2015.iterable.d.ts",
231
- "lib.es2015.promise.d.ts",
232
- "lib.es2015.proxy.d.ts",
233
- "lib.es2015.reflect.d.ts",
234
- "lib.es2015.symbol.d.ts",
235
- "lib.es2015.symbol.wellknown.d.ts",
236
- "lib.es2016.array.include.d.ts",
237
- "lib.es2016.d.ts",
238
- "lib.es2016.full.d.ts",
239
- "lib.es2016.intl.d.ts",
240
- "lib.es2017.arraybuffer.d.ts",
241
- "lib.es2017.d.ts",
242
- "lib.es2017.date.d.ts",
243
- "lib.es2017.full.d.ts",
244
- "lib.es2017.intl.d.ts",
245
- "lib.es2017.object.d.ts",
246
- "lib.es2017.sharedmemory.d.ts",
247
- "lib.es2017.string.d.ts",
248
- "lib.es2017.typedarrays.d.ts",
249
- "lib.es2018.asyncgenerator.d.ts",
250
- "lib.es2018.asynciterable.d.ts",
251
- "lib.es2018.d.ts",
252
- "lib.es2018.full.d.ts",
253
- "lib.es2018.intl.d.ts",
254
- "lib.es2018.promise.d.ts",
255
- "lib.es2018.regexp.d.ts",
256
- "lib.es2019.array.d.ts",
257
- "lib.es2019.d.ts",
258
- "lib.es2019.full.d.ts",
259
- "lib.es2019.intl.d.ts",
260
- "lib.es2019.object.d.ts",
261
- "lib.es2019.string.d.ts",
262
- "lib.es2019.symbol.d.ts",
263
- "lib.es2020.bigint.d.ts",
264
- "lib.es2020.d.ts",
265
- "lib.es2020.date.d.ts",
266
- "lib.es2020.full.d.ts",
267
- "lib.es2020.intl.d.ts",
268
- "lib.es2020.number.d.ts",
269
- "lib.es2020.promise.d.ts",
270
- "lib.es2020.sharedmemory.d.ts",
271
- "lib.es2020.string.d.ts",
272
- "lib.es2020.symbol.wellknown.d.ts",
273
- "lib.es2021.d.ts",
274
- "lib.es2021.full.d.ts",
275
- "lib.es2021.intl.d.ts",
276
- "lib.es2021.promise.d.ts",
277
- "lib.es2021.string.d.ts",
278
- "lib.es2021.weakref.d.ts",
279
- "lib.es2022.array.d.ts",
280
- "lib.es2022.d.ts",
281
- "lib.es2022.error.d.ts",
282
- "lib.es2022.full.d.ts",
283
- "lib.es2022.intl.d.ts",
284
- "lib.es2022.object.d.ts",
285
- "lib.es2022.regexp.d.ts",
286
- "lib.es2022.string.d.ts",
287
- "lib.es2023.array.d.ts",
288
- "lib.es2023.collection.d.ts",
289
- "lib.es2023.d.ts",
290
- "lib.es2023.full.d.ts",
291
- "lib.es2023.intl.d.ts",
292
- "lib.es2024.arraybuffer.d.ts",
293
- "lib.es2024.collection.d.ts",
294
- "lib.es2024.d.ts",
295
- "lib.es2024.full.d.ts",
296
- "lib.es2024.object.d.ts",
297
- "lib.es2024.promise.d.ts",
298
- "lib.es2024.regexp.d.ts",
299
- "lib.es2024.sharedmemory.d.ts",
300
- "lib.es2024.string.d.ts",
301
- "lib.es5.d.ts",
302
- "lib.es6.d.ts",
303
- "lib.esnext.array.d.ts",
304
- "lib.esnext.collection.d.ts",
305
- "lib.esnext.d.ts",
306
- "lib.esnext.decorators.d.ts",
307
- "lib.esnext.disposable.d.ts",
308
- "lib.esnext.error.d.ts",
309
- "lib.esnext.float16.d.ts",
310
- "lib.esnext.full.d.ts",
311
- "lib.esnext.intl.d.ts",
312
- "lib.esnext.iterator.d.ts",
313
- "lib.esnext.promise.d.ts",
314
- "lib.esnext.sharedmemory.d.ts",
315
- "lib.scripthost.d.ts",
316
- "lib.webworker.asynciterable.d.ts",
317
- "lib.webworker.d.ts",
318
- "lib.webworker.importscripts.d.ts",
319
- "lib.webworker.iterable.d.ts"
320
- ];
package/dist/node/node.js DELETED
@@ -1,149 +0,0 @@
1
- // packages/language-server/src/node.ts
2
- import {
3
- createConnection,
4
- createServer,
5
- createTypeScriptProject,
6
- loadTsdkByPath
7
- } from "@volar/language-server/node.js";
8
- import { createGtsLanguagePlugin } from "@gi-tcg/gts-language-plugin";
9
-
10
- // packages/language-server/src/diagnostics.ts
11
- import {
12
- DiagnosticSeverity
13
- } from "@volar/language-server";
14
-
15
- // packages/language-server/src/utils.ts
16
- import { URI } from "vscode-uri";
17
- import { GtsVirtualCode } from "@gi-tcg/gts-language-plugin";
18
- function getVirtualCode(document, context) {
19
- const uri = URI.parse(document.uri);
20
- const decoded = context.decodeEmbeddedDocumentUri(uri);
21
- const [sourceUri, virtualCodeId] = decoded;
22
- const sourceScript = context.language.scripts.get(sourceUri);
23
- const virtualCode = sourceScript?.generated?.embeddedCodes.get(virtualCodeId);
24
- if (!virtualCode) {
25
- return [null, sourceUri];
26
- }
27
- if (!(virtualCode instanceof GtsVirtualCode)) {
28
- return [null, sourceUri];
29
- }
30
- return [virtualCode, sourceUri];
31
- }
32
-
33
- // packages/language-server/src/diagnostics.ts
34
- var createDiagnosticsPlugin = () => {
35
- return {
36
- name: "gts-diagnostics",
37
- capabilities: {
38
- diagnosticProvider: {
39
- interFileDependencies: false,
40
- workspaceDiagnostics: false
41
- }
42
- },
43
- create: (context) => {
44
- return {
45
- provideDiagnostics: (document) => {
46
- try {
47
- const [virtualCode] = getVirtualCode(document, context);
48
- if (!virtualCode) {
49
- return;
50
- }
51
- return virtualCode.errors.map((err) => {
52
- const loc = err.position ?? {
53
- start: { line: 1, column: 0 },
54
- end: { line: 1, column: 1 }
55
- };
56
- const range = {
57
- start: {
58
- line: loc.start.line - 1,
59
- character: loc.start.column
60
- },
61
- end: { line: loc.end.line - 1, character: loc.end.column }
62
- };
63
- return {
64
- severity: DiagnosticSeverity.Error,
65
- range,
66
- message: err.message,
67
- source: "gts-transpiler",
68
- code: "gts-transpiler-error"
69
- };
70
- });
71
- } catch (e) {
72
- console.error(e);
73
- return;
74
- }
75
- }
76
- };
77
- }
78
- };
79
- };
80
-
81
- // packages/language-server/src/typescript.ts
82
- import { create } from "volar-service-typescript";
83
- function createTypeScriptServices(ts) {
84
- const services = create(ts);
85
- const semanticService = services.find((service) => service.name === "typescript-semantic");
86
- if (semanticService?.capabilities.signatureHelpProvider?.triggerCharacters) {
87
- semanticService.capabilities.signatureHelpProvider.triggerCharacters.push(" ");
88
- }
89
- return services;
90
- }
91
-
92
- // packages/language-server/src/completion.ts
93
- var createCompletionPlugin = () => {
94
- return {
95
- name: "gts-completion",
96
- capabilities: {
97
- completionProvider: {
98
- triggerCharacters: [":"]
99
- }
100
- },
101
- create: (context) => {
102
- let originalProvideCompletionItems;
103
- for (const [plugin, instance] of context.plugins) {
104
- if (plugin.name === "typescript-semantic") {
105
- originalProvideCompletionItems = instance.provideCompletionItems;
106
- }
107
- }
108
- if (!originalProvideCompletionItems) {
109
- console.warn(`TS's original provideCompletionItems not found`);
110
- return {};
111
- }
112
- return {
113
- provideCompletionItems: async (document, position, context2, token) => {
114
- if (context2.triggerCharacter === ":") {
115
- context2.triggerCharacter = ".";
116
- const response = await originalProvideCompletionItems(document, position, context2, token);
117
- return response;
118
- }
119
- return null;
120
- }
121
- };
122
- }
123
- };
124
- };
125
-
126
- // packages/language-server/src/node.ts
127
- var connection = createConnection();
128
- var server = createServer(connection);
129
- connection.listen();
130
- connection.onInitialize((params) => {
131
- const tsdk = loadTsdkByPath(params.initializationOptions.typescript.tsdk, params.locale);
132
- return server.initialize(params, createTypeScriptProject(tsdk.typescript, tsdk.diagnosticMessages, () => {
133
- return {
134
- languagePlugins: [createGtsLanguagePlugin(tsdk.typescript)]
135
- };
136
- }), [
137
- ...createTypeScriptServices(tsdk.typescript),
138
- createDiagnosticsPlugin(),
139
- createCompletionPlugin()
140
- ]);
141
- });
142
- connection.onInitialized(server.initialized);
143
- connection.onShutdown(server.shutdown);
144
- process.on("uncaughtException", (err) => {
145
- console.error("Uncaught exception:", err);
146
- });
147
- process.on("unhandledRejection", (reason, promise) => {
148
- console.error("Unhandled rejection at:", promise, "reason:", reason);
149
- });
@@ -1,5 +0,0 @@
1
- // packages/language-server/src/web_worker.ts
2
- var web_worker_default = undefined;
3
- export {
4
- web_worker_default as default
5
- };