runescript-lsp 0.0.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.
Files changed (192) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/cache/CompletionCache.d.ts +15 -0
  4. package/dist/cache/CompletionCache.js +58 -0
  5. package/dist/cache/CompletionCache.js.map +1 -0
  6. package/dist/cache/FileCache.d.ts +25 -0
  7. package/dist/cache/FileCache.js +101 -0
  8. package/dist/cache/FileCache.js.map +1 -0
  9. package/dist/cache/IdCache.d.ts +28 -0
  10. package/dist/cache/IdCache.js +47 -0
  11. package/dist/cache/IdCache.js.map +1 -0
  12. package/dist/cache/SymbolCache.d.ts +76 -0
  13. package/dist/cache/SymbolCache.js +205 -0
  14. package/dist/cache/SymbolCache.js.map +1 -0
  15. package/dist/cache/Trie.d.ts +22 -0
  16. package/dist/cache/Trie.js +122 -0
  17. package/dist/cache/Trie.js.map +1 -0
  18. package/dist/cache/WorkspaceCache.d.ts +32 -0
  19. package/dist/cache/WorkspaceCache.js +60 -0
  20. package/dist/cache/WorkspaceCache.js.map +1 -0
  21. package/dist/cache/cacheManager.d.ts +16 -0
  22. package/dist/cache/cacheManager.js +47 -0
  23. package/dist/cache/cacheManager.js.map +1 -0
  24. package/dist/handler/colorProvider.d.ts +2 -0
  25. package/dist/handler/colorProvider.js +103 -0
  26. package/dist/handler/colorProvider.js.map +1 -0
  27. package/dist/handler/commands.d.ts +6 -0
  28. package/dist/handler/commands.js +25 -0
  29. package/dist/handler/commands.js.map +1 -0
  30. package/dist/handler/completion.d.ts +3 -0
  31. package/dist/handler/completion.js +25 -0
  32. package/dist/handler/completion.js.map +1 -0
  33. package/dist/handler/definition.d.ts +2 -0
  34. package/dist/handler/definition.js +20 -0
  35. package/dist/handler/definition.js.map +1 -0
  36. package/dist/handler/fileEvents.d.ts +3 -0
  37. package/dist/handler/fileEvents.js +107 -0
  38. package/dist/handler/fileEvents.js.map +1 -0
  39. package/dist/handler/gitEvents.d.ts +6 -0
  40. package/dist/handler/gitEvents.js +22 -0
  41. package/dist/handler/gitEvents.js.map +1 -0
  42. package/dist/handler/hover.d.ts +2 -0
  43. package/dist/handler/hover.js +125 -0
  44. package/dist/handler/hover.js.map +1 -0
  45. package/dist/handler/references.d.ts +2 -0
  46. package/dist/handler/references.js +33 -0
  47. package/dist/handler/references.js.map +1 -0
  48. package/dist/handler/rename.d.ts +2 -0
  49. package/dist/handler/rename.js +6 -0
  50. package/dist/handler/rename.js.map +1 -0
  51. package/dist/handler/semanticTokens.d.ts +4 -0
  52. package/dist/handler/semanticTokens.js +40 -0
  53. package/dist/handler/semanticTokens.js.map +1 -0
  54. package/dist/handler/settingsEvents.d.ts +2 -0
  55. package/dist/handler/settingsEvents.js +11 -0
  56. package/dist/handler/settingsEvents.js.map +1 -0
  57. package/dist/handler/signatureHelp.d.ts +2 -0
  58. package/dist/handler/signatureHelp.js +6 -0
  59. package/dist/handler/signatureHelp.js.map +1 -0
  60. package/dist/handler/workspaceEvents.d.ts +2 -0
  61. package/dist/handler/workspaceEvents.js +30 -0
  62. package/dist/handler/workspaceEvents.js.map +1 -0
  63. package/dist/manager.d.ts +6 -0
  64. package/dist/manager.js +126 -0
  65. package/dist/manager.js.map +1 -0
  66. package/dist/parser/configParser.d.ts +29 -0
  67. package/dist/parser/configParser.js +216 -0
  68. package/dist/parser/configParser.js.map +1 -0
  69. package/dist/parser/constantParser.d.ts +14 -0
  70. package/dist/parser/constantParser.js +40 -0
  71. package/dist/parser/constantParser.js.map +1 -0
  72. package/dist/parser/dbtableParser.d.ts +18 -0
  73. package/dist/parser/dbtableParser.js +114 -0
  74. package/dist/parser/dbtableParser.js.map +1 -0
  75. package/dist/parser/packParser.d.ts +11 -0
  76. package/dist/parser/packParser.js +13 -0
  77. package/dist/parser/packParser.js.map +1 -0
  78. package/dist/parser/parser.d.ts +44 -0
  79. package/dist/parser/parser.js +34 -0
  80. package/dist/parser/parser.js.map +1 -0
  81. package/dist/parser/runescriptParser.d.ts +13 -0
  82. package/dist/parser/runescriptParser.js +28 -0
  83. package/dist/parser/runescriptParser.js.map +1 -0
  84. package/dist/public/commands.d.ts +1 -0
  85. package/dist/public/commands.js +2 -0
  86. package/dist/public/commands.js.map +1 -0
  87. package/dist/public/settings.d.ts +2 -0
  88. package/dist/public/settings.js +2 -0
  89. package/dist/public/settings.js.map +1 -0
  90. package/dist/public/types.d.ts +2 -0
  91. package/dist/public/types.js +2 -0
  92. package/dist/public/types.js.map +1 -0
  93. package/dist/resolver/configResolver.d.ts +2 -0
  94. package/dist/resolver/configResolver.js +102 -0
  95. package/dist/resolver/configResolver.js.map +1 -0
  96. package/dist/resolver/constantResolver.d.ts +2 -0
  97. package/dist/resolver/constantResolver.js +37 -0
  98. package/dist/resolver/constantResolver.js.map +1 -0
  99. package/dist/resolver/dbtableResolver.d.ts +2 -0
  100. package/dist/resolver/dbtableResolver.js +28 -0
  101. package/dist/resolver/dbtableResolver.js.map +1 -0
  102. package/dist/resolver/packResolver.d.ts +2 -0
  103. package/dist/resolver/packResolver.js +32 -0
  104. package/dist/resolver/packResolver.js.map +1 -0
  105. package/dist/resolver/resolver.d.ts +15 -0
  106. package/dist/resolver/resolver.js +95 -0
  107. package/dist/resolver/resolver.js.map +1 -0
  108. package/dist/resolver/runescriptResolver.d.ts +2 -0
  109. package/dist/resolver/runescriptResolver.js +347 -0
  110. package/dist/resolver/runescriptResolver.js.map +1 -0
  111. package/dist/resource/configKeys.d.ts +21 -0
  112. package/dist/resource/configKeys.js +86 -0
  113. package/dist/resource/configKeys.js.map +1 -0
  114. package/dist/resource/enum/displayItems.d.ts +13 -0
  115. package/dist/resource/enum/displayItems.js +23 -0
  116. package/dist/resource/enum/displayItems.js.map +1 -0
  117. package/dist/resource/enum/fileTypes.d.ts +26 -0
  118. package/dist/resource/enum/fileTypes.js +28 -0
  119. package/dist/resource/enum/fileTypes.js.map +1 -0
  120. package/dist/resource/enum/languages.d.ts +25 -0
  121. package/dist/resource/enum/languages.js +27 -0
  122. package/dist/resource/enum/languages.js.map +1 -0
  123. package/dist/resource/enum/regex.d.ts +24 -0
  124. package/dist/resource/enum/regex.js +25 -0
  125. package/dist/resource/enum/regex.js.map +1 -0
  126. package/dist/resource/enum/semanticTokens.d.ts +24 -0
  127. package/dist/resource/enum/semanticTokens.js +26 -0
  128. package/dist/resource/enum/semanticTokens.js.map +1 -0
  129. package/dist/resource/enum/symbolTypes.d.ts +49 -0
  130. package/dist/resource/enum/symbolTypes.js +51 -0
  131. package/dist/resource/enum/symbolTypes.js.map +1 -0
  132. package/dist/resource/enum/types.d.ts +47 -0
  133. package/dist/resource/enum/types.js +49 -0
  134. package/dist/resource/enum/types.js.map +1 -0
  135. package/dist/resource/scriptTriggers.d.ts +8 -0
  136. package/dist/resource/scriptTriggers.js +72 -0
  137. package/dist/resource/scriptTriggers.js.map +1 -0
  138. package/dist/resource/symbolConfig.d.ts +10 -0
  139. package/dist/resource/symbolConfig.js +234 -0
  140. package/dist/resource/symbolConfig.js.map +1 -0
  141. package/dist/resource/symbolPostProcessors.d.ts +15 -0
  142. package/dist/resource/symbolPostProcessors.js +70 -0
  143. package/dist/resource/symbolPostProcessors.js.map +1 -0
  144. package/dist/server.d.ts +1 -0
  145. package/dist/server.js +110 -0
  146. package/dist/server.js.map +1 -0
  147. package/dist/types.d.ts +214 -0
  148. package/dist/types.js +6 -0
  149. package/dist/types.js.map +1 -0
  150. package/dist/utils/cacheUtils.d.ts +12 -0
  151. package/dist/utils/cacheUtils.js +26 -0
  152. package/dist/utils/cacheUtils.js.map +1 -0
  153. package/dist/utils/connectionUtils.d.ts +3 -0
  154. package/dist/utils/connectionUtils.js +8 -0
  155. package/dist/utils/connectionUtils.js.map +1 -0
  156. package/dist/utils/diagnosticsUtils.d.ts +4 -0
  157. package/dist/utils/diagnosticsUtils.js +11 -0
  158. package/dist/utils/diagnosticsUtils.js.map +1 -0
  159. package/dist/utils/documentUtils.d.ts +5 -0
  160. package/dist/utils/documentUtils.js +14 -0
  161. package/dist/utils/documentUtils.js.map +1 -0
  162. package/dist/utils/fileUtils.d.ts +42 -0
  163. package/dist/utils/fileUtils.js +82 -0
  164. package/dist/utils/fileUtils.js.map +1 -0
  165. package/dist/utils/handlerUtils.d.ts +1 -0
  166. package/dist/utils/handlerUtils.js +5 -0
  167. package/dist/utils/handlerUtils.js.map +1 -0
  168. package/dist/utils/highlightUtils.d.ts +7 -0
  169. package/dist/utils/highlightUtils.js +52 -0
  170. package/dist/utils/highlightUtils.js.map +1 -0
  171. package/dist/utils/initUtils.d.ts +3 -0
  172. package/dist/utils/initUtils.js +18 -0
  173. package/dist/utils/initUtils.js.map +1 -0
  174. package/dist/utils/logger.d.ts +11 -0
  175. package/dist/utils/logger.js +38 -0
  176. package/dist/utils/logger.js.map +1 -0
  177. package/dist/utils/progressUtils.d.ts +7 -0
  178. package/dist/utils/progressUtils.js +31 -0
  179. package/dist/utils/progressUtils.js.map +1 -0
  180. package/dist/utils/resolverUtils.d.ts +17 -0
  181. package/dist/utils/resolverUtils.js +97 -0
  182. package/dist/utils/resolverUtils.js.map +1 -0
  183. package/dist/utils/settingsUtils.d.ts +19 -0
  184. package/dist/utils/settingsUtils.js +88 -0
  185. package/dist/utils/settingsUtils.js.map +1 -0
  186. package/dist/utils/symbolBuilder.d.ts +10 -0
  187. package/dist/utils/symbolBuilder.js +135 -0
  188. package/dist/utils/symbolBuilder.js.map +1 -0
  189. package/dist/utils/workspaceUtils.d.ts +11 -0
  190. package/dist/utils/workspaceUtils.js +52 -0
  191. package/dist/utils/workspaceUtils.js.map +1 -0
  192. package/package.json +51 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kylmp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # runescript-lsp
