Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export function activate(context: vscode.ExtensionContext) {
// context.subscriptions.push(vscode.commands.registerCommand(command, formatDocument));

let languageServerRunning = ZSconfig.get<boolean>('serverStartupSetting', false); // Default to 2 if not set
let displayAlphaWarning = ZSconfig.get<boolean>('displayAlphaWarning', true);
let precompileTransitionKeys = ZSconfig.get<boolean>('precompileTransitionKeys', false);

context.subscriptions.push(vscode.commands.registerCommand('ZeroSyntax.stopLanguageServer', () => {
if (languageServerRunning) {
Expand Down Expand Up @@ -72,10 +74,12 @@ export function activate(context: vscode.ExtensionContext) {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: vscode.workspace.createFileSystemWatcher('**/.clientrc')
},
// initializationOptions: {
initializationOptions: {
precompileTransitionKeys: precompileTransitionKeys,
forceAddModule: forceAddModule
// SemanticTokenTypes,
// SemanticTokenModifiers
// },
},
// middleware: {
// didChange: (event, next) => {
// const { contentChanges, document } = event;
Expand Down Expand Up @@ -104,7 +108,14 @@ export function activate(context: vscode.ExtensionContext) {
client.start();
}

vscode.window.showWarningMessage('Zero Syntax: This is an alpha version!\nPlease report bugs to https://github.com/ViTeXFTW/ZeroSyntax-Server/issues');
if (displayAlphaWarning) {
// Add buttons to close or turn off the warning
vscode.window.showWarningMessage('Zero Syntax: This is an alpha version!\nPlease report bugs to https://github.com/ViTeXFTW/ZeroSyntax-Server/issues', 'Turn off', 'Close').then((selection) => {
if (selection === 'Turn off') {
ZSconfig.update('displayAlphaWarning', false, vscode.ConfigurationTarget.Global);
}
});
}
}

vscode.workspace.onDidChangeConfiguration((e) => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "ZeroSyntax-Server",
"description": "Language server for Generals Zero Hour INI files",
"icon": "images/icon.png",
"version": "0.1.5",
"version": "0.1.6",
"publisher": "ViTeXFTW",
"author": {
"name": "ViTeXFTW",
Expand Down Expand Up @@ -82,13 +82,28 @@
"default": true,
"description": "Controls whether the server is started automatically after the extension is activated."
},
"languageServerExample.maxNumberOfProblems": {
"ZeroSyntax.displayAlphaWarning": {
"type": "boolean",
"default": true,
"description": "Controls whether the alpha warning is displayed when the server is started."
},
"ZeroSyntax.forceAddModule": {
"type": "boolean",
"default": true,
"description": "Controls whether AddModule around modules is forced."
},
"ZeroSyntax.precompileTransitionKeys": {
"type": "boolean",
"default": true,
"description": "Controls whether the transition keys are precompiled when the server is started."
},
"ZeroSyntax.maxNumberOfProblems": {
"scope": "resource",
"type": "number",
"default": 100,
"description": "Controls the maximum number of problems produced by the server."
},
"languageServerExample.trace.server": {
"ZeroSyntax.trace.server": {
"scope": "window",
"type": "string",
"enum": [
Expand All @@ -105,6 +120,7 @@
"scripts": {
"vscode:prepublish": "npm run compile",
"package": "npm run compile && vsce package",
"cc": "npm run clean && npm run antlr4ng && npm run compile",
"compile": "tsc -b",
"clean": "rimraf ./client/out && rimraf ./server/out",
"compile-test": "cd client && npm run compile-test && cd .. && cd server && npm run compile-test",
Expand Down
56 changes: 50 additions & 6 deletions server/src/diagnostic/diagnosticsVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Diagnostic, DiagnosticSeverity } from "vscode-languageserver";
import * as list from '../utils/lists'
import { Location } from "../utils/location";
import { MapIniVisitor } from "../utils/antlr4ng/MapIniVisitor";
import { Armor_valueContext, Commandbutton_valueContext, CommandSet_valueContext, CommandSetClassPropertyContext, Cursorname_valueContext, DamageFX_valueContext, DrawModule_conditionBlockContext, DrawModule_conditionStateValueContext, DrawModule_transitionKeyPropertyContext, DrawModule_transitionStateBlockContext, EndContext, Fxlist_valueContext, Locomotor_valueContext, MapIniParser, Mappedimage_valueContext, Object_valueContext, ObjectClass_drawModulesContext, ObjectClass_propertiesContext, ObjectClass_setsContext, ObjectClass_soundsContext, ObjectClassContext, Particlesystem_valueContext, ParticleSystemClassContext, ProgramContext, Science_valueContext, Specialpower_valueContext, TransitionKey_valueContext, Upgrade_valueContext } from "../utils/antlr4ng/MapIniParser";
import { AbstractParseTreeVisitor } from "antlr4ng";
import { Armor_valueContext, Commandbutton_valueContext, CommandSet_valueContext, CommandSetClassPropertyContext, Cursorname_valueContext, DamageFX_valueContext, DrawModule_conditionBlockContext, DrawModule_conditionStatePropertiesContext, DrawModule_conditionStateValueContext, DrawModule_defaultconditionBlockContext, DrawModule_transitionKeyPropertyContext, DrawModule_transitionStateBlockContext, EndContext, Fxlist_valueContext, Locomotor_valueContext, MapIniParser, Mappedimage_valueContext, Object_valueContext, ObjectClass_drawModulesContext, ObjectClass_propertiesContext, ObjectClass_setsContext, ObjectClass_soundsContext, ObjectClassContext, Particlesystem_valueContext, ParticleSystemClassContext, ProgramContext, Science_valueContext, Specialpower_valueContext, TransitionKey_valueContext, Upgrade_valueContext, W3dDebrisDrawModuleContext, W3dDefaultDrawModuleContext, W3dDependencyDrawModuleContext, W3dLaserDrawModuleContext, W3dModelDrawModuleContext, W3dOverlordTankDrawModuleContext, W3dProjectileStreamDrawModuleContext, W3dScienceModelDrawModuleContext, W3dSupplyDrawModuleContext, W3dTreeDrawModuleContext, W3dVehicleDrawModuleContext } from "../utils/antlr4ng/MapIniParser";
import { AbstractParseTreeVisitor, ParserRuleContext } from "antlr4ng";
import { ErrorListener } from "../errorListener";
import { ClassVisitor } from './classVisitor';

Expand All @@ -14,10 +14,12 @@ export class DiagnosticVisitor extends AbstractParseTreeVisitor<void> implements
}

diagnostics: Diagnostic[]
precompileTransitionKeys: boolean

constructor(diagnostics: Diagnostic[]) {
constructor(diagnostics: Diagnostic[], precompileTransitionKeys: boolean) {
super()
this.diagnostics = diagnostics
this.precompileTransitionKeys = precompileTransitionKeys
}

visitProgram(ctx: ProgramContext): void {
Expand Down Expand Up @@ -177,11 +179,52 @@ export class DiagnosticVisitor extends AbstractParseTreeVisitor<void> implements
// }

visitObjectClass_drawModules(ctx: ObjectClass_drawModulesContext): void {
console.log(list.customConditionStates)
list.customConditionStates.clear()


if (this.precompileTransitionKeys) {
for (const child of ctx.children || []) {
if (child instanceof W3dModelDrawModuleContext ||
child instanceof W3dVehicleDrawModuleContext ||
child instanceof W3dOverlordTankDrawModuleContext
) {
this.collectTransitionKeys(child)
}
}
}


this.visitChildren(ctx)
}

private collectTransitionKeys(ctx: ParserRuleContext): void {
for (const child of ctx.children || []) {
if (child instanceof DrawModule_conditionBlockContext) {
// Recursively check condition block for TransitionKey properties
this.collectTransitionKeysFromBlock(child)
} else if (child instanceof DrawModule_defaultconditionBlockContext) {
// Check default condition block
this.collectTransitionKeysFromBlock(child)
}
// Recursively check other children
this.collectTransitionKeys(child as ParserRuleContext)
}
}

private collectTransitionKeysFromBlock(ctx: ParserRuleContext): void {
for (const child of ctx.children || []) {
if (child instanceof DrawModule_conditionStatePropertiesContext) {
const transitionKeyProp = child.drawModule_transitionKeyProperty?.()
if (transitionKeyProp?.transitionKey_value()?.ID()) {
const ID_text = transitionKeyProp.transitionKey_value().ID()!.getText()
list.customConditionStates.remove(ID_text)
list.customConditionStates.insert(ID_text)
}
}
// Recursively check other children
this.collectTransitionKeysFromBlock(child as ParserRuleContext)
}
}

// =====================================
// =========== CLASS VALUES ============
Expand Down Expand Up @@ -403,6 +446,7 @@ export class DiagnosticVisitor extends AbstractParseTreeVisitor<void> implements
}
}
}

this.visitChildren(ctx)
}

Expand Down Expand Up @@ -454,7 +498,7 @@ export class DiagnosticVisitor extends AbstractParseTreeVisitor<void> implements
}
}

export function computeDiagnostics(parser: MapIniParser): Diagnostic[] {
export function computeDiagnostics(parser: MapIniParser, precompileTransitionKeys: boolean): Diagnostic[] {

let diagnostics: Diagnostic[] = []

Expand All @@ -464,7 +508,7 @@ export function computeDiagnostics(parser: MapIniParser): Diagnostic[] {
const tree = parser.program()
// console.log(`Tree: ${tree.getText()}`)

const vistor = new DiagnosticVisitor(diagnostics)
const vistor = new DiagnosticVisitor(diagnostics, precompileTransitionKeys)
const classVisitor = new ClassVisitor()

classVisitor.visitProgram(tree)
Expand Down
7 changes: 7 additions & 0 deletions server/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ export class Parser {
private lexer: MapIniLexer | undefined;
private tokenStream: CommonTokenStream | undefined;

private document: TextDocument | undefined;

constructor() {}

updateParser(document: TextDocument): MapIniParser {
this.inputStream = CharStream.fromString(document.getText());
this.lexer = new MapIniLexer(this.inputStream);
this.tokenStream = new CommonTokenStream(this.lexer);
this.latestParser = new MapIniParser(this.tokenStream);
this.document = document;

return this.latestParser
}
Expand Down Expand Up @@ -48,4 +51,8 @@ export class Parser {
}
}

getDocument(): TextDocument | undefined {
return this.document
}

}
17 changes: 10 additions & 7 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ let parser: Parser = new Parser();
let currentParser: MapIniParser;

let forceAddModule: boolean = true
let precompileTransitionKeys: boolean = false

connection.onInitialize((params: InitializeParams) => {
const capabilities = params.capabilities;
Expand Down Expand Up @@ -93,6 +94,10 @@ connection.onInitialize((params: InitializeParams) => {
// }
}
};

forceAddModule = options.forceAddModule !== undefined ? options.forceAddModule : true
precompileTransitionKeys = options.precompileTransitionKeys !== undefined ? options.precompileTransitionKeys : false

if (hasWorkspaceFolderCapability) {
result.capabilities.workspace = {
workspaceFolders: {
Expand Down Expand Up @@ -120,12 +125,10 @@ connection.onInitialized(() => {
connection.onDidChangeConfiguration(async (change: DidChangeConfigurationParams) => {
const settings = await connection.workspace.getConfiguration('ZeroSyntax')

if (settings.forceAddModule !== null) {
forceAddModule = settings.forceAddModule
console.log(`Updated forceAddmodule to: ${forceAddModule}`)
} else {
// If setting is not null set forceAddmoule to setting else default to true
change.settings.forceAddModule !== null ? forceAddModule = change.settings.forceAddModule : forceAddModule = true
forceAddModule = settings.forceAddModule !== null ? settings.forceAddModule : true

if (settings.precompileTransitionKeys !== null) {
precompileTransitionKeys = settings.precompileTransitionKeys
}
})
}
Expand Down Expand Up @@ -181,7 +184,7 @@ documents.onDidChangeContent((change) => {
currentParser = parser.updateParser(change.document) //Potentially add another timer that is shorter, but does not create a parser for every input.

diagnosticTimer = setTimeout(() => {
let diagnostics = computeDiagnostics(currentParser)
let diagnostics = computeDiagnostics(currentParser, precompileTransitionKeys)
// console.log(`Diagnostics: ${diagnostics}`)
connection.sendDiagnostics({ uri: change.document.uri, diagnostics })
console.log(`Diagnostics sent!`)
Expand Down
Loading