@player-lang/json-language-server 0.0.2-next.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/dist/cjs/index.cjs +244 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/index.legacy-esm.js +215 -0
- package/dist/index.mjs +215 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +29 -0
- package/src/index.ts +239 -0
- package/src/utils.ts +32 -0
- package/types/index.d.ts +2 -0
- package/types/utils.d.ts +5 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-server/src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
runAndCatch: () => runAndCatch
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
var import_vscode_languageserver2 = require("vscode-languageserver");
|
|
37
|
+
var import_vscode_languageserver_textdocument = require("vscode-languageserver-textdocument");
|
|
38
|
+
var import_json_language_service = require("@player-lang/json-language-service");
|
|
39
|
+
var import_fs = __toESM(require("fs"));
|
|
40
|
+
|
|
41
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-server/src/utils.ts
|
|
42
|
+
var import_vscode_languageserver = require("vscode-languageserver");
|
|
43
|
+
function cancel() {
|
|
44
|
+
return new import_vscode_languageserver.ResponseError(
|
|
45
|
+
-32800,
|
|
46
|
+
"Request cancelled"
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
async function runAndCatch(func, token, errorVal) {
|
|
50
|
+
if (token.isCancellationRequested) {
|
|
51
|
+
return cancel();
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const result = await func();
|
|
55
|
+
if (token.isCancellationRequested) {
|
|
56
|
+
return cancel();
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return errorVal;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-server/src/index.ts
|
|
65
|
+
var dateFormat = new Intl.DateTimeFormat("en", {
|
|
66
|
+
year: "numeric",
|
|
67
|
+
month: "2-digit",
|
|
68
|
+
day: "2-digit",
|
|
69
|
+
hour12: false,
|
|
70
|
+
hour: "2-digit",
|
|
71
|
+
minute: "2-digit",
|
|
72
|
+
second: "2-digit"
|
|
73
|
+
});
|
|
74
|
+
var logFilePath = process.argv.length === 4 && import_fs.default.existsSync(process.argv[3]) && process.argv[3];
|
|
75
|
+
var formatLog = (a) => {
|
|
76
|
+
const msg = typeof a === "string" ? a : JSON.stringify(a);
|
|
77
|
+
const date = /* @__PURE__ */ new Date();
|
|
78
|
+
return `${dateFormat.format(date)},$${date.getMilliseconds()} | ${msg}
|
|
79
|
+
`;
|
|
80
|
+
};
|
|
81
|
+
var fileLog = logFilePath ? (a) => import_fs.default.appendFile(logFilePath, formatLog(a), () => {
|
|
82
|
+
}) : () => {
|
|
83
|
+
};
|
|
84
|
+
var service = new import_json_language_service.PlayerLanguageService();
|
|
85
|
+
var connection = (0, import_vscode_languageserver2.createConnection)(import_vscode_languageserver2.ProposedFeatures.all);
|
|
86
|
+
var documents = new import_vscode_languageserver2.TextDocuments(import_vscode_languageserver_textdocument.TextDocument);
|
|
87
|
+
var hasConfigurationCapability = false;
|
|
88
|
+
process.on("unhandledRejection", (e) => {
|
|
89
|
+
console.error(e.message);
|
|
90
|
+
});
|
|
91
|
+
process.on("uncaughtException", (e) => {
|
|
92
|
+
console.error(e.message);
|
|
93
|
+
});
|
|
94
|
+
console.log = (a) => {
|
|
95
|
+
fileLog(a);
|
|
96
|
+
connection.console.log(JSON.stringify(a, null, 2));
|
|
97
|
+
};
|
|
98
|
+
console.error = (a) => {
|
|
99
|
+
fileLog(a);
|
|
100
|
+
connection.console.error(JSON.stringify(a, null, 2));
|
|
101
|
+
};
|
|
102
|
+
async function validate(textDocument) {
|
|
103
|
+
const diagnostics = await service.validateTextDocument(textDocument);
|
|
104
|
+
if (diagnostics) {
|
|
105
|
+
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
connection.onInitialize((params) => {
|
|
109
|
+
const { capabilities } = params;
|
|
110
|
+
hasConfigurationCapability = Boolean(
|
|
111
|
+
capabilities.workspace && Boolean(capabilities.workspace.configuration)
|
|
112
|
+
);
|
|
113
|
+
fileLog("Initialized Player LSP Server");
|
|
114
|
+
return {
|
|
115
|
+
capabilities: {
|
|
116
|
+
textDocumentSync: import_vscode_languageserver2.TextDocumentSyncKind.Full,
|
|
117
|
+
codeActionProvider: true,
|
|
118
|
+
definitionProvider: true,
|
|
119
|
+
completionProvider: {
|
|
120
|
+
resolveProvider: false,
|
|
121
|
+
triggerCharacters: ['"', ":"]
|
|
122
|
+
},
|
|
123
|
+
documentFormattingProvider: true,
|
|
124
|
+
documentRangeFormattingProvider: true,
|
|
125
|
+
hoverProvider: true
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
connection.onCompletion(async (textDocumentPosition, token) => {
|
|
130
|
+
return runAndCatch(
|
|
131
|
+
() => {
|
|
132
|
+
const document = documents.get(textDocumentPosition.textDocument.uri);
|
|
133
|
+
if (document !== void 0) {
|
|
134
|
+
return service.getCompletionsAtPosition(
|
|
135
|
+
document,
|
|
136
|
+
textDocumentPosition.position
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
},
|
|
141
|
+
token,
|
|
142
|
+
null
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
connection.onHover(async (hoverParams, token) => {
|
|
146
|
+
return runAndCatch(
|
|
147
|
+
() => {
|
|
148
|
+
const document = documents.get(hoverParams.textDocument.uri);
|
|
149
|
+
if (document !== void 0) {
|
|
150
|
+
return service.getHoverInfoAtPosition(document, hoverParams.position);
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
},
|
|
154
|
+
token,
|
|
155
|
+
null
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
connection.onCompletionResolve(
|
|
159
|
+
(item, token) => runAndCatch(() => service.resolveCompletionItem(item), token, item)
|
|
160
|
+
);
|
|
161
|
+
connection.onDocumentFormatting(
|
|
162
|
+
(formattingParams, token) => runAndCatch(
|
|
163
|
+
() => {
|
|
164
|
+
const document = documents.get(formattingParams.textDocument.uri);
|
|
165
|
+
if (document !== void 0) {
|
|
166
|
+
return service.formatTextDocument(document, formattingParams.options);
|
|
167
|
+
}
|
|
168
|
+
return void 0;
|
|
169
|
+
},
|
|
170
|
+
token,
|
|
171
|
+
null
|
|
172
|
+
)
|
|
173
|
+
);
|
|
174
|
+
connection.onDocumentRangeFormatting(
|
|
175
|
+
(formattingParams, token) => runAndCatch(
|
|
176
|
+
() => {
|
|
177
|
+
const document = documents.get(formattingParams.textDocument.uri);
|
|
178
|
+
if (document !== void 0) {
|
|
179
|
+
return service.formatTextDocument(
|
|
180
|
+
document,
|
|
181
|
+
formattingParams.options,
|
|
182
|
+
formattingParams.range
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
return void 0;
|
|
186
|
+
},
|
|
187
|
+
token,
|
|
188
|
+
null
|
|
189
|
+
)
|
|
190
|
+
);
|
|
191
|
+
connection.onDefinition(
|
|
192
|
+
(definitionParams, token) => runAndCatch(
|
|
193
|
+
() => {
|
|
194
|
+
const document = documents.get(definitionParams.textDocument.uri);
|
|
195
|
+
if (document !== void 0) {
|
|
196
|
+
return service.getDefinitionAtPosition(
|
|
197
|
+
document,
|
|
198
|
+
definitionParams.position
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
return void 0;
|
|
202
|
+
},
|
|
203
|
+
token,
|
|
204
|
+
null
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
connection.onInitialized(() => {
|
|
208
|
+
if (hasConfigurationCapability) {
|
|
209
|
+
connection.client.register(
|
|
210
|
+
import_vscode_languageserver2.DidChangeConfigurationNotification.type,
|
|
211
|
+
void 0
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
connection.onCodeAction((codeAction) => {
|
|
216
|
+
const document = documents.get(codeAction.textDocument.uri);
|
|
217
|
+
if (!document) {
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
return service.getCodeActionsInRange(document, codeAction.context);
|
|
221
|
+
});
|
|
222
|
+
documents.onDidClose((change) => {
|
|
223
|
+
service.onClose(change.document);
|
|
224
|
+
});
|
|
225
|
+
documents.onDidChangeContent((change) => {
|
|
226
|
+
validate(change.document);
|
|
227
|
+
});
|
|
228
|
+
connection.onNotification(
|
|
229
|
+
"player/setAssetBundles",
|
|
230
|
+
(assetBundles) => {
|
|
231
|
+
if (Array.isArray(assetBundles)) {
|
|
232
|
+
console.log("Updating asset type bundles");
|
|
233
|
+
service.setAssetTypes(assetBundles);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
fileLog("Starting Player LSP Server");
|
|
238
|
+
documents.listen(connection);
|
|
239
|
+
connection.listen();
|
|
240
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
241
|
+
0 && (module.exports = {
|
|
242
|
+
runAndCatch
|
|
243
|
+
});
|
|
244
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-server/src/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-server/src/utils.ts"],"sourcesContent":["import type { InitializeParams } from \"vscode-languageserver\";\nimport {\n createConnection,\n ProposedFeatures,\n TextDocuments,\n DidChangeConfigurationNotification,\n TextDocumentSyncKind,\n} from \"vscode-languageserver\";\nimport { TextDocument } from \"vscode-languageserver-textdocument\";\nimport { PlayerLanguageService } from \"@player-lang/json-language-service\";\nimport fs from \"fs\";\nimport { runAndCatch } from \"./utils\";\n\nexport * from \"./utils\";\n\nconst dateFormat = new Intl.DateTimeFormat(\"en\", {\n year: \"numeric\",\n month: \"2-digit\",\n day: \"2-digit\",\n hour12: false,\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n});\n\nconst logFilePath =\n process.argv.length === 4 &&\n fs.existsSync(process.argv[3]) &&\n process.argv[3];\n\n/** Format a log message to work in the console */\nconst formatLog = (a: unknown): string => {\n const msg = typeof a === \"string\" ? a : JSON.stringify(a);\n const date = new Date();\n return `${dateFormat.format(date)},$${date.getMilliseconds()} | ${msg} \\n`;\n};\n\nconst fileLog = logFilePath\n ? (a: unknown) =>\n fs.appendFile(logFilePath, formatLog(a), () => {\n /* do nothing */\n })\n : () => {\n /* do nothing */\n };\n\nconst service = new PlayerLanguageService();\n\nconst connection = createConnection(ProposedFeatures.all);\nconst documents = new TextDocuments(TextDocument);\n\nlet hasConfigurationCapability = false;\n\nprocess.on(\"unhandledRejection\", (e: Error) => {\n console.error(e.message);\n});\nprocess.on(\"uncaughtException\", (e: Error) => {\n console.error(e.message);\n});\n\nconsole.log = (a: Error) => {\n fileLog(a);\n connection.console.log(JSON.stringify(a, null, 2));\n};\n\nconsole.error = (a: Error) => {\n fileLog(a);\n connection.console.error(JSON.stringify(a, null, 2));\n};\n\n/** Handle validating a text-document and returning the response back to the extension */\nasync function validate(textDocument: TextDocument): Promise<void> {\n const diagnostics = await service.validateTextDocument(textDocument);\n\n if (diagnostics) {\n connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });\n }\n}\n\nconnection.onInitialize((params: InitializeParams) => {\n const { capabilities } = params;\n\n // Does the client support the `workspace/configuration` request?\n // If not, we will fall back using global settings\n hasConfigurationCapability = Boolean(\n capabilities.workspace && Boolean(capabilities.workspace.configuration),\n );\n\n fileLog(\"Initialized Player LSP Server\");\n return {\n capabilities: {\n textDocumentSync: TextDocumentSyncKind.Full,\n codeActionProvider: true,\n definitionProvider: true,\n completionProvider: {\n resolveProvider: false,\n triggerCharacters: ['\"', \":\"],\n },\n documentFormattingProvider: true,\n documentRangeFormattingProvider: true,\n hoverProvider: true,\n },\n };\n});\n\nconnection.onCompletion(async (textDocumentPosition, token) => {\n return runAndCatch(\n () => {\n const document = documents.get(textDocumentPosition.textDocument.uri);\n if (document !== undefined) {\n return service.getCompletionsAtPosition(\n document,\n textDocumentPosition.position,\n );\n }\n\n return null;\n },\n token,\n null,\n );\n});\n\nconnection.onHover(async (hoverParams, token) => {\n return runAndCatch(\n () => {\n const document = documents.get(hoverParams.textDocument.uri);\n if (document !== undefined) {\n return service.getHoverInfoAtPosition(document, hoverParams.position);\n }\n\n return null;\n },\n token,\n null,\n );\n});\n\nconnection.onCompletionResolve((item, token) =>\n runAndCatch(() => service.resolveCompletionItem(item), token, item),\n);\n\nconnection.onDocumentFormatting((formattingParams, token) =>\n runAndCatch(\n () => {\n const document = documents.get(formattingParams.textDocument.uri);\n\n if (document !== undefined) {\n return service.formatTextDocument(document, formattingParams.options);\n }\n\n return undefined;\n },\n token,\n null,\n ),\n);\n\nconnection.onDocumentRangeFormatting((formattingParams, token) =>\n runAndCatch(\n () => {\n const document = documents.get(formattingParams.textDocument.uri);\n\n if (document !== undefined) {\n return service.formatTextDocument(\n document,\n formattingParams.options,\n formattingParams.range,\n );\n }\n\n return undefined;\n },\n token,\n null,\n ),\n);\n\nconnection.onDefinition((definitionParams, token) =>\n runAndCatch(\n () => {\n const document = documents.get(definitionParams.textDocument.uri);\n\n if (document !== undefined) {\n return service.getDefinitionAtPosition(\n document,\n definitionParams.position,\n );\n }\n\n return undefined;\n },\n token,\n null,\n ),\n);\n\nconnection.onInitialized(() => {\n if (hasConfigurationCapability) {\n // Register for all configuration changes.\n connection.client.register(\n DidChangeConfigurationNotification.type,\n undefined,\n );\n }\n});\n\nconnection.onCodeAction((codeAction) => {\n const document = documents.get(codeAction.textDocument.uri);\n if (!document) {\n return [];\n }\n\n return service.getCodeActionsInRange(document, codeAction.context);\n});\n\ndocuments.onDidClose((change) => {\n service.onClose(change.document);\n});\n\ndocuments.onDidChangeContent((change) => {\n validate(change.document);\n});\n\nconnection.onNotification(\n \"player/setAssetBundles\",\n (assetBundles: Array<string>) => {\n // Don't trust data over the wire\n if (Array.isArray(assetBundles)) {\n console.log(\"Updating asset type bundles\");\n service.setAssetTypes(assetBundles);\n }\n },\n);\n\nfileLog(\"Starting Player LSP Server\");\n\ndocuments.listen(connection);\nconnection.listen();\n","import type { CancellationToken } from \"vscode-languageserver\";\nimport { ResponseError } from \"vscode-languageserver\";\n\n/** Get a cancellation error */\nfunction cancel() {\n return new ResponseError(\n -32800 /* ErrorCodes.RequestCancelled */,\n \"Request cancelled\",\n );\n}\n\n/** Run the given function and handle being cancelled */\nexport async function runAndCatch<T>(\n func: () => Promise<T> | T,\n token: CancellationToken,\n errorVal: T,\n): Promise<T | ResponseError<any>> {\n if (token.isCancellationRequested) {\n return cancel();\n }\n\n try {\n const result = await func();\n if (token.isCancellationRequested) {\n return cancel();\n }\n\n return result;\n } catch (e) {\n return errorVal;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,gCAMO;AACP,gDAA6B;AAC7B,mCAAsC;AACtC,gBAAe;;;ACTf,mCAA8B;AAG9B,SAAS,SAAS;AAChB,SAAO,IAAI;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;AAGA,eAAsB,YACpB,MACA,OACA,UACiC;AACjC,MAAI,MAAM,yBAAyB;AACjC,WAAO,OAAO;AAAA,EAChB;AAEA,MAAI;AACF,UAAM,SAAS,MAAM,KAAK;AAC1B,QAAI,MAAM,yBAAyB;AACjC,aAAO,OAAO;AAAA,IAChB;AAEA,WAAO;AAAA,EACT,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;;;ADhBA,IAAM,aAAa,IAAI,KAAK,eAAe,MAAM;AAAA,EAC/C,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AACV,CAAC;AAED,IAAM,cACJ,QAAQ,KAAK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AU,OAAO,UAAU;AAC3B,WAAW,OAAO;","names":["import_vscode_languageserver","fs"]}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-server/src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
createConnection,
|
|
4
|
+
ProposedFeatures,
|
|
5
|
+
TextDocuments,
|
|
6
|
+
DidChangeConfigurationNotification,
|
|
7
|
+
TextDocumentSyncKind
|
|
8
|
+
} from "vscode-languageserver";
|
|
9
|
+
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
10
|
+
import { PlayerLanguageService } from "@player-lang/json-language-service";
|
|
11
|
+
import fs from "fs";
|
|
12
|
+
|
|
13
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-server/src/utils.ts
|
|
14
|
+
import { ResponseError } from "vscode-languageserver";
|
|
15
|
+
function cancel() {
|
|
16
|
+
return new ResponseError(
|
|
17
|
+
-32800,
|
|
18
|
+
"Request cancelled"
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
async function runAndCatch(func, token, errorVal) {
|
|
22
|
+
if (token.isCancellationRequested) {
|
|
23
|
+
return cancel();
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const result = await func();
|
|
27
|
+
if (token.isCancellationRequested) {
|
|
28
|
+
return cancel();
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return errorVal;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-server/src/index.ts
|
|
37
|
+
var dateFormat = new Intl.DateTimeFormat("en", {
|
|
38
|
+
year: "numeric",
|
|
39
|
+
month: "2-digit",
|
|
40
|
+
day: "2-digit",
|
|
41
|
+
hour12: false,
|
|
42
|
+
hour: "2-digit",
|
|
43
|
+
minute: "2-digit",
|
|
44
|
+
second: "2-digit"
|
|
45
|
+
});
|
|
46
|
+
var logFilePath = process.argv.length === 4 && fs.existsSync(process.argv[3]) && process.argv[3];
|
|
47
|
+
var formatLog = (a) => {
|
|
48
|
+
const msg = typeof a === "string" ? a : JSON.stringify(a);
|
|
49
|
+
const date = /* @__PURE__ */ new Date();
|
|
50
|
+
return `${dateFormat.format(date)},$${date.getMilliseconds()} | ${msg}
|
|
51
|
+
`;
|
|
52
|
+
};
|
|
53
|
+
var fileLog = logFilePath ? (a) => fs.appendFile(logFilePath, formatLog(a), () => {
|
|
54
|
+
}) : () => {
|
|
55
|
+
};
|
|
56
|
+
var service = new PlayerLanguageService();
|
|
57
|
+
var connection = createConnection(ProposedFeatures.all);
|
|
58
|
+
var documents = new TextDocuments(TextDocument);
|
|
59
|
+
var hasConfigurationCapability = false;
|
|
60
|
+
process.on("unhandledRejection", (e) => {
|
|
61
|
+
console.error(e.message);
|
|
62
|
+
});
|
|
63
|
+
process.on("uncaughtException", (e) => {
|
|
64
|
+
console.error(e.message);
|
|
65
|
+
});
|
|
66
|
+
console.log = (a) => {
|
|
67
|
+
fileLog(a);
|
|
68
|
+
connection.console.log(JSON.stringify(a, null, 2));
|
|
69
|
+
};
|
|
70
|
+
console.error = (a) => {
|
|
71
|
+
fileLog(a);
|
|
72
|
+
connection.console.error(JSON.stringify(a, null, 2));
|
|
73
|
+
};
|
|
74
|
+
async function validate(textDocument) {
|
|
75
|
+
const diagnostics = await service.validateTextDocument(textDocument);
|
|
76
|
+
if (diagnostics) {
|
|
77
|
+
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
connection.onInitialize((params) => {
|
|
81
|
+
const { capabilities } = params;
|
|
82
|
+
hasConfigurationCapability = Boolean(
|
|
83
|
+
capabilities.workspace && Boolean(capabilities.workspace.configuration)
|
|
84
|
+
);
|
|
85
|
+
fileLog("Initialized Player LSP Server");
|
|
86
|
+
return {
|
|
87
|
+
capabilities: {
|
|
88
|
+
textDocumentSync: TextDocumentSyncKind.Full,
|
|
89
|
+
codeActionProvider: true,
|
|
90
|
+
definitionProvider: true,
|
|
91
|
+
completionProvider: {
|
|
92
|
+
resolveProvider: false,
|
|
93
|
+
triggerCharacters: ['"', ":"]
|
|
94
|
+
},
|
|
95
|
+
documentFormattingProvider: true,
|
|
96
|
+
documentRangeFormattingProvider: true,
|
|
97
|
+
hoverProvider: true
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
connection.onCompletion(async (textDocumentPosition, token) => {
|
|
102
|
+
return runAndCatch(
|
|
103
|
+
() => {
|
|
104
|
+
const document = documents.get(textDocumentPosition.textDocument.uri);
|
|
105
|
+
if (document !== void 0) {
|
|
106
|
+
return service.getCompletionsAtPosition(
|
|
107
|
+
document,
|
|
108
|
+
textDocumentPosition.position
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
},
|
|
113
|
+
token,
|
|
114
|
+
null
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
connection.onHover(async (hoverParams, token) => {
|
|
118
|
+
return runAndCatch(
|
|
119
|
+
() => {
|
|
120
|
+
const document = documents.get(hoverParams.textDocument.uri);
|
|
121
|
+
if (document !== void 0) {
|
|
122
|
+
return service.getHoverInfoAtPosition(document, hoverParams.position);
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
},
|
|
126
|
+
token,
|
|
127
|
+
null
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
connection.onCompletionResolve(
|
|
131
|
+
(item, token) => runAndCatch(() => service.resolveCompletionItem(item), token, item)
|
|
132
|
+
);
|
|
133
|
+
connection.onDocumentFormatting(
|
|
134
|
+
(formattingParams, token) => runAndCatch(
|
|
135
|
+
() => {
|
|
136
|
+
const document = documents.get(formattingParams.textDocument.uri);
|
|
137
|
+
if (document !== void 0) {
|
|
138
|
+
return service.formatTextDocument(document, formattingParams.options);
|
|
139
|
+
}
|
|
140
|
+
return void 0;
|
|
141
|
+
},
|
|
142
|
+
token,
|
|
143
|
+
null
|
|
144
|
+
)
|
|
145
|
+
);
|
|
146
|
+
connection.onDocumentRangeFormatting(
|
|
147
|
+
(formattingParams, token) => runAndCatch(
|
|
148
|
+
() => {
|
|
149
|
+
const document = documents.get(formattingParams.textDocument.uri);
|
|
150
|
+
if (document !== void 0) {
|
|
151
|
+
return service.formatTextDocument(
|
|
152
|
+
document,
|
|
153
|
+
formattingParams.options,
|
|
154
|
+
formattingParams.range
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
return void 0;
|
|
158
|
+
},
|
|
159
|
+
token,
|
|
160
|
+
null
|
|
161
|
+
)
|
|
162
|
+
);
|
|
163
|
+
connection.onDefinition(
|
|
164
|
+
(definitionParams, token) => runAndCatch(
|
|
165
|
+
() => {
|
|
166
|
+
const document = documents.get(definitionParams.textDocument.uri);
|
|
167
|
+
if (document !== void 0) {
|
|
168
|
+
return service.getDefinitionAtPosition(
|
|
169
|
+
document,
|
|
170
|
+
definitionParams.position
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
return void 0;
|
|
174
|
+
},
|
|
175
|
+
token,
|
|
176
|
+
null
|
|
177
|
+
)
|
|
178
|
+
);
|
|
179
|
+
connection.onInitialized(() => {
|
|
180
|
+
if (hasConfigurationCapability) {
|
|
181
|
+
connection.client.register(
|
|
182
|
+
DidChangeConfigurationNotification.type,
|
|
183
|
+
void 0
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
connection.onCodeAction((codeAction) => {
|
|
188
|
+
const document = documents.get(codeAction.textDocument.uri);
|
|
189
|
+
if (!document) {
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
return service.getCodeActionsInRange(document, codeAction.context);
|
|
193
|
+
});
|
|
194
|
+
documents.onDidClose((change) => {
|
|
195
|
+
service.onClose(change.document);
|
|
196
|
+
});
|
|
197
|
+
documents.onDidChangeContent((change) => {
|
|
198
|
+
validate(change.document);
|
|
199
|
+
});
|
|
200
|
+
connection.onNotification(
|
|
201
|
+
"player/setAssetBundles",
|
|
202
|
+
(assetBundles) => {
|
|
203
|
+
if (Array.isArray(assetBundles)) {
|
|
204
|
+
console.log("Updating asset type bundles");
|
|
205
|
+
service.setAssetTypes(assetBundles);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
fileLog("Starting Player LSP Server");
|
|
210
|
+
documents.listen(connection);
|
|
211
|
+
connection.listen();
|
|
212
|
+
export {
|
|
213
|
+
runAndCatch
|
|
214
|
+
};
|
|
215
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-server/src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
createConnection,
|
|
4
|
+
ProposedFeatures,
|
|
5
|
+
TextDocuments,
|
|
6
|
+
DidChangeConfigurationNotification,
|
|
7
|
+
TextDocumentSyncKind
|
|
8
|
+
} from "vscode-languageserver";
|
|
9
|
+
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
10
|
+
import { PlayerLanguageService } from "@player-lang/json-language-service";
|
|
11
|
+
import fs from "fs";
|
|
12
|
+
|
|
13
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-server/src/utils.ts
|
|
14
|
+
import { ResponseError } from "vscode-languageserver";
|
|
15
|
+
function cancel() {
|
|
16
|
+
return new ResponseError(
|
|
17
|
+
-32800,
|
|
18
|
+
"Request cancelled"
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
async function runAndCatch(func, token, errorVal) {
|
|
22
|
+
if (token.isCancellationRequested) {
|
|
23
|
+
return cancel();
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const result = await func();
|
|
27
|
+
if (token.isCancellationRequested) {
|
|
28
|
+
return cancel();
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return errorVal;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-server/src/index.ts
|
|
37
|
+
var dateFormat = new Intl.DateTimeFormat("en", {
|
|
38
|
+
year: "numeric",
|
|
39
|
+
month: "2-digit",
|
|
40
|
+
day: "2-digit",
|
|
41
|
+
hour12: false,
|
|
42
|
+
hour: "2-digit",
|
|
43
|
+
minute: "2-digit",
|
|
44
|
+
second: "2-digit"
|
|
45
|
+
});
|
|
46
|
+
var logFilePath = process.argv.length === 4 && fs.existsSync(process.argv[3]) && process.argv[3];
|
|
47
|
+
var formatLog = (a) => {
|
|
48
|
+
const msg = typeof a === "string" ? a : JSON.stringify(a);
|
|
49
|
+
const date = /* @__PURE__ */ new Date();
|
|
50
|
+
return `${dateFormat.format(date)},$${date.getMilliseconds()} | ${msg}
|
|
51
|
+
`;
|
|
52
|
+
};
|
|
53
|
+
var fileLog = logFilePath ? (a) => fs.appendFile(logFilePath, formatLog(a), () => {
|
|
54
|
+
}) : () => {
|
|
55
|
+
};
|
|
56
|
+
var service = new PlayerLanguageService();
|
|
57
|
+
var connection = createConnection(ProposedFeatures.all);
|
|
58
|
+
var documents = new TextDocuments(TextDocument);
|
|
59
|
+
var hasConfigurationCapability = false;
|
|
60
|
+
process.on("unhandledRejection", (e) => {
|
|
61
|
+
console.error(e.message);
|
|
62
|
+
});
|
|
63
|
+
process.on("uncaughtException", (e) => {
|
|
64
|
+
console.error(e.message);
|
|
65
|
+
});
|
|
66
|
+
console.log = (a) => {
|
|
67
|
+
fileLog(a);
|
|
68
|
+
connection.console.log(JSON.stringify(a, null, 2));
|
|
69
|
+
};
|
|
70
|
+
console.error = (a) => {
|
|
71
|
+
fileLog(a);
|
|
72
|
+
connection.console.error(JSON.stringify(a, null, 2));
|
|
73
|
+
};
|
|
74
|
+
async function validate(textDocument) {
|
|
75
|
+
const diagnostics = await service.validateTextDocument(textDocument);
|
|
76
|
+
if (diagnostics) {
|
|
77
|
+
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
connection.onInitialize((params) => {
|
|
81
|
+
const { capabilities } = params;
|
|
82
|
+
hasConfigurationCapability = Boolean(
|
|
83
|
+
capabilities.workspace && Boolean(capabilities.workspace.configuration)
|
|
84
|
+
);
|
|
85
|
+
fileLog("Initialized Player LSP Server");
|
|
86
|
+
return {
|
|
87
|
+
capabilities: {
|
|
88
|
+
textDocumentSync: TextDocumentSyncKind.Full,
|
|
89
|
+
codeActionProvider: true,
|
|
90
|
+
definitionProvider: true,
|
|
91
|
+
completionProvider: {
|
|
92
|
+
resolveProvider: false,
|
|
93
|
+
triggerCharacters: ['"', ":"]
|
|
94
|
+
},
|
|
95
|
+
documentFormattingProvider: true,
|
|
96
|
+
documentRangeFormattingProvider: true,
|
|
97
|
+
hoverProvider: true
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
connection.onCompletion(async (textDocumentPosition, token) => {
|
|
102
|
+
return runAndCatch(
|
|
103
|
+
() => {
|
|
104
|
+
const document = documents.get(textDocumentPosition.textDocument.uri);
|
|
105
|
+
if (document !== void 0) {
|
|
106
|
+
return service.getCompletionsAtPosition(
|
|
107
|
+
document,
|
|
108
|
+
textDocumentPosition.position
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
},
|
|
113
|
+
token,
|
|
114
|
+
null
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
connection.onHover(async (hoverParams, token) => {
|
|
118
|
+
return runAndCatch(
|
|
119
|
+
() => {
|
|
120
|
+
const document = documents.get(hoverParams.textDocument.uri);
|
|
121
|
+
if (document !== void 0) {
|
|
122
|
+
return service.getHoverInfoAtPosition(document, hoverParams.position);
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
},
|
|
126
|
+
token,
|
|
127
|
+
null
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
connection.onCompletionResolve(
|
|
131
|
+
(item, token) => runAndCatch(() => service.resolveCompletionItem(item), token, item)
|
|
132
|
+
);
|
|
133
|
+
connection.onDocumentFormatting(
|
|
134
|
+
(formattingParams, token) => runAndCatch(
|
|
135
|
+
() => {
|
|
136
|
+
const document = documents.get(formattingParams.textDocument.uri);
|
|
137
|
+
if (document !== void 0) {
|
|
138
|
+
return service.formatTextDocument(document, formattingParams.options);
|
|
139
|
+
}
|
|
140
|
+
return void 0;
|
|
141
|
+
},
|
|
142
|
+
token,
|
|
143
|
+
null
|
|
144
|
+
)
|
|
145
|
+
);
|
|
146
|
+
connection.onDocumentRangeFormatting(
|
|
147
|
+
(formattingParams, token) => runAndCatch(
|
|
148
|
+
() => {
|
|
149
|
+
const document = documents.get(formattingParams.textDocument.uri);
|
|
150
|
+
if (document !== void 0) {
|
|
151
|
+
return service.formatTextDocument(
|
|
152
|
+
document,
|
|
153
|
+
formattingParams.options,
|
|
154
|
+
formattingParams.range
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
return void 0;
|
|
158
|
+
},
|
|
159
|
+
token,
|
|
160
|
+
null
|
|
161
|
+
)
|
|
162
|
+
);
|
|
163
|
+
connection.onDefinition(
|
|
164
|
+
(definitionParams, token) => runAndCatch(
|
|
165
|
+
() => {
|
|
166
|
+
const document = documents.get(definitionParams.textDocument.uri);
|
|
167
|
+
if (document !== void 0) {
|
|
168
|
+
return service.getDefinitionAtPosition(
|
|
169
|
+
document,
|
|
170
|
+
definitionParams.position
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
return void 0;
|
|
174
|
+
},
|
|
175
|
+
token,
|
|
176
|
+
null
|
|
177
|
+
)
|
|
178
|
+
);
|
|
179
|
+
connection.onInitialized(() => {
|
|
180
|
+
if (hasConfigurationCapability) {
|
|
181
|
+
connection.client.register(
|
|
182
|
+
DidChangeConfigurationNotification.type,
|
|
183
|
+
void 0
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
connection.onCodeAction((codeAction) => {
|
|
188
|
+
const document = documents.get(codeAction.textDocument.uri);
|
|
189
|
+
if (!document) {
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
return service.getCodeActionsInRange(document, codeAction.context);
|
|
193
|
+
});
|
|
194
|
+
documents.onDidClose((change) => {
|
|
195
|
+
service.onClose(change.document);
|
|
196
|
+
});
|
|
197
|
+
documents.onDidChangeContent((change) => {
|
|
198
|
+
validate(change.document);
|
|
199
|
+
});
|
|
200
|
+
connection.onNotification(
|
|
201
|
+
"player/setAssetBundles",
|
|
202
|
+
(assetBundles) => {
|
|
203
|
+
if (Array.isArray(assetBundles)) {
|
|
204
|
+
console.log("Updating asset type bundles");
|
|
205
|
+
service.setAssetTypes(assetBundles);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
fileLog("Starting Player LSP Server");
|
|
210
|
+
documents.listen(connection);
|
|
211
|
+
connection.listen();
|
|
212
|
+
export {
|
|
213
|
+
runAndCatch
|
|
214
|
+
};
|
|
215
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-server/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-server/src/utils.ts"],"sourcesContent":["import type { InitializeParams } from \"vscode-languageserver\";\nimport {\n createConnection,\n ProposedFeatures,\n TextDocuments,\n DidChangeConfigurationNotification,\n TextDocumentSyncKind,\n} from \"vscode-languageserver\";\nimport { TextDocument } from \"vscode-languageserver-textdocument\";\nimport { PlayerLanguageService } from \"@player-lang/json-language-service\";\nimport fs from \"fs\";\nimport { runAndCatch } from \"./utils\";\n\nexport * from \"./utils\";\n\nconst dateFormat = new Intl.DateTimeFormat(\"en\", {\n year: \"numeric\",\n month: \"2-digit\",\n day: \"2-digit\",\n hour12: false,\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n});\n\nconst logFilePath =\n process.argv.length === 4 &&\n fs.existsSync(process.argv[3]) &&\n process.argv[3];\n\n/** Format a log message to work in the console */\nconst formatLog = (a: unknown): string => {\n const msg = typeof a === \"string\" ? a : JSON.stringify(a);\n const date = new Date();\n return `${dateFormat.format(date)},$${date.getMilliseconds()} | ${msg} \\n`;\n};\n\nconst fileLog = logFilePath\n ? (a: unknown) =>\n fs.appendFile(logFilePath, formatLog(a), () => {\n /* do nothing */\n })\n : () => {\n /* do nothing */\n };\n\nconst service = new PlayerLanguageService();\n\nconst connection = createConnection(ProposedFeatures.all);\nconst documents = new TextDocuments(TextDocument);\n\nlet hasConfigurationCapability = false;\n\nprocess.on(\"unhandledRejection\", (e: Error) => {\n console.error(e.message);\n});\nprocess.on(\"uncaughtException\", (e: Error) => {\n console.error(e.message);\n});\n\nconsole.log = (a: Error) => {\n fileLog(a);\n connection.console.log(JSON.stringify(a, null, 2));\n};\n\nconsole.error = (a: Error) => {\n fileLog(a);\n connection.console.error(JSON.stringify(a, null, 2));\n};\n\n/** Handle validating a text-document and returning the response back to the extension */\nasync function validate(textDocument: TextDocument): Promise<void> {\n const diagnostics = await service.validateTextDocument(textDocument);\n\n if (diagnostics) {\n connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });\n }\n}\n\nconnection.onInitialize((params: InitializeParams) => {\n const { capabilities } = params;\n\n // Does the client support the `workspace/configuration` request?\n // If not, we will fall back using global settings\n hasConfigurationCapability = Boolean(\n capabilities.workspace && Boolean(capabilities.workspace.configuration),\n );\n\n fileLog(\"Initialized Player LSP Server\");\n return {\n capabilities: {\n textDocumentSync: TextDocumentSyncKind.Full,\n codeActionProvider: true,\n definitionProvider: true,\n completionProvider: {\n resolveProvider: false,\n triggerCharacters: ['\"', \":\"],\n },\n documentFormattingProvider: true,\n documentRangeFormattingProvider: true,\n hoverProvider: true,\n },\n };\n});\n\nconnection.onCompletion(async (textDocumentPosition, token) => {\n return runAndCatch(\n () => {\n const document = documents.get(textDocumentPosition.textDocument.uri);\n if (document !== undefined) {\n return service.getCompletionsAtPosition(\n document,\n textDocumentPosition.position,\n );\n }\n\n return null;\n },\n token,\n null,\n );\n});\n\nconnection.onHover(async (hoverParams, token) => {\n return runAndCatch(\n () => {\n const document = documents.get(hoverParams.textDocument.uri);\n if (document !== undefined) {\n return service.getHoverInfoAtPosition(document, hoverParams.position);\n }\n\n return null;\n },\n token,\n null,\n );\n});\n\nconnection.onCompletionResolve((item, token) =>\n runAndCatch(() => service.resolveCompletionItem(item), token, item),\n);\n\nconnection.onDocumentFormatting((formattingParams, token) =>\n runAndCatch(\n () => {\n const document = documents.get(formattingParams.textDocument.uri);\n\n if (document !== undefined) {\n return service.formatTextDocument(document, formattingParams.options);\n }\n\n return undefined;\n },\n token,\n null,\n ),\n);\n\nconnection.onDocumentRangeFormatting((formattingParams, token) =>\n runAndCatch(\n () => {\n const document = documents.get(formattingParams.textDocument.uri);\n\n if (document !== undefined) {\n return service.formatTextDocument(\n document,\n formattingParams.options,\n formattingParams.range,\n );\n }\n\n return undefined;\n },\n token,\n null,\n ),\n);\n\nconnection.onDefinition((definitionParams, token) =>\n runAndCatch(\n () => {\n const document = documents.get(definitionParams.textDocument.uri);\n\n if (document !== undefined) {\n return service.getDefinitionAtPosition(\n document,\n definitionParams.position,\n );\n }\n\n return undefined;\n },\n token,\n null,\n ),\n);\n\nconnection.onInitialized(() => {\n if (hasConfigurationCapability) {\n // Register for all configuration changes.\n connection.client.register(\n DidChangeConfigurationNotification.type,\n undefined,\n );\n }\n});\n\nconnection.onCodeAction((codeAction) => {\n const document = documents.get(codeAction.textDocument.uri);\n if (!document) {\n return [];\n }\n\n return service.getCodeActionsInRange(document, codeAction.context);\n});\n\ndocuments.onDidClose((change) => {\n service.onClose(change.document);\n});\n\ndocuments.onDidChangeContent((change) => {\n validate(change.document);\n});\n\nconnection.onNotification(\n \"player/setAssetBundles\",\n (assetBundles: Array<string>) => {\n // Don't trust data over the wire\n if (Array.isArray(assetBundles)) {\n console.log(\"Updating asset type bundles\");\n service.setAssetTypes(assetBundles);\n }\n },\n);\n\nfileLog(\"Starting Player LSP Server\");\n\ndocuments.listen(connection);\nconnection.listen();\n","import type { CancellationToken } from \"vscode-languageserver\";\nimport { ResponseError } from \"vscode-languageserver\";\n\n/** Get a cancellation error */\nfunction cancel() {\n return new ResponseError(\n -32800 /* ErrorCodes.RequestCancelled */,\n \"Request cancelled\",\n );\n}\n\n/** Run the given function and handle being cancelled */\nexport async function runAndCatch<T>(\n func: () => Promise<T> | T,\n token: CancellationToken,\n errorVal: T,\n): Promise<T | ResponseError<any>> {\n if (token.isCancellationRequested) {\n return cancel();\n }\n\n try {\n const result = await func();\n if (token.isCancellationRequested) {\n return cancel();\n }\n\n return result;\n } catch (e) {\n return errorVal;\n }\n}\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AACtC,OAAO,QAAQ;;;ACTf,SAAS,qBAAqB;AAG9B,SAAS,SAAS;AAChB,SAAO,IAAI;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;AAGA,eAAsB,YACpB,MACA,OACA,UACiC;AACjC,MAAI,MAAM,yBAAyB;AACjC,WAAO,OAAO;AAAA,EAChB;AAEA,MAAI;AACF,UAAM,SAAS,MAAM,KAAK;AAC1B,QAAI,MAAM,yBAAyB;AACjC,aAAO,OAAO;AAAA,IAChB;AAEA,WAAO;AAAA,EACT,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;;;ADhBA,IAAM,aAAa,IAAI,KAAK,eAAe,MAAM;AAAA,EAC/C,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;A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BAA6B;AACzC,cAAQ,cAAc,YAAY;AAAA,IACpC;AAAA,EACF;AACF;AAEA,QAAQ,4BAA4B;AAEpC,UAAU,OAAO,UAAU;AAC3B,WAAW,OAAO;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"sideEffects": false,
|
|
3
|
+
"files": [
|
|
4
|
+
"dist",
|
|
5
|
+
"src",
|
|
6
|
+
"types"
|
|
7
|
+
],
|
|
8
|
+
"name": "@player-lang/json-language-server",
|
|
9
|
+
"version": "0.0.2-next.0",
|
|
10
|
+
"main": "dist/cjs/index.cjs",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@player-lang/json-language-service": "0.0.2-next.0",
|
|
13
|
+
"vscode-languageserver": "^6.1.1",
|
|
14
|
+
"vscode-languageserver-textdocument": "^1.0.1",
|
|
15
|
+
"tslib": "^2.6.2"
|
|
16
|
+
},
|
|
17
|
+
"module": "dist/index.legacy-esm.js",
|
|
18
|
+
"types": "types/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
"./package.json": "./package.json",
|
|
21
|
+
"./dist/index.css": "./dist/index.css",
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./types/index.d.ts",
|
|
24
|
+
"import": "./dist/index.mjs",
|
|
25
|
+
"default": "./dist/cjs/index.cjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {}
|
|
29
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import type { InitializeParams } from "vscode-languageserver";
|
|
2
|
+
import {
|
|
3
|
+
createConnection,
|
|
4
|
+
ProposedFeatures,
|
|
5
|
+
TextDocuments,
|
|
6
|
+
DidChangeConfigurationNotification,
|
|
7
|
+
TextDocumentSyncKind,
|
|
8
|
+
} from "vscode-languageserver";
|
|
9
|
+
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
10
|
+
import { PlayerLanguageService } from "@player-lang/json-language-service";
|
|
11
|
+
import fs from "fs";
|
|
12
|
+
import { runAndCatch } from "./utils";
|
|
13
|
+
|
|
14
|
+
export * from "./utils";
|
|
15
|
+
|
|
16
|
+
const dateFormat = new Intl.DateTimeFormat("en", {
|
|
17
|
+
year: "numeric",
|
|
18
|
+
month: "2-digit",
|
|
19
|
+
day: "2-digit",
|
|
20
|
+
hour12: false,
|
|
21
|
+
hour: "2-digit",
|
|
22
|
+
minute: "2-digit",
|
|
23
|
+
second: "2-digit",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const logFilePath =
|
|
27
|
+
process.argv.length === 4 &&
|
|
28
|
+
fs.existsSync(process.argv[3]) &&
|
|
29
|
+
process.argv[3];
|
|
30
|
+
|
|
31
|
+
/** Format a log message to work in the console */
|
|
32
|
+
const formatLog = (a: unknown): string => {
|
|
33
|
+
const msg = typeof a === "string" ? a : JSON.stringify(a);
|
|
34
|
+
const date = new Date();
|
|
35
|
+
return `${dateFormat.format(date)},$${date.getMilliseconds()} | ${msg} \n`;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const fileLog = logFilePath
|
|
39
|
+
? (a: unknown) =>
|
|
40
|
+
fs.appendFile(logFilePath, formatLog(a), () => {
|
|
41
|
+
/* do nothing */
|
|
42
|
+
})
|
|
43
|
+
: () => {
|
|
44
|
+
/* do nothing */
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const service = new PlayerLanguageService();
|
|
48
|
+
|
|
49
|
+
const connection = createConnection(ProposedFeatures.all);
|
|
50
|
+
const documents = new TextDocuments(TextDocument);
|
|
51
|
+
|
|
52
|
+
let hasConfigurationCapability = false;
|
|
53
|
+
|
|
54
|
+
process.on("unhandledRejection", (e: Error) => {
|
|
55
|
+
console.error(e.message);
|
|
56
|
+
});
|
|
57
|
+
process.on("uncaughtException", (e: Error) => {
|
|
58
|
+
console.error(e.message);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
console.log = (a: Error) => {
|
|
62
|
+
fileLog(a);
|
|
63
|
+
connection.console.log(JSON.stringify(a, null, 2));
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
console.error = (a: Error) => {
|
|
67
|
+
fileLog(a);
|
|
68
|
+
connection.console.error(JSON.stringify(a, null, 2));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** Handle validating a text-document and returning the response back to the extension */
|
|
72
|
+
async function validate(textDocument: TextDocument): Promise<void> {
|
|
73
|
+
const diagnostics = await service.validateTextDocument(textDocument);
|
|
74
|
+
|
|
75
|
+
if (diagnostics) {
|
|
76
|
+
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
connection.onInitialize((params: InitializeParams) => {
|
|
81
|
+
const { capabilities } = params;
|
|
82
|
+
|
|
83
|
+
// Does the client support the `workspace/configuration` request?
|
|
84
|
+
// If not, we will fall back using global settings
|
|
85
|
+
hasConfigurationCapability = Boolean(
|
|
86
|
+
capabilities.workspace && Boolean(capabilities.workspace.configuration),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
fileLog("Initialized Player LSP Server");
|
|
90
|
+
return {
|
|
91
|
+
capabilities: {
|
|
92
|
+
textDocumentSync: TextDocumentSyncKind.Full,
|
|
93
|
+
codeActionProvider: true,
|
|
94
|
+
definitionProvider: true,
|
|
95
|
+
completionProvider: {
|
|
96
|
+
resolveProvider: false,
|
|
97
|
+
triggerCharacters: ['"', ":"],
|
|
98
|
+
},
|
|
99
|
+
documentFormattingProvider: true,
|
|
100
|
+
documentRangeFormattingProvider: true,
|
|
101
|
+
hoverProvider: true,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
connection.onCompletion(async (textDocumentPosition, token) => {
|
|
107
|
+
return runAndCatch(
|
|
108
|
+
() => {
|
|
109
|
+
const document = documents.get(textDocumentPosition.textDocument.uri);
|
|
110
|
+
if (document !== undefined) {
|
|
111
|
+
return service.getCompletionsAtPosition(
|
|
112
|
+
document,
|
|
113
|
+
textDocumentPosition.position,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return null;
|
|
118
|
+
},
|
|
119
|
+
token,
|
|
120
|
+
null,
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
connection.onHover(async (hoverParams, token) => {
|
|
125
|
+
return runAndCatch(
|
|
126
|
+
() => {
|
|
127
|
+
const document = documents.get(hoverParams.textDocument.uri);
|
|
128
|
+
if (document !== undefined) {
|
|
129
|
+
return service.getHoverInfoAtPosition(document, hoverParams.position);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return null;
|
|
133
|
+
},
|
|
134
|
+
token,
|
|
135
|
+
null,
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
connection.onCompletionResolve((item, token) =>
|
|
140
|
+
runAndCatch(() => service.resolveCompletionItem(item), token, item),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
connection.onDocumentFormatting((formattingParams, token) =>
|
|
144
|
+
runAndCatch(
|
|
145
|
+
() => {
|
|
146
|
+
const document = documents.get(formattingParams.textDocument.uri);
|
|
147
|
+
|
|
148
|
+
if (document !== undefined) {
|
|
149
|
+
return service.formatTextDocument(document, formattingParams.options);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return undefined;
|
|
153
|
+
},
|
|
154
|
+
token,
|
|
155
|
+
null,
|
|
156
|
+
),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
connection.onDocumentRangeFormatting((formattingParams, token) =>
|
|
160
|
+
runAndCatch(
|
|
161
|
+
() => {
|
|
162
|
+
const document = documents.get(formattingParams.textDocument.uri);
|
|
163
|
+
|
|
164
|
+
if (document !== undefined) {
|
|
165
|
+
return service.formatTextDocument(
|
|
166
|
+
document,
|
|
167
|
+
formattingParams.options,
|
|
168
|
+
formattingParams.range,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return undefined;
|
|
173
|
+
},
|
|
174
|
+
token,
|
|
175
|
+
null,
|
|
176
|
+
),
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
connection.onDefinition((definitionParams, token) =>
|
|
180
|
+
runAndCatch(
|
|
181
|
+
() => {
|
|
182
|
+
const document = documents.get(definitionParams.textDocument.uri);
|
|
183
|
+
|
|
184
|
+
if (document !== undefined) {
|
|
185
|
+
return service.getDefinitionAtPosition(
|
|
186
|
+
document,
|
|
187
|
+
definitionParams.position,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return undefined;
|
|
192
|
+
},
|
|
193
|
+
token,
|
|
194
|
+
null,
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
connection.onInitialized(() => {
|
|
199
|
+
if (hasConfigurationCapability) {
|
|
200
|
+
// Register for all configuration changes.
|
|
201
|
+
connection.client.register(
|
|
202
|
+
DidChangeConfigurationNotification.type,
|
|
203
|
+
undefined,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
connection.onCodeAction((codeAction) => {
|
|
209
|
+
const document = documents.get(codeAction.textDocument.uri);
|
|
210
|
+
if (!document) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return service.getCodeActionsInRange(document, codeAction.context);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
documents.onDidClose((change) => {
|
|
218
|
+
service.onClose(change.document);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
documents.onDidChangeContent((change) => {
|
|
222
|
+
validate(change.document);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
connection.onNotification(
|
|
226
|
+
"player/setAssetBundles",
|
|
227
|
+
(assetBundles: Array<string>) => {
|
|
228
|
+
// Don't trust data over the wire
|
|
229
|
+
if (Array.isArray(assetBundles)) {
|
|
230
|
+
console.log("Updating asset type bundles");
|
|
231
|
+
service.setAssetTypes(assetBundles);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
fileLog("Starting Player LSP Server");
|
|
237
|
+
|
|
238
|
+
documents.listen(connection);
|
|
239
|
+
connection.listen();
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CancellationToken } from "vscode-languageserver";
|
|
2
|
+
import { ResponseError } from "vscode-languageserver";
|
|
3
|
+
|
|
4
|
+
/** Get a cancellation error */
|
|
5
|
+
function cancel() {
|
|
6
|
+
return new ResponseError(
|
|
7
|
+
-32800 /* ErrorCodes.RequestCancelled */,
|
|
8
|
+
"Request cancelled",
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Run the given function and handle being cancelled */
|
|
13
|
+
export async function runAndCatch<T>(
|
|
14
|
+
func: () => Promise<T> | T,
|
|
15
|
+
token: CancellationToken,
|
|
16
|
+
errorVal: T,
|
|
17
|
+
): Promise<T | ResponseError<any>> {
|
|
18
|
+
if (token.isCancellationRequested) {
|
|
19
|
+
return cancel();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const result = await func();
|
|
24
|
+
if (token.isCancellationRequested) {
|
|
25
|
+
return cancel();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return result;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return errorVal;
|
|
31
|
+
}
|
|
32
|
+
}
|
package/types/index.d.ts
ADDED
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CancellationToken } from "vscode-languageserver";
|
|
2
|
+
import { ResponseError } from "vscode-languageserver";
|
|
3
|
+
/** Run the given function and handle being cancelled */
|
|
4
|
+
export declare function runAndCatch<T>(func: () => Promise<T> | T, token: CancellationToken, errorVal: T): Promise<T | ResponseError<any>>;
|
|
5
|
+
//# sourceMappingURL=utils.d.ts.map
|