2
+
3
+ Language Server Protocol implementation for Runescript.
4
+
5
+ ## Build
6
+
7
+ ```bash
8
+ npm run build
9
+ ```
10
+
11
+ ## Run
12
+
13
+ ```bash
14
+ node dist/server.js
15
+ ```
@@ -0,0 +1,15 @@
1
+ import { SymbolType } from '../resource/enum/symbolTypes.js';
2
+ /**
3
+ * One trie per SymbolType, stores the names of all symbols of a type into a trie datastructure
4
+ * This is used for quicker code completion lookups
5
+ */
6
+ export declare class CompletionCache {
7
+ private readonly cache;
8
+ put(name: string, symbolType: SymbolType): void;
9
+ getAllWithPrefix(prefix: string, symbolType: SymbolType): string[] | undefined;
10
+ contains(name: string, symbolType: SymbolType): boolean;
11
+ remove(name: string, symbolType: SymbolType): void;
12
+ clear(symbolType?: SymbolType): void;
13
+ getTypes(): SymbolType[];
14
+ getTypesCount(): string[];
15
+ }
@@ -0,0 +1,58 @@
1
+ import { Trie } from './Trie.js';
2
+ /**
3
+ * One trie per SymbolType, stores the names of all symbols of a type into a trie datastructure
4
+ * This is used for quicker code completion lookups
5
+ */
6
+ export class CompletionCache {
7
+ cache = new Map();
8
+ put(name, symbolType) {
9
+ if (!this.cache.has(symbolType)) {
10
+ this.cache.set(symbolType, new Trie());
11
+ }
12
+ this.cache.get(symbolType).insert(name);
13
+ const colonIndex = name.indexOf(':');
14
+ if (colonIndex >= 0) {
15
+ this.cache.get(symbolType).insert(name.substring(colonIndex + 1));
16
+ }
17
+ }
18
+ getAllWithPrefix(prefix, symbolType) {
19
+ const symbolTrie = this.cache.get(symbolType);
20
+ if (symbolTrie) {
21
+ return symbolTrie.findAllWithPrefix(prefix);
22
+ }
23
+ return undefined;
24
+ }
25
+ contains(name, symbolType) {
26
+ const symbolTrie = this.cache.get(symbolType);
27
+ if (symbolTrie) {
28
+ return symbolTrie.hasWord(name);
29
+ }
30
+ return false;
31
+ }
32
+ remove(name, symbolType) {
33
+ const symbolTrie = this.cache.get(symbolType);
34
+ if (symbolTrie) {
35
+ symbolTrie.removeWord(name);
36
+ }
37
+ }
38
+ clear(symbolType) {
39
+ if (symbolType) {
40
+ this.cache.delete(symbolType);
41
+ return;
42
+ }
43
+ this.cache.clear();
44
+ }
45
+ getTypes() {
46
+ return Array.from(this.cache.keys());
47
+ }
48
+ getTypesCount() {
49
+ const labelWidth = 12;
50
+ return this.getTypes()
51
+ .sort((a, b) => this.cache.get(b).getAllWordsCount() - this.cache.get(a).getAllWordsCount())
52
+ .map(type => {
53
+ const label = `${type}:`.padEnd(labelWidth);
54
+ return ` ${label} ${this.cache.get(type).getAllWordsCount()}`;
55
+ });
56
+ }
57
+ }
58
+ //# sourceMappingURL=CompletionCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompletionCache.js","sourceRoot":"","sources":["../../src/cache/CompletionCache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;EAGE;AACF,MAAM,OAAO,eAAe;IACT,KAAK,GAA0B,IAAI,GAAG,EAAE,CAAC;IAE1D,GAAG,CAAC,IAAY,EAAE,UAAsB;QACtC,IA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;IAED,KAAK,CAAC,UAAuB;QAC3B,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAC9B,OAAO;QACT,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,QAAQ;QACN,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,aAAa;QACX,MAAM,UAAU,GAAG,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,QAAQ,EAAE;aACnB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC,gBAAgB,EAAE,CAAC;aAC7F,GAAG,CAAC,IAAI,CAAC,EAAE;YACV,MAAM,KAAK,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAC5C,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,gBAAgB,EAAE,EAAE,CAAC;QAClE,CAAC,CAAC,CAAC;IACP,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ import { Range } from "vscode-languageserver";
2
+ import { DataRange, FileInfo, ResolvedSymbol, RunescriptSymbol } from "../types.js";
3
+ import { Position } from "vscode-languageserver-textdocument";
4
+ import { HighlightKind } from "../types.js";
5
+ export declare class FileCache {
6
+ private readonly fileSymbols;
7
+ private readonly localVarCache;
8
+ private readonly scriptRanges;
9
+ private readonly symbolRanges;
10
+ private readonly fileInfo;
11
+ constructor(fileInfo: FileInfo);
12
+ addSymbol(lineNum: number, symbol: DataRange<ResolvedSymbol>): void;
13
+ getAtPosition(position: Position): DataRange<ResolvedSymbol> | undefined;
14
+ getSymbols(): Map<number, DataRange<ResolvedSymbol>[]>;
15
+ getSymbolRanges(): {
16
+ kind: HighlightKind;
17
+ range: Range;
18
+ }[];
19
+ addLocalVariable(localVar: RunescriptSymbol, lineNum: number, start: number, end: number): undefined;
20
+ addLocalVariableReference(name: string, lineNum: number, start: number, end: number): undefined;
21
+ getLocalVariable(lineNum: number, name: string): RunescriptSymbol | undefined;
22
+ addScriptRange(startLine: number, endLine: number, blockName: string): void;
23
+ getScriptName(lineNum: number): DataRange<string> | undefined;
24
+ getFileInfo(): FileInfo;
25
+ }
@@ -0,0 +1,101 @@
1
+ import { findMatchInRange } from "../utils/resolverUtils.js";
2
+ import { addReference } from "../utils/symbolBuilder.js";
3
+ import { SymbolType } from "../resource/enum/symbolTypes.js";
4
+ import { warn } from "../utils/logger.js";
5
+ import { getSymbolConfig } from "../resource/symbolConfig.js";
6
+ import { HighlightKind } from "../types.js";
7
+ export class FileCache {
8
+ // Cache of all symbols in the file, per line
9
+ fileSymbols;
10
+ // key => block name | value => map of local variable symbols keyed by variable name
11
+ localVarCache;
12
+ // Tracks the line number range of scripts in the file
13
+ scriptRanges;
14
+ symbolRanges;
15
+ fileInfo;
16
+ constructor(fileInfo) {
17
+ this.fileSymbols = new Map();
18
+ this.localVarCache = new Map();
19
+ this.scriptRanges = [];
20
+ this.symbolRanges = [];
21
+ this.fileInfo = fileInfo;
22
+ }
23
+ addSymbol(lineNum, symbol) {
24
+ this.symbolRanges.push({
25
+ kind: symbol.data.symbol.symbolType === SymbolType.Unknown ? HighlightKind.Unknown : HighlightKind.Symbol,
26
+ range: {
27
+ start: { line: lineNum, character: symbol.start },
28
+ end: { line: lineNum, character: symbol.end }
29
+ }
30
+ });
31
+ let symbols = this.fileSymbols.get(lineNum);
32
+ if (!symbols) {
33
+ this.fileSymbols.set(lineNum, [symbol]);
34
+ return;
35
+ }
36
+ if (symbols.length === 0 || symbols[symbols.length - 1].start <= symbol.start) {
37
+ symbols.push(symbol);
38
+ return;
39
+ }
40
+ for (let i = 0; i < symbols.length; i++) {
41
+ if (symbols[i].start > symbol.start) {
42
+ symbols.splice(i, 0, symbol);
43
+ return;
44
+ }
45
+ }
46
+ symbols.push(symbol);
47
+ }
48
+ getAtPosition(position) {
49
+ return findMatchInRange(position.character, this.fileSymbols.get(position.line));
50
+ }
51
+ getSymbols() {
52
+ return this.fileSymbols;
53
+ }
54
+ getSymbolRanges() {
55
+ return this.symbolRanges;
56
+ }
57
+ addLocalVariable(localVar, lineNum, start, end) {
58
+ const scriptName = this.getScriptName(lineNum);
59
+ if (!scriptName)
60
+ return undefined;
61
+ const scriptLocalVariables = this.localVarCache.get(scriptName.data) ?? new Map();
62
+ scriptLocalVariables.set(localVar.name, localVar);
63
+ this.localVarCache.set(scriptName.data, scriptLocalVariables);
64
+ const resolvedLocalVar = { start, end, data: { symbol: localVar, symbolConfig: getSymbolConfig(SymbolType.LocalVar), declaration: true } };
65
+ this.addSymbol(lineNum, resolvedLocalVar);
66
+ }
67
+ addLocalVariableReference(name, lineNum, start, end) {
68
+ const scriptName = this.getScriptName(lineNum);
69
+ if (!scriptName)
70
+ return undefined;
71
+ const scriptLocalVariables = this.localVarCache.get(scriptName.data) ?? new Map();
72
+ const localVarSymbol = scriptLocalVariables.get(name);
73
+ if (!localVarSymbol) {
74
+ warn(`Tried to add local var reference but the definition doesn't exist. localVar=${name}, file=${this.fileInfo.fsPath}`);
75
+ return;
76
+ }
77
+ const refs = addReference(localVarSymbol, this.fileInfo.fsPath, lineNum, start, end);
78
+ localVarSymbol.references[this.fileInfo.fsPath] = refs;
79
+ const resolvedLocalVar = { start, end, data: { symbol: localVarSymbol, symbolConfig: getSymbolConfig(SymbolType.LocalVar), declaration: false } };
80
+ this.addSymbol(lineNum, resolvedLocalVar);
81
+ }
82
+ getLocalVariable(lineNum, name) {
83
+ const scriptName = this.getScriptName(lineNum);
84
+ if (!scriptName)
85
+ return undefined;
86
+ const scriptLocalVariables = this.localVarCache.get(scriptName.data);
87
+ if (!scriptLocalVariables)
88
+ return undefined;
89
+ return scriptLocalVariables.get(name);
90
+ }
91
+ addScriptRange(startLine, endLine, blockName) {
92
+ this.scriptRanges.push({ start: startLine, end: endLine, data: blockName });
93
+ }
94
+ getScriptName(lineNum) {
95
+ return findMatchInRange(lineNum, this.scriptRanges);
96
+ }
97
+ getFileInfo() {
98
+ return this.fileInfo;
99
+ }
100
+ }
101
+ //# sourceMappingURL=FileCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileCache.js","sourceRoot":"","sources":["../../src/cache/FileCache.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAuB,MAAM,2BAA2B,CAAC;AAElF,OAAO,EAAE,YAAY,EAAsB,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,OAAO,SAAS;IACpB,6CAA6C;IAC5B,WAAW,CAA2C;IAEvE,oFAAoF;IACnE,aAAa,CAA6C;IAE3E,sDAAsD;IACrC,YAAY,CAAsB;IAElC,YAAY,CAAwC;IAEpD,QAAQ,CAAW;IAEpC,YAAY,QAAkB;QAC5B,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAuC,CAAC;QAClE,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAyC,CAAC;QACtE,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,SAAS,CAAC,OAAe,EAAE,MAAiC;QAC1D,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;YACrB,IAAI,EAAE,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E,CAAC;IAED,aAAa,CAAC,OAAe;QAC3B,OAAO,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACtD,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ import { SymbolType } from "../resource/enum/symbolTypes.js";
2
+ /**
3
+ * Cache of npc, loc, and obj id to name map. Used for quick lookups of ids in map files.
4
+ */
5
+ export declare class IdCache {
6
+ /**
7
+ * The symbolTypes whose values are cached
8
+ */
9
+ private readonly cachedTypes;
10
+ private readonly cache;
11
+ constructor();
12
+ /**
13
+ * Adds the name and id of a symbol type to the cache, if its one of the cached types
14
+ */
15
+ add(symbolType: SymbolType, id: string, name: string): void;
16
+ /**
17
+ * Returns the name of a symbolType given it's id
18
+ */
19
+ get(symbolType: SymbolType, id: string): string | undefined;
20
+ /**
21
+ * Clears the cache of a particular symbolType (type is resolved from the pack file uri name)
22
+ */
23
+ clear(uri: string): void;
24
+ /**
25
+ * Clears the entire cache
26
+ */
27
+ clearAll(): void;
28
+ }
@@ -0,0 +1,47 @@
1
+ import { SymbolType } from "../resource/enum/symbolTypes.js";
2
+ import { uriToFileInfo } from "../utils/fileUtils.js";
3
+ /**
4
+ * Cache of npc, loc, and obj id to name map. Used for quick lookups of ids in map files.
5
+ */
6
+ export class IdCache {
7
+ /**
8
+ * The symbolTypes whose values are cached
9
+ */
10
+ cachedTypes = new Set([SymbolType.Loc, SymbolType.Npc, SymbolType.Obj]);
11
+ cache = new Map();
12
+ constructor() {
13
+ this.clearAll();
14
+ }
15
+ /**
16
+ * Adds the name and id of a symbol type to the cache, if its one of the cached types
17
+ */
18
+ add(symbolType, id, name) {
19
+ if (this.cachedTypes.has(symbolType)) {
20
+ this.cache.get(symbolType).set(id, name);
21
+ }
22
+ }
23
+ /**
24
+ * Returns the name of a symbolType given it's id
25
+ */
26
+ get(symbolType, id) {
27
+ return this.cache.get(symbolType)?.get(id);
28
+ }
29
+ /**
30
+ * Clears the cache of a particular symbolType (type is resolved from the pack file uri name)
31
+ */
32
+ clear(uri) {
33
+ const fileInfo = uriToFileInfo(uri);
34
+ if (fileInfo.type === "pack" && this.cachedTypes.has(fileInfo.name)) {
35
+ this.cache.set(fileInfo.name, new Map());
36
+ }
37
+ }
38
+ /**
39
+ * Clears the entire cache
40
+ */
41
+ clearAll() {
42
+ for (const type of this.cachedTypes) {
43
+ this.cache.set(type, new Map());
44
+ }
45
+ }
46
+ }
47
+ //# sourceMappingURL=IdCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IdCache.js","sourceRoot":"","sources":["../../src/cache/IdCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;GAEG;AACH,MAAM,OAAO,OAAO;IAClB;;OAEG;IACc,WAAW,GAAG,IAAI,GAAG,CAAa,CAAC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IAEpF,KAAK,GAAyC,IAAI,GAAG,EAAE,CAAC;IAEzE;QACE,IAAI,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,UAAsB,EAAE,EAAU,EAAE,IAAY;QAClD,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAE,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,UAAsB,EAAE,EAAU;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAW;QACf,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,QAAQ,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAkB,CAAC,EAAE,CAAC;YAClF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAkB,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACpC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,76 @@
1
+ import { SymbolType } from "../resource/enum/symbolTypes.js";
2
+ import { SymbolKey, RunescriptSymbol, FileSymbols } from "../types.js";
3
+ import { CompletionCache } from "./CompletionCache.js";
4
+ export declare class SymbolCache {
5
+ /**
6
+ * The symbolCache stores all resolved symbols in the workspace
7
+ * key = symbol name + SymbolType, value = RunescriptSymbol
8
+ */
9
+ private readonly symbolCache;
10
+ /**
11
+ * The fileToSymbolMap keeps track of all symbol declarations and references within a particular file
12
+ * This is used to more easily keep symbol references up to date when changes are made to files
13
+ * key = file fsPath, value = stores the symbolKey for all decs/refs in the file
14
+ */
15
+ private readonly fileToSymbolMap;
16
+ /**
17
+ * Holds all of the symbol names in a Trie (per symbol type) for quick code completions
18
+ */
19
+ private readonly completionCache;
20
+ /**
21
+ * Get the cached symbol using the symbol name and type
22
+ * @param name Name of the symbol
23
+ * @param symbolType type of the symbol
24
+ * @returns symbol if found, undefined otherwise
25
+ */
26
+ get(name: string, symbolType: SymbolType): RunescriptSymbol | undefined;
27
+ /**
28
+ * Get the cached symbol using the symbol key
29
+ * @param key SymbolKey
30
+ * @returns symbol if found, undefined otherwise
31
+ */
32
+ getByKey(key: SymbolKey): RunescriptSymbol | undefined;
33
+ /**
34
+ * Put (declaration) symbol into the cache
35
+ * @param symbol the symbol to insert
36
+ * @param fsPath the fsPath of the file the symbol is defined in
37
+ */
38
+ put(symbol: RunescriptSymbol, fsPath: string): RunescriptSymbol | undefined;
39
+ /**
40
+ * Put (reference) symbol into the cache. Adds a reference if symbol already exists, creates it if not.
41
+ * @param name symbol name
42
+ * @param symbolType symbol type for this reference
43
+ * @param fsPath file fsPath the reference is found in
44
+ * @param fileType file type the reference is found in
45
+ * @param lineNum line number within the file the reference is found on
46
+ * @param startIndex the index within the line where the reference word starts
47
+ * @param endIndex the index within the line where the reference word ends
48
+ */
49
+ putReference(name: string, symbolType: SymbolType, fsPath: string, fileType: string, lineNum: number, startIndex: number, endIndex: number, id?: string, extraData?: Record<string, any>): RunescriptSymbol;
50
+ /**
51
+ * Clears the identifier cache and relevant supporting caches
52
+ */
53
+ clearAll(): void;
54
+ /**
55
+ * Clears out all references and declarations from the cache of a given file
56
+ * @param fsPath The file URI to clear out of the cache
57
+ */
58
+ clearFile(fsPath: string): void;
59
+ /**
60
+ * Update the fileMap with the file of a new identifier declared or referenced within said file
61
+ * @param fileKey fileKey where this identifier declaration or reference is found
62
+ * @param symbolKey identifierKey of this identifier
63
+ * @param declaration boolean: true if inserting a declaration, false if inserting a reference
64
+ */
65
+ private addToFileMap;
66
+ getCompletionCache(): CompletionCache;
67
+ getFileSymbols(fsPath: string): FileSymbols;
68
+ /**
69
+ * Return all of the cache keys in the identifier cache, used for the export cache keys debug command
70
+ * @returns cache keys
71
+ */
72
+ getCacheKeys(): string[];
73
+ getCacheKeyCount(identifiers?: boolean): number;
74
+ getTotalReferences(): number;
75
+ getFileIdentifiers(fsPath: string): FileSymbols | undefined;
76
+ }
@@ -0,0 +1,205 @@
1
+ import { getSymbolConfig } from "../resource/symbolConfig.js";
2
+ import { decodeReference, resolveSymbolKey } from "../utils/cacheUtils.js";
3
+ import { addReference, buildSymbolFromRef } from "../utils/symbolBuilder.js";
4
+ import { CompletionCache } from "./CompletionCache.js";
5
+ export class SymbolCache {
6
+ /**
7
+ * The symbolCache stores all resolved symbols in the workspace
8
+ * key = symbol name + SymbolType, value = RunescriptSymbol
9
+ */
10
+ symbolCache = new Map();
11
+ /**
12
+ * The fileToSymbolMap keeps track of all symbol declarations and references within a particular file
13
+ * This is used to more easily keep symbol references up to date when changes are made to files
14
+ * key = file fsPath, value = stores the symbolKey for all decs/refs in the file
15
+ */
16
+ fileToSymbolMap = new Map();
17
+ /**
18
+ * Holds all of the symbol names in a Trie (per symbol type) for quick code completions
19
+ */
20
+ completionCache = new CompletionCache();
21
+ /**
22
+ * Get the cached symbol using the symbol name and type
23
+ * @param name Name of the symbol
24
+ * @param symbolType type of the symbol
25
+ * @returns symbol if found, undefined otherwise
26
+ */
27
+ get(name, symbolType) {
28
+ const key = resolveSymbolKey(name, symbolType);
29
+ return key !== undefined ? this.symbolCache.get(key) : undefined;
30
+ }
31
+ /**
32
+ * Get the cached symbol using the symbol key
33
+ * @param key SymbolKey
34
+ * @returns symbol if found, undefined otherwise
35
+ */
36
+ getByKey(key) {
37
+ return this.symbolCache.get(key);
38
+ }
39
+ /**
40
+ * Put (declaration) symbol into the cache
41
+ * @param symbol the symbol to insert
42
+ * @param fsPath the fsPath of the file the symbol is defined in
43
+ */
44
+ put(symbol, fsPath) {
45
+ // This function is only for inserting definitions
46
+ if (!symbol.declaration) {
47
+ return undefined;
48
+ }
49
+ // Make sure cache keys resolve correctly
50
+ const key = resolveSymbolKey(symbol.cacheName, symbol.symbolType);
51
+ const fileKey = fsPath;
52
+ // Retrieve current symbol from cache (if any)
53
+ let currentSymbol = this.symbolCache.get(key);
54
+ // If the current symbol in cache already is the declaration, don't overwrite
55
+ if (currentSymbol?.declaration) {
56
+ return currentSymbol;
57
+ }
58
+ if (!currentSymbol) {
59
+ currentSymbol = symbol;
60
+ }
61
+ if (!currentSymbol.declaration) {
62
+ currentSymbol.declaration = symbol.declaration;
63
+ }
64
+ currentSymbol.cacheName = symbol.cacheName;
65
+ this.symbolCache.set(key, currentSymbol);
66
+ // Add the declarartion to the file map
67
+ this.addToFileMap(fileKey, key, true);
68
+ // Add the symbol name to the completion cache
69
+ this.completionCache.put(currentSymbol.name, currentSymbol.symbolType);
70
+ // Also insert the declaration as a reference
71
+ const ref = decodeReference(currentSymbol.declaration.ref);
72
+ if (ref) {
73
+ const { line, start, end } = ref;
74
+ this.putReference(currentSymbol.cacheName, currentSymbol.symbolType, fsPath, currentSymbol.fileType ?? 'rs2', line, start, end);
75
+ }
76
+ // Return the symbol
77
+ return currentSymbol;
78
+ }
79
+ /**
80
+ * Put (reference) symbol into the cache. Adds a reference if symbol already exists, creates it if not.
81
+ * @param name symbol name
82
+ * @param symbolType symbol type for this reference
83
+ * @param fsPath file fsPath the reference is found in
84
+ * @param fileType file type the reference is found in
85
+ * @param lineNum line number within the file the reference is found on
86
+ * @param startIndex the index within the line where the reference word starts
87
+ * @param endIndex the index within the line where the reference word ends
88
+ */
89
+ putReference(name, symbolType, fsPath, fileType, lineNum, startIndex, endIndex, id, extraData) {
90
+ // Make sure cache keys resolve correctly
91
+ const key = resolveSymbolKey(name, symbolType);
92
+ const fileKey = fsPath;
93
+ // If the symbol doesn't yet exist in the cache, build it
94
+ if (!this.symbolCache.has(key)) {
95
+ this.symbolCache.set(key, buildSymbolFromRef(name, symbolType, fileType, extraData));
96
+ }
97
+ // Get the current references for this identifier in the current file (if any) and add this new reference
98
+ const currentSymbol = this.symbolCache.get(key);
99
+ addReference(currentSymbol, fileKey, lineNum, startIndex, endIndex, id);
100
+ // Add the reference to the file map
101
+ this.addToFileMap(fileKey, key, false);
102
+ // If the matchType of this identifier is reference only, add the data to the completion cache (others will get added when the declaration is added)
103
+ const symbolConfig = getSymbolConfig(symbolType);
104
+ if (symbolConfig?.referenceOnly)
105
+ this.completionCache.put(name, symbolType);
106
+ if (symbolConfig?.cache)
107
+ currentSymbol.cacheName = name;
108
+ return currentSymbol;
109
+ }
110
+ /**
111
+ * Clears the identifier cache and relevant supporting caches
112
+ */
113
+ clearAll() {
114
+ this.symbolCache.clear();
115
+ this.fileToSymbolMap.clear();
116
+ this.completionCache.clear();
117
+ }
118
+ /**
119
+ * Clears out all references and declarations from the cache of a given file
120
+ * @param fsPath The file URI to clear out of the cache
121
+ */
122
+ clearFile(fsPath) {
123
+ const fileKey = fsPath;
124
+ // Get the identifiers in the file
125
+ const symbolsInFile = this.fileToSymbolMap.get(fileKey) || { declarations: new Set(), references: new Set() };
126
+ // Iterate thru the references in the file
127
+ symbolsInFile.references.forEach((key) => {
128
+ const symbol = this.symbolCache.get(key);
129
+ if (symbol) {
130
+ // Delete references to the cleared file from every identifier which referenced the file
131
+ if (symbol.references[fileKey]) {
132
+ delete symbol.references[fileKey];
133
+ }
134
+ // Cleanup/Delete identifiers without a declaration who no longer have any references
135
+ if (Object.keys(symbol.references).length === 0 && !symbol.declaration) {
136
+ if (symbol.symbolType)
137
+ this.completionCache.remove(symbol.name, symbol.symbolType);
138
+ this.symbolCache.delete(key);
139
+ }
140
+ }
141
+ });
142
+ // Iterate thru the declarations in the file
143
+ symbolsInFile.declarations.forEach((key) => {
144
+ const symbol = this.symbolCache.get(key);
145
+ if (symbol) {
146
+ // If the identifier has orphaned references, then we only delete the declaration and keep the identifier w/references
147
+ // Otherwise, we delete the entire identifier (no declaration and no references => no longer exists in any capacity)
148
+ if (symbol.symbolType)
149
+ this.completionCache.remove(symbol.name, symbol.symbolType);
150
+ const hasOrphanedRefs = Object.keys(symbol.references).length > 0;
151
+ if (hasOrphanedRefs) {
152
+ delete symbol.declaration;
153
+ }
154
+ else {
155
+ this.symbolCache.delete(key);
156
+ }
157
+ }
158
+ });
159
+ // Remove the entry for the file from the fileToIdentifierMap
160
+ this.fileToSymbolMap.delete(fileKey);
161
+ }
162
+ /**
163
+ * Update the fileMap with the file of a new identifier declared or referenced within said file
164
+ * @param fileKey fileKey where this identifier declaration or reference is found
165
+ * @param symbolKey identifierKey of this identifier
166
+ * @param declaration boolean: true if inserting a declaration, false if inserting a reference
167
+ */
168
+ addToFileMap(fileKey, symbolKey, declaration = true) {
169
+ // Get the current identifiers in a file, or a new default empty set for both declarations and reference if nothing exists
170
+ const symbolsInFile = this.fileToSymbolMap.get(fileKey) || { declarations: new Set(), references: new Set() };
171
+ // If we are inserting a declaration update declaration identifiers, else update reference identifiers of the file
172
+ (declaration) ? symbolsInFile.declarations.add(symbolKey) : symbolsInFile.references.add(symbolKey);
173
+ // Update the cache with the new data
174
+ this.fileToSymbolMap.set(fileKey, symbolsInFile);
175
+ }
176
+ getCompletionCache() {
177
+ return this.completionCache;
178
+ }
179
+ getFileSymbols(fsPath) {
180
+ return this.fileToSymbolMap.get(fsPath) ?? { declarations: new Set(), references: new Set() };
181
+ }
182
+ /**
183
+ * Return all of the cache keys in the identifier cache, used for the export cache keys debug command
184
+ * @returns cache keys
185
+ */
186
+ getCacheKeys() {
187
+ return Array.from(this.symbolCache.keys()).sort();
188
+ }
189
+ getCacheKeyCount(identifiers = true) {
190
+ return identifiers ? this.symbolCache.size : this.fileToSymbolMap.size;
191
+ }
192
+ getTotalReferences() {
193
+ let total = 0;
194
+ for (const symbol of this.symbolCache.values()) {
195
+ for (const references of Object.values(symbol.references ?? {})) {
196
+ total += references.size;
197
+ }
198
+ }
199
+ return total;
200
+ }
201
+ getFileIdentifiers(fsPath) {
202
+ return this.fileToSymbolMap.get(fsPath);
203
+ }
204
+ }
205
+ //# sourceMappingURL=SymbolCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SymbolCache.js","sourceRoot":"","sources":["../../src/cache/SymbolCache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,C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d,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC;YAC/C,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,CAAC;gBAChE,KAAK,IAAI,UAAU,CAAC,IAAI,CAAC;YAC3B,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,kBAAkB,CAAC,MAAc;QAC/B,OAAO,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ declare class TrieNode {
2
+ children: Map<string, TrieNode>;
3
+ value: string;
4
+ endOfWord: boolean;
5
+ constructor(value?: string);
6
+ }
7
+ export declare class Trie {
8
+ private root;
9
+ constructor();
10
+ insert(word: string): TrieNode | false;
11
+ getLastNode(letters: string, start?: TrieNode): TrieNode | false;
12
+ hasWord(word: string, start?: TrieNode): boolean;
13
+ findAllWithPrefix(prefix: string, start?: TrieNode): string[];
14
+ getWordsFrom(node?: TrieNode, stringAcc?: string, array?: string[]): string[] | undefined;
15
+ removeWord(word: string): boolean;
16
+ clear(): void;
17
+ getAllWords(): string[];
18
+ getAllWordsCount(): number;
19
+ private countWordsFrom;
20
+ matchLongest(text: string, startIndex?: number): number;
21
+ }
22
+ export {};