Skip to content

Commit feead6a

Browse files
committed
refactor: removed unused imports.
refactor: Created functions for general tasks. feat: More properties in list, semantic token working example.
1 parent fd01cd8 commit feead6a

24 files changed

+4689
-1732
lines changed

package-lock.json

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
"@typescript-eslint/parser": "^6.7.0",
113113
"eslint": "^8.35.0",
114114
"mocha": "^9.2.1",
115+
"stack-typescript": "^1.0.4",
115116
"typescript": "^5.3.2"
116117
},
117118
"dependencies": {

server/src/AntlrListener.ts

Lines changed: 100 additions & 34 deletions
Large diffs are not rendered by default.

server/src/lists.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export class ReservedKeywords {
44

55
private static readonly allowedObjectProperties: string[] = [
6+
"Buildable",
67
"RadarPriority",
78
"KindOf",
89
"SelectPortrait",
@@ -16,19 +17,42 @@ export class ReservedKeywords {
1617
"Side",
1718
"EditorSorting",
1819
"TransportSlotCount",
20+
"PlacementViewAngle",
21+
"EnergyProduction",
22+
"EnergyBonus",
1923
"BuildCost",
2024
"BuildTime",
2125
"VisionRange",
2226
"ShroudClearingRange",
27+
"ShroudRevealToAllRange",
28+
"MaxSimultaneousOfType",
29+
"MaxSimultaneousLinkKey",
30+
"RefundValue",
2331
"CrusherLevel",
2432
"CrushableLevel",
33+
"ExperienceValue",
34+
"ExperienceRequired",
35+
"IsTrainable",
2536
"CommandSet",
2637
"VoiceSelect",
38+
"VoiceGroupSelect",
2739
"VoiceMove",
2840
"VoiceEnter",
41+
"VoiceGuard",
42+
"VoiceAttack",
43+
"VoiceAttackAir",
2944
"VoiceTaskComplete",
45+
"VoiceFear",
46+
"SoundStealthOn",
47+
"SoundStealthOff",
3048
"SoundMoveStart",
3149
"SoundMoveStartDamaged",
50+
"SoundOnDamaged",
51+
"SoundOnReallyDamaged",
52+
"SoundEnter",
53+
"SoundExit",
54+
"SoundAmbient",
55+
"SoundAmbientRubble",
3256
"Locomotor",
3357
"Geometry",
3458
"GeometryMajorRadius",
@@ -110,7 +134,8 @@ export class ReservedKeywords {
110134
"InitialRecoilSpeed",
111135
"MaxRecoilDistance",
112136
"RecoilSettleSpeed",
113-
"RecoilDamping"
137+
"RecoilDamping",
138+
"AnimationsRequirePower"
114139
];
115140

116141
public getAllowedSingleModelDrawProperties(): string[] {
@@ -169,6 +194,15 @@ export class ReservedKeywords {
169194
return ReservedKeywords.allowedTruckDrawProperties.concat(this.getAllowedTankDrawProperties());
170195
}
171196

197+
private static readonly allowedDependencyDrawProperties: string[] = [
198+
"AttachToBoneInContainer",
199+
"OkToChangeModelColor"
200+
]
201+
202+
public getAllowedDependencyDrawProperties(): string[] {
203+
return this.getAllowedDependencyDrawProperties()
204+
}
205+
172206
private static readonly allowedTreeDrawProperties: string[] = [
173207
"ModelName",
174208
"TextureName",
@@ -215,7 +249,8 @@ export class ReservedKeywords {
215249
"Segments",
216250
"SegmentOverlapRatio",
217251
"ArcHeight",
218-
"TilingScalar"
252+
"TilingScalar",
253+
"ScrollRate"
219254
];
220255

221256
public getAllowedLaserDrawProperties(): string[] {
@@ -378,7 +413,14 @@ export class ReservedKeywords {
378413
"RIGHT_TO_CENTER",
379414
"CENTER_TO_RIGHT",
380415
"LEFT_TO_CENTER",
381-
"CENTER_TO_LEFT"
416+
"CENTER_TO_LEFT",
417+
"DOWN_DEFAULT",
418+
"UP_DAY",
419+
"UP_NIGHT",
420+
"UP_SNOW",
421+
"UP_SNOWNIGHT",
422+
"RADAR_EXTENDING",
423+
"GARRISONED"
382424
];
383425

384426
public getAllowedConditionStates(): string[] {

server/src/server.ts

Lines changed: 33 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
createConnection,
77
TextDocuments,
88
Diagnostic,
9-
DiagnosticSeverity,
109
ProposedFeatures,
1110
InitializeParams,
1211
DidChangeConfigurationNotification,
@@ -15,23 +14,16 @@ import {
1514
TextDocumentPositionParams,
1615
TextDocumentSyncKind,
1716
InitializeResult,
18-
ParameterInformation,
19-
integer,
2017
DidChangeConfigurationParams,
2118
DocumentFormattingRequest,
2219
DefinitionParams,
2320
Definition,
24-
Position,
25-
Location,
2621
HoverParams,
27-
MarkupContent,
28-
MarkupKind,
2922
Hover,
3023
SemanticTokensParams,
31-
SemanticTokensRequest,
3224
SemanticTokens,
33-
SemanticTokensBuilder,
34-
Range
25+
DidOpenTextDocumentParams,
26+
SemanticTokensBuilder
3527
} from 'vscode-languageserver/node';
3628

3729
import {
@@ -46,13 +38,13 @@ import { MapIniLexer } from './utils/antlr/MapIniLexer';
4638
import { MapIniParser } from './utils/antlr/MapIniParser';
4739
import { ParseTreeWalker } from 'antlr4ts/tree/ParseTreeWalker';
4840

49-
import * as formatter from './utils/formatter'
50-
import { SymbolVisitor } from './utils/symbols/SymbolVisitor';
41+
import { formatDocument } from './utils/formatter';
5142
import { computeSymbolTable, SymbolTable } from './utils/symbols/SymbolTable';
52-
import { findDefinition, getWordAtPosition } from './utils/definitions';
43+
import { findDefinition } from './utils/definitions';
5344
import { getHoverInformation } from './utils/hover';
5445
import { tokenModifiers, tokenTypes } from './utils/tokenTypes'
5546
import { getSemanticTokens } from './utils/semanticTokens';
47+
import { computeDiagnostics } from './utils/diagnostics';
5648

5749
// Create a connection for the server, using Node's IPC as a transport.
5850
// Also include all preview / proposed LSP features.
@@ -71,7 +63,7 @@ let hasDiagnosticRelatedInformationCapability = false;
7163

7264
let forceAddModule: boolean = true
7365

74-
let symbolTable = new SymbolTable()
66+
let symbolTable: Map<string, SymbolTable> = new Map<string, SymbolTable>();
7567

7668
connection.onInitialize((params: InitializeParams) => {
7769

@@ -144,7 +136,7 @@ connection.onInitialized(() => {
144136
return null
145137
}
146138

147-
return formatter.formatDocument(document, _edits.options.tabSize)
139+
return formatDocument(document, _edits.options.tabSize)
148140
})
149141

150142
connection.client.register(DidChangeConfigurationNotification.type)
@@ -157,82 +149,70 @@ connection.onInitialized(() => {
157149
forceAddModule = settings.forceAddModule
158150
connection.console.log(`Updated forceAddmodule to: ${forceAddModule}`)
159151
} else {
160-
// If setting is not null set forceAddmoule to setting else set forceAddmodule to true
152+
// If setting is not null set forceAddmoule to setting else default to true
161153
change.settings.forceAddModule !== null ? forceAddModule = change.settings.forceAddModule : forceAddModule = true
162154
}
163155
})
164156
}
165157
});
166158

159+
connection.onDidOpenTextDocument((params: DidOpenTextDocumentParams) => {
160+
const textDocument = documents.get(params.textDocument.uri)
161+
symbolTable.set(textDocument!.uri, computeSymbolTable(textDocument!))
162+
});
163+
167164
connection.onHover((params: HoverParams): Hover | null => {
168-
return getHoverInformation(params, documents, symbolTable)
165+
return getHoverInformation(params, documents, symbolTable.get(params.textDocument.uri)!)
169166
});
170167

171168
connection.onDefinition((params: DefinitionParams): Definition | null => {
172-
return findDefinition(params, documents, symbolTable)
169+
return findDefinition(params, documents, symbolTable.get(params.textDocument.uri)!)
173170
});
174171

175172
connection.onRequest("textDocument/semanticTokens/full", (params: SemanticTokensParams): SemanticTokens => {
176-
return getSemanticTokens(documents, params, symbolTable)
173+
try {
174+
return getSemanticTokens(documents, params, symbolTable.get(params.textDocument.uri)!)
175+
} catch {
176+
console.log('Failed to generate SemanticTokens, rerun on next change.')
177+
let tokenBuilder = new SemanticTokensBuilder()
178+
return tokenBuilder.build()
179+
}
177180
});
178181

179182
connection.onRequest("textDocument/semanticTokens/range", (params: SemanticTokensParams): SemanticTokens => {
180-
return getSemanticTokens(documents, params, symbolTable)
183+
try {
184+
return getSemanticTokens(documents, params, symbolTable.get(params.textDocument.uri)!)
185+
} catch {
186+
console.log('Failed to generate SemanticTokens, rerun on next change.')
187+
let tokenBuilder = new SemanticTokensBuilder()
188+
return tokenBuilder.build()
189+
}
181190
});
182191

183192
// The content of a text document has changed. This event is emitted
184193
// when the text document first opened or when its content has changed.
185194
documents.onDidChangeContent(change => {
186195

187-
188196
if (parseTimer) {
189197
clearTimeout(parseTimer);
190198
}
191199

192200
parseTimer = setTimeout(async () => {
193201
const textDocument = change.document;
202+
// Update SymbolTable
203+
symbolTable.set(textDocument.uri, computeSymbolTable(textDocument))
204+
194205
// Create a listener for tree traversal
195206
const treeListener = new TreeListener(forceAddModule);
196-
197207
// Parse the document to compute diagnostics
198208
const diagnostics = await computeDiagnostics(treeListener, textDocument);
209+
treeListener.resetDiagnostics();
199210

200211
// Send the updated diagnostics to the client
201212
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
202-
203-
// Reset the tree listener diagnostics for the next run
204-
treeListener.resetDiagnostics();
205-
206-
207-
// Update SymbolTable
208-
symbolTable = computeSymbolTable(textDocument)
209-
// connection.console.log(`All Symbols: ${symbolTable.getAllSymbols()}`)
210-
211213
}, parseDelay);
212214
});
213215

214-
async function computeDiagnostics(listener: TreeListener, textDocument: TextDocument): Promise<Diagnostic[]> {
215-
try {
216-
217-
const inputStream = CharStreams.fromString(textDocument.getText());
218-
const lexer = new MapIniLexer(inputStream);
219-
const tokenStream = new CommonTokenStream(lexer);
220-
const parser = new MapIniParser(tokenStream);
221-
parser.removeErrorListeners();
222-
parser.addErrorListener(new CustomErrorListener(textDocument, listener));
223-
224-
const walker = new ParseTreeWalker();
225-
const root = parser.program();
226-
walker.walk(listener, root);
227-
228-
return listener.getDiagnostics();
229-
} catch (error) {
230-
// Handle any parsing errors here
231-
connection.console.error(`Error computing diagnostics: ${error}`);
232-
return [];
233-
}
234-
}
235-
236216
connection.onDidCloseTextDocument(e => {
237217
connection.console.log(`Closed document`)
238218
});
@@ -318,10 +298,6 @@ connection.onCompletionResolve(
318298
}
319299
);
320300

321-
322-
323-
324-
325301
// Make the text document manager listen on the connection
326302
// for open, change and close text document events
327303
documents.listen(connection);

0 commit comments

Comments
 (0)