@webgal/language-server 0.0.2-alpha.0 → 0.0.2-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/browser.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  require('./providerState-B7hGbqQj.cjs');
3
3
  const require_utils = require('./utils.cjs');
4
- const require_onInitialize = require('./onInitialize-Czud2_xG.cjs');
4
+ const require_onInitialize = require('./onInitialize-uaxhCEGr.cjs');
5
5
  let _volar_language_server_browser = require("@volar/language-server/browser");
6
6
 
7
7
  //#region src/browser.ts
@@ -11,16 +11,26 @@ function startServer(connection) {
11
11
  const documents = server.documents;
12
12
  require_utils.bindCoreFileAccessorToClientVfs(connection);
13
13
  server.fileSystem.install("file", require_utils.createClientVfsFileSystem(connection));
14
- const webgalLanguagePlugin = { getLanguageId(scriptId) {
15
- const path = scriptId.path.toLowerCase();
16
- if (scriptId.scheme !== "file") {
17
- if (path.endsWith("/game/config.txt") || path.endsWith("config.txt")) return "webgal-config";
18
- if (path.endsWith(".txt")) return "webgal";
19
- return "webgal";
14
+ const webgalLanguagePlugin = {
15
+ getLanguageId(scriptId) {
16
+ const path = scriptId.path.toLowerCase();
17
+ if (scriptId.scheme !== "file") {
18
+ if (path.endsWith("/game/config.txt") || path.endsWith("config.txt")) return "webgal-config";
19
+ if (path.endsWith(".txt")) return "webgal";
20
+ return "webgal";
21
+ }
22
+ if (path.endsWith("/game/config.txt")) return "webgal-config";
23
+ if (path.endsWith(".txt") && path.includes("/game/scene/")) return "webgal";
24
+ },
25
+ createVirtualCode(scriptId, languageId, snapshot) {
26
+ if (languageId !== "webgal" && languageId !== "webgal-config") return;
27
+ return require_utils.createWebgalVirtualCode(scriptId, languageId, snapshot);
28
+ },
29
+ updateVirtualCode(_scriptId, virtualCode, newSnapshot) {
30
+ if (virtualCode.languageId !== "webgal" && virtualCode.languageId !== "webgal-config") return;
31
+ return require_utils.updateWebgalVirtualCode(virtualCode, newSnapshot);
20
32
  }
21
- if (path.endsWith("/game/config.txt")) return "webgal-config";
22
- if (path.endsWith(".txt") && path.includes("/game/scene/")) return "webgal";
23
- } };
33
+ };
24
34
  connection.onInitialize((params) => {
25
35
  require_onInitialize.applyClientCapabilities(params);
26
36
  const result = server.initialize(params, (0, _volar_language_server_browser.createSimpleProject)([webgalLanguagePlugin]), [require_onInitialize.createWebgalService(connection)]);
@@ -28,8 +38,8 @@ function startServer(connection) {
28
38
  return result;
29
39
  });
30
40
  connection.onInitialized(() => {
31
- require_onInitialize.registerConnectionHandlers(documents, connection);
32
41
  server.initialized();
42
+ require_onInitialize.registerConnectionHandlers(documents, connection);
33
43
  });
34
44
  connection.onShutdown(server.shutdown);
35
45
  connection.listen();
package/build/browser.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./providerState-CLCXHs37.mjs";
2
- import { bindCoreFileAccessorToClientVfs, createClientVfsFileSystem } from "./utils.mjs";
3
- import { i as registerConnectionHandlers, n as applyServerCapabilities, r as createWebgalService, t as applyClientCapabilities } from "./onInitialize-B6oAsPYj.mjs";
2
+ import { bindCoreFileAccessorToClientVfs, createClientVfsFileSystem, createWebgalVirtualCode, updateWebgalVirtualCode } from "./utils.mjs";
3
+ import { i as registerConnectionHandlers, n as applyServerCapabilities, r as createWebgalService, t as applyClientCapabilities } from "./onInitialize-DIUUrHI3.mjs";
4
4
  import { createConnection, createConnection as createConnection$1, createServer, createSimpleProject } from "@volar/language-server/browser";
5
5
 
6
6
  //#region src/browser.ts
@@ -10,16 +10,26 @@ function startServer(connection) {
10
10
  const documents = server.documents;
11
11
  bindCoreFileAccessorToClientVfs(connection);
12
12
  server.fileSystem.install("file", createClientVfsFileSystem(connection));
13
- const webgalLanguagePlugin = { getLanguageId(scriptId) {
14
- const path = scriptId.path.toLowerCase();
15
- if (scriptId.scheme !== "file") {
16
- if (path.endsWith("/game/config.txt") || path.endsWith("config.txt")) return "webgal-config";
17
- if (path.endsWith(".txt")) return "webgal";
18
- return "webgal";
13
+ const webgalLanguagePlugin = {
14
+ getLanguageId(scriptId) {
15
+ const path = scriptId.path.toLowerCase();
16
+ if (scriptId.scheme !== "file") {
17
+ if (path.endsWith("/game/config.txt") || path.endsWith("config.txt")) return "webgal-config";
18
+ if (path.endsWith(".txt")) return "webgal";
19
+ return "webgal";
20
+ }
21
+ if (path.endsWith("/game/config.txt")) return "webgal-config";
22
+ if (path.endsWith(".txt") && path.includes("/game/scene/")) return "webgal";
23
+ },
24
+ createVirtualCode(scriptId, languageId, snapshot) {
25
+ if (languageId !== "webgal" && languageId !== "webgal-config") return;
26
+ return createWebgalVirtualCode(scriptId, languageId, snapshot);
27
+ },
28
+ updateVirtualCode(_scriptId, virtualCode, newSnapshot) {
29
+ if (virtualCode.languageId !== "webgal" && virtualCode.languageId !== "webgal-config") return;
30
+ return updateWebgalVirtualCode(virtualCode, newSnapshot);
19
31
  }
20
- if (path.endsWith("/game/config.txt")) return "webgal-config";
21
- if (path.endsWith(".txt") && path.includes("/game/scene/")) return "webgal";
22
- } };
32
+ };
23
33
  connection.onInitialize((params) => {
24
34
  applyClientCapabilities(params);
25
35
  const result = server.initialize(params, createSimpleProject([webgalLanguagePlugin]), [createWebgalService(connection)]);
@@ -27,8 +37,8 @@ function startServer(connection) {
27
37
  return result;
28
38
  });
29
39
  connection.onInitialized(() => {
30
- registerConnectionHandlers(documents, connection);
31
40
  server.initialized();
41
+ registerConnectionHandlers(documents, connection);
32
42
  });
33
43
  connection.onShutdown(server.shutdown);
34
44
  connection.listen();
package/build/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  require('./providerState-B7hGbqQj.cjs');
2
2
  const require_utils = require('./utils.cjs');
3
- const require_onInitialize = require('./onInitialize-Czud2_xG.cjs');
3
+ const require_onInitialize = require('./onInitialize-uaxhCEGr.cjs');
4
4
  let _volar_language_server_node = require("@volar/language-server/node");
5
5
  let vscode_languageserver_node = require("vscode-languageserver/node");
6
6
 
@@ -47,16 +47,26 @@ function startServer(connection, useClientVfs) {
47
47
  if (useClientVfs) server.fileSystem.install("file", require_utils.createClientVfsFileSystem(connection));
48
48
  connection.onInitialize((params) => {
49
49
  require_onInitialize.applyClientCapabilities(params);
50
- const result = server.initialize(params, (0, _volar_language_server_node.createSimpleProject)([{ getLanguageId(scriptId) {
51
- const path = scriptId.path.toLowerCase();
52
- if (scriptId.scheme !== "file") {
53
- if (path.endsWith("/game/config.txt") || path.endsWith("config.txt")) return "webgal-config";
54
- if (path.endsWith(".txt")) return "webgal";
55
- return "webgal";
50
+ const result = server.initialize(params, (0, _volar_language_server_node.createSimpleProject)([{
51
+ getLanguageId(scriptId) {
52
+ const path = scriptId.path.toLowerCase();
53
+ if (scriptId.scheme !== "file") {
54
+ if (path.endsWith("/game/config.txt") || path.endsWith("config.txt")) return "webgal-config";
55
+ if (path.endsWith(".txt")) return "webgal";
56
+ return "webgal";
57
+ }
58
+ if (path.endsWith("/game/config.txt")) return "webgal-config";
59
+ if (path.endsWith(".txt") && path.includes("/game/scene/")) return "webgal";
60
+ },
61
+ createVirtualCode(scriptId, languageId, snapshot) {
62
+ if (languageId !== "webgal" && languageId !== "webgal-config") return;
63
+ return require_utils.createWebgalVirtualCode(scriptId, languageId, snapshot);
64
+ },
65
+ updateVirtualCode(_scriptId, virtualCode, newSnapshot) {
66
+ if (virtualCode.languageId !== "webgal" && virtualCode.languageId !== "webgal-config") return;
67
+ return require_utils.updateWebgalVirtualCode(virtualCode, newSnapshot);
56
68
  }
57
- if (path.endsWith("/game/config.txt")) return "webgal-config";
58
- if (path.endsWith(".txt") && path.includes("/game/scene/")) return "webgal";
59
- } }]), [require_onInitialize.createWebgalService(connection)]);
69
+ }]), [require_onInitialize.createWebgalService(connection)]);
60
70
  require_onInitialize.applyServerCapabilities(result);
61
71
  return result;
62
72
  });
package/build/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./providerState-CLCXHs37.mjs";
2
- import { bindCoreFileAccessorToClientVfs, createClientVfsFileSystem } from "./utils.mjs";
3
- import { i as registerConnectionHandlers, n as applyServerCapabilities, r as createWebgalService, t as applyClientCapabilities } from "./onInitialize-B6oAsPYj.mjs";
2
+ import { bindCoreFileAccessorToClientVfs, createClientVfsFileSystem, createWebgalVirtualCode, updateWebgalVirtualCode } from "./utils.mjs";
3
+ import { i as registerConnectionHandlers, n as applyServerCapabilities, r as createWebgalService, t as applyClientCapabilities } from "./onInitialize-DIUUrHI3.mjs";
4
4
  import { createConnection, createServer, createSimpleProject } from "@volar/language-server/node";
5
5
  import { createConnection as createConnection$1 } from "vscode-languageserver/node";
6
6
 
@@ -47,16 +47,26 @@ function startServer(connection, useClientVfs) {
47
47
  if (useClientVfs) server.fileSystem.install("file", createClientVfsFileSystem(connection));
48
48
  connection.onInitialize((params) => {
49
49
  applyClientCapabilities(params);
50
- const result = server.initialize(params, createSimpleProject([{ getLanguageId(scriptId) {
51
- const path = scriptId.path.toLowerCase();
52
- if (scriptId.scheme !== "file") {
53
- if (path.endsWith("/game/config.txt") || path.endsWith("config.txt")) return "webgal-config";
54
- if (path.endsWith(".txt")) return "webgal";
55
- return "webgal";
50
+ const result = server.initialize(params, createSimpleProject([{
51
+ getLanguageId(scriptId) {
52
+ const path = scriptId.path.toLowerCase();
53
+ if (scriptId.scheme !== "file") {
54
+ if (path.endsWith("/game/config.txt") || path.endsWith("config.txt")) return "webgal-config";
55
+ if (path.endsWith(".txt")) return "webgal";
56
+ return "webgal";
57
+ }
58
+ if (path.endsWith("/game/config.txt")) return "webgal-config";
59
+ if (path.endsWith(".txt") && path.includes("/game/scene/")) return "webgal";
60
+ },
61
+ createVirtualCode(scriptId, languageId, snapshot) {
62
+ if (languageId !== "webgal" && languageId !== "webgal-config") return;
63
+ return createWebgalVirtualCode(scriptId, languageId, snapshot);
64
+ },
65
+ updateVirtualCode(_scriptId, virtualCode, newSnapshot) {
66
+ if (virtualCode.languageId !== "webgal" && virtualCode.languageId !== "webgal-config") return;
67
+ return updateWebgalVirtualCode(virtualCode, newSnapshot);
56
68
  }
57
- if (path.endsWith("/game/config.txt")) return "webgal-config";
58
- if (path.endsWith(".txt") && path.includes("/game/scene/")) return "webgal";
59
- } }]), [createWebgalService(connection)]);
69
+ }]), [createWebgalService(connection)]);
60
70
  applyServerCapabilities(result);
61
71
  return result;
62
72
  });
@@ -1,6 +1,5 @@
1
- import { StateConfig, defaultSettings, documentSettings, findTokenRange, getPatternAtPosition, getStageCompletionContext, getWordAtPosition, setGlobalSettings, updateGlobalMap, validateTextDocument } from "./utils.mjs";
2
- import { GlobalMap } from "@webgal/language-core";
3
- import { CompletionItemKind, DidChangeConfigurationNotification, FoldingRangeKind, InsertTextFormat, LocationLink, MarkupKind, Position, Range, TextDocumentSyncKind } from "@volar/language-server";
1
+ import { StateConfig, defaultSettings, documentSettings, findTokenRange, getPatternAtPosition, getStageCompletionContext, getWebgalDefinitionMap, getWebgalDocumentLinkCandidates, getWebgalFoldingRanges, getWebgalLineCommandTypes, getWebgalSourceUriString, getWebgalVirtualCodeLines, getWebgalVirtualCodeText, getWordAtPosition, setGlobalSettings, validateTextDocument } from "./utils.mjs";
2
+ import { CompletionItemKind, DidChangeConfigurationNotification, InsertTextFormat, LocationLink, MarkupKind, Position, Range, TextDocumentSyncKind } from "@volar/language-server";
4
3
 
5
4
  //#region src/events/onDid.ts
6
5
  var onDid_default = function(documents, connection) {
@@ -1172,9 +1171,9 @@ function getTypeDirectory(command, fileName) {
1172
1171
 
1173
1172
  //#endregion
1174
1173
  //#region src/events/onCompletion.ts
1175
- async function provideCompletionItems(document, position, connection) {
1176
- const file_name = document.uri;
1177
- const documentTextArray = document.getText().split("\n");
1174
+ async function provideCompletionItems(document, position, connection, definitionMap, lines, lineCommandTypes, sourceUri) {
1175
+ const file_name = sourceUri;
1176
+ const documentTextArray = lines;
1178
1177
  const { token } = findTokenRange(document, position);
1179
1178
  const CompletionItemSuggestions = [];
1180
1179
  if (file_name.endsWith("/game/config.txt")) {
@@ -1226,8 +1225,8 @@ async function provideCompletionItems(document, position, connection) {
1226
1225
  return CompletionItemSuggestions;
1227
1226
  }
1228
1227
  const wordMeta = getWordAtPosition(document, Position.create(position.line, 0));
1229
- const currentLine = documentTextArray[position.line];
1230
- const commandType = currentLine.substring(0, currentLine.indexOf(":") !== -1 ? currentLine.indexOf(":") : currentLine.indexOf(";"));
1228
+ const currentLine = documentTextArray[position.line] ?? "";
1229
+ const commandType = lineCommandTypes[position.line] ?? "";
1231
1230
  const isSayCommandType = !resourcesMap[commandType];
1232
1231
  if (token.startsWith("./") || !!~token.indexOf("/") || Object.keys(resourcesMap).includes(commandType) || token.startsWith("-")) {
1233
1232
  const resourceBaseDir = isSayCommandType ? "vocal" : resourcesMap[commandType];
@@ -1252,10 +1251,9 @@ async function provideCompletionItems(document, position, connection) {
1252
1251
  return CompletionItemSuggestions;
1253
1252
  }
1254
1253
  if (token) {
1255
- updateGlobalMap(documentTextArray);
1256
- const currentPool = GlobalMap.setVar;
1254
+ const currentPool = definitionMap.setVar;
1257
1255
  for (const key in currentPool) if (key.includes(token)) {
1258
- const latest = GlobalMap.setVar[key][GlobalMap.setVar[key].length - 1];
1256
+ const latest = definitionMap.setVar[key][definitionMap.setVar[key].length - 1];
1259
1257
  CompletionItemSuggestions.push({
1260
1258
  label: key,
1261
1259
  kind: CompletionItemKind.Variable,
@@ -1276,89 +1274,59 @@ async function provideCompletionItems(document, position, connection) {
1276
1274
 
1277
1275
  //#endregion
1278
1276
  //#region src/events/onDefinition.ts
1279
- function provideDefinition(document, position) {
1277
+ function provideDefinition(document, position, definitionMap) {
1280
1278
  const text = document.getText();
1281
1279
  const findWord = getWordAtPosition(document, position);
1282
1280
  const definitionLinks = [];
1283
1281
  if (!findWord) return definitionLinks;
1284
- const documentTextArray = text.split("\n");
1285
- const currentLine = documentTextArray[position.line];
1282
+ const currentLine = text.split("\n")[position.line];
1286
1283
  const commandType = currentLine.substring(0, currentLine.indexOf(":") !== -1 ? currentLine.indexOf(":") : currentLine.indexOf(";"));
1287
- updateGlobalMap(documentTextArray);
1288
- const jumpLabelMap = GlobalMap.label;
1289
- const setVarMap = GlobalMap.setVar;
1284
+ const jumpLabelMap = definitionMap.label;
1285
+ const setVarMap = definitionMap.setVar;
1290
1286
  const targetPool = ["jumpLabel", "choose"].includes(commandType) ? jumpLabelMap : setVarMap;
1291
1287
  if (!targetPool) return definitionLinks;
1292
1288
  const targetPoolArray = targetPool[findWord.word];
1293
1289
  if (!targetPoolArray) return definitionLinks;
1294
- for (const current of targetPoolArray) if (current.word === findWord.word) definitionLinks.push(LocationLink.create(document.uri, Range.create(Position.create(position.line, findWord.start), Position.create(position.line, findWord.end)), Range.create(current.position, current.position), Range.create(Position.create(0, 0), Position.create(0, 0))));
1290
+ for (const current of targetPoolArray) if (current.word === findWord.word && current.position) definitionLinks.push(LocationLink.create(document.uri, Range.create(Position.create(position.line, findWord.start), Position.create(position.line, findWord.end)), Range.create(Position.create(current.position.line, current.position.character), Position.create(current.position.line, current.position.character)), Range.create(Position.create(0, 0), Position.create(0, 0))));
1295
1291
  return definitionLinks;
1296
1292
  }
1297
1293
 
1298
1294
  //#endregion
1299
1295
  //#region src/events/onDocumentLinks.ts
1300
- async function provideDocumentLinks(document, connection) {
1301
- const documentTextArray = document.getText().split("\n");
1296
+ async function provideDocumentLinks(document, connection, candidates) {
1302
1297
  const pathArray = document.uri.split("/");
1303
1298
  const currentDirectory = await connection.sendRequest("client/currentDirectory");
1304
1299
  const documentLinks = [];
1305
- for (let i = 0; i < documentTextArray.length; i++) {
1306
- const currentLine = documentTextArray[i];
1307
- let startText = currentLine.substring(0, currentLine.indexOf(":") !== -1 ? currentLine.indexOf(":") : currentLine.indexOf(";"));
1308
- startText = startText.startsWith(";") ? startText.substring(1) : startText;
1309
- let match;
1310
- const regex = /\$?\{?(\w+)\.(\w+)\}?/g;
1311
- while (match = regex.exec(currentLine)) {
1312
- if (match[0].startsWith("$")) continue;
1313
- const matchText = match[0];
1314
- const pathName = pathArray[pathArray.length - 3 > 0 ? pathArray.length - 3 : pathArray.length - 2];
1315
- const isConfig = pathArray[pathArray.length - 1] === "config.txt" && pathArray[pathArray.length - 2] === "game" && pathName === pathArray[pathArray.length - 3];
1316
- const dirResources = getTypeDirectory(match.input.substring(0, match.input.indexOf(":")), matchText);
1317
- let targetPath;
1318
- if (isConfig) targetPath = await connection.sendRequest("client/FJoin", currentDirectory + "/");
1319
- else targetPath = await connection.sendRequest("client/FJoin", currentDirectory + "/" + dirResources);
1320
- let basePath = await connection.sendRequest("client/FJoin", targetPath + "/" + matchText);
1321
- if (!await connection.sendRequest("client/FStat", basePath)) basePath = await connection.sendRequest("client/findFile", [currentDirectory, matchText]);
1322
- documentLinks.push({
1323
- target: "file:///" + basePath,
1324
- range: Range.create(Position.create(i, match.index), Position.create(i, match.index + matchText.length)),
1325
- tooltip: basePath
1326
- });
1327
- if (regex.lastIndex === match.index) regex.lastIndex++;
1328
- }
1300
+ const pathName = pathArray[pathArray.length - 3 > 0 ? pathArray.length - 3 : pathArray.length - 2];
1301
+ const isConfig = pathArray[pathArray.length - 1] === "config.txt" && pathArray[pathArray.length - 2] === "game" && pathName === pathArray[pathArray.length - 3];
1302
+ for (const candidate of candidates) {
1303
+ const matchText = candidate.text;
1304
+ const dirResources = getTypeDirectory(candidate.command, matchText);
1305
+ let targetPath;
1306
+ if (isConfig) targetPath = await connection.sendRequest("client/FJoin", currentDirectory + "/");
1307
+ else targetPath = await connection.sendRequest("client/FJoin", currentDirectory + "/" + dirResources);
1308
+ let basePath = await connection.sendRequest("client/FJoin", targetPath + "/" + matchText);
1309
+ if (!await connection.sendRequest("client/FStat", basePath)) basePath = await connection.sendRequest("client/findFile", [currentDirectory, matchText]);
1310
+ documentLinks.push({
1311
+ target: "file:///" + basePath,
1312
+ range: Range.create(Position.create(candidate.line, candidate.start), Position.create(candidate.line, candidate.end)),
1313
+ tooltip: basePath
1314
+ });
1329
1315
  }
1330
1316
  return [...documentLinks];
1331
1317
  }
1332
1318
 
1333
1319
  //#endregion
1334
1320
  //#region src/events/onFoldingRanges.ts
1335
- function provideFoldingRanges(doc) {
1336
- const docText = doc.getText();
1337
- const foldingRanges = [];
1338
- const regex = /label:([\s\S]*?)(?=(?:\r?\n|^)end|(?:\r?\n|^)label:|$)/g;
1339
- let match;
1340
- while (match = regex.exec(docText)) if (match !== null) {
1341
- const startLine = doc.positionAt(match.index).line;
1342
- const endPos = doc.positionAt(match.index + match[0].length);
1343
- let endLine = endPos.line;
1344
- if (endPos.character === 0) endLine = endPos.line - 1;
1345
- if (endLine > startLine) foldingRanges.push({
1346
- startLine,
1347
- endLine,
1348
- collapsedText: match[1].split("\n")[0].replace(/;/g, "").trim() || "...",
1349
- kind: FoldingRangeKind.Region
1350
- });
1351
- }
1352
- return foldingRanges;
1321
+ function provideFoldingRanges(_doc, ranges) {
1322
+ return ranges;
1353
1323
  }
1354
1324
 
1355
1325
  //#endregion
1356
1326
  //#region src/events/onHover.ts
1357
- async function provideHover(document, position, connection) {
1358
- const file_name = document.uri;
1359
- const documentTextArray = document.getText().split("\n");
1360
- const currentLine = documentTextArray[position.line];
1361
- const commandType = currentLine.substring(0, currentLine.indexOf(":") !== -1 ? currentLine.indexOf(":") : currentLine.indexOf(";"));
1327
+ async function provideHover(document, position, connection, definitionMap, lineCommandTypes, sourceUri) {
1328
+ const file_name = sourceUri;
1329
+ const commandType = lineCommandTypes[position.line] ?? "";
1362
1330
  let findWordWithPattern = getPatternAtPosition(document, position, /\{([^}]*)\}/);
1363
1331
  findWordWithPattern = getPatternAtPosition(document, position, /(?<=-)[\w]+/);
1364
1332
  if (findWordWithPattern) {
@@ -1414,9 +1382,8 @@ async function provideHover(document, position, connection) {
1414
1382
  ].join("\n\n")
1415
1383
  } };
1416
1384
  }
1417
- updateGlobalMap(documentTextArray);
1418
1385
  if (findWord && `{${findWord.word}}` !== "{}") {
1419
- const current = GlobalMap.setVar[findWord.word];
1386
+ const current = definitionMap.setVar[findWord.word];
1420
1387
  if (!current || current.length <= 0) return { contents: [] };
1421
1388
  const currentVariable = current[current.length - 1];
1422
1389
  const hoverContent = [`### ${findWord.word}`];
@@ -1426,8 +1393,11 @@ async function provideHover(document, position, connection) {
1426
1393
  hoverContent.push(currentVariable.desc);
1427
1394
  }
1428
1395
  hoverContent.push("<hr>");
1429
- if (findWord.word in GlobalMap.setVar) {
1430
- hoverContent.push(`Position: ${currentVariable.position?.line + 1},${currentVariable.position?.character + 1}`);
1396
+ if (findWord.word in definitionMap.setVar) {
1397
+ const positionValue = currentVariable.position;
1398
+ const line = positionValue && typeof positionValue.line === "number" ? positionValue.line : -1;
1399
+ const character = positionValue && typeof positionValue.character === "number" ? positionValue.character : -1;
1400
+ hoverContent.push(`Position: ${line + 1},${character + 1}`);
1431
1401
  hoverContent.push("```webgal");
1432
1402
  hoverContent.push(`${currentVariable.input?.replace(/\t\r\n/g, "")}\n\n\`\`\``);
1433
1403
  }
@@ -1441,8 +1411,8 @@ async function provideHover(document, position, connection) {
1441
1411
 
1442
1412
  //#endregion
1443
1413
  //#region src/events/onDiagnostics.ts
1444
- async function provideDiagnostics(document, connection) {
1445
- return validateTextDocument(connection, document);
1414
+ async function provideDiagnostics(document, connection, text) {
1415
+ return validateTextDocument(connection, document, text);
1446
1416
  }
1447
1417
 
1448
1418
  //#endregion
@@ -1470,28 +1440,35 @@ function createWebgalService(connection) {
1470
1440
  foldingRangeProvider: true,
1471
1441
  definitionProvider: true
1472
1442
  },
1473
- create() {
1443
+ create(context) {
1444
+ const getDefinitionMap = (document) => getWebgalDefinitionMap(context, document);
1445
+ const getVirtualCodeText = (document) => getWebgalVirtualCodeText(context, document);
1446
+ const getVirtualCodeLines = (document) => getWebgalVirtualCodeLines(context, document);
1447
+ const getLineCommandTypes = (document) => getWebgalLineCommandTypes(context, document);
1448
+ const getSourceUriString = (document) => getWebgalSourceUriString(context, document);
1449
+ const getDocumentLinkCandidates = (document) => getWebgalDocumentLinkCandidates(context, document);
1450
+ const getFoldingRanges = (document) => getWebgalFoldingRanges(context, document);
1474
1451
  return {
1475
1452
  async provideCompletionItems(document, position, _context, _token) {
1476
1453
  return {
1477
1454
  isIncomplete: false,
1478
- items: await provideCompletionItems(document, position, connection)
1455
+ items: await provideCompletionItems(document, position, connection, getDefinitionMap(document), getVirtualCodeLines(document), getLineCommandTypes(document), getSourceUriString(document))
1479
1456
  };
1480
1457
  },
1481
1458
  async provideHover(document, position, _token) {
1482
- return provideHover(document, position, connection);
1459
+ return provideHover(document, position, connection, getDefinitionMap(document), getLineCommandTypes(document), getSourceUriString(document));
1483
1460
  },
1484
1461
  provideDefinition(document, position, _token) {
1485
- return provideDefinition(document, position);
1462
+ return provideDefinition(document, position, getDefinitionMap(document));
1486
1463
  },
1487
1464
  async provideDocumentLinks(document, _token) {
1488
- return provideDocumentLinks(document, connection);
1465
+ return provideDocumentLinks(document, connection, getDocumentLinkCandidates(document));
1489
1466
  },
1490
1467
  provideFoldingRanges(document, _token) {
1491
- return provideFoldingRanges(document);
1468
+ return provideFoldingRanges(document, getFoldingRanges(document));
1492
1469
  },
1493
1470
  async provideDiagnostics(document, _token) {
1494
- return provideDiagnostics(document, connection);
1471
+ return provideDiagnostics(document, connection, getVirtualCodeText(document));
1495
1472
  }
1496
1473
  };
1497
1474
  }