Skip to content

Commit c706cb1

Browse files
committed
Fix various small issues
1 parent c6c95b7 commit c706cb1

File tree

12 files changed

+142
-210
lines changed

12 files changed

+142
-210
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"eqeqeq": "warn",
2727
"no-unsafe-finally": "warn",
2828
"no-throw-literal": "warn",
29+
"prefer-const": "warn",
2930
"space-before-function-paren": "off",
3031
"semi": "off",
3132
"quotes": "off",

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,10 @@ All notable changes to the "nwscript-ee-language-server" extension will be docum
4848
## [1.5.2]
4949

5050
- `const` expressions resolution has been enhanced.
51+
52+
## [1.5.3]
53+
54+
- Goto will now work for functions from `nwscript.nss` if the file is in your project.
55+
- Fixed the compilation provider not reporting warnings.
56+
- New compiler setting `reportWarnings`. True by default.
57+
- New formatter setting `verbose`. False by default.

package.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "https://github.com/PhilippeChab/nwscript-ee-language-server"
99
},
1010
"license": "MIT",
11-
"version": "1.5.2",
11+
"version": "1.5.3",
1212
"author": {
1313
"name": "Philippe Chabot"
1414
},
@@ -71,12 +71,17 @@
7171
"enabled": {
7272
"type": "boolean",
7373
"default": false,
74-
"description": "Whether the formatter is enabled or not."
74+
"description": "Whether or not the formatter is enabled."
75+
},
76+
"verbose": {
77+
"type": "boolean",
78+
"default": false,
79+
"description": "Whether or not the formatter is verbose."
7580
},
7681
"executable": {
7782
"type": "string",
7883
"default": "clang-format",
79-
"description": "Clang's executable path."
84+
"description": "Clang format's executable path."
8085
},
8186
"ignoredGlobs": {
8287
"type": "array",
@@ -111,12 +116,17 @@
111116
"enabled": {
112117
"type": "boolean",
113118
"default": true,
114-
"description": "Whether the compiler is enabled or not."
119+
"description": "Whether or not the compiler is enabled."
115120
},
116121
"verbose": {
117122
"type": "boolean",
118123
"default": false,
119-
"description": "Print the compilation result in the output console."
124+
"description": "Whether or not the compiler is verbose."
125+
},
126+
"reportWarnings": {
127+
"type": "boolean",
128+
"default": false,
129+
"description": "Whether or not the compiler report warnings."
120130
},
121131
"nwnHome": {
122132
"type": "string",

server/src/Documents/DocumentsIndexer.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@ const generateTokens = async (filesPath: string[]) => {
1010
}
1111

1212
const tokenizer = await new Tokenizer().loadGrammar();
13-
1413
for (let i = 0; i < filesPath.length; i++) {
1514
const filePath = filesPath[i];
16-
if (filePath.includes("nwscript.nss")) {
17-
continue;
18-
}
19-
2015
const fileContent = readFileSync(filePath).toString();
2116
const globalScope = tokenizer.tokenizeContent(fileContent, TokenizedScope.global);
2217

server/src/Providers/DiagnosticsProvider.ts

Lines changed: 49 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ServerManager } from "../ServerManager";
88
import Provider from "./Provider";
99

1010
const lineNumber = /\(([^)]+)\)/;
11-
const lineMessage = /Error:(.*)/;
11+
const lineMessage = /(Error|Warning):(.*)/;
1212
const lineFilename = /^[^(]+/;
1313

1414
enum OS {
@@ -30,11 +30,7 @@ export default class DiagnoticsProvider extends Provider {
3030
);
3131
}
3232

33-
private sendDiagnostics(uri: string, diagnostics: Diagnostic[]) {
34-
this.server.connection.sendDiagnostics({ uri, diagnostics });
35-
}
36-
37-
private generateDiagnostic(uris: string[], files: FilesDiagnostics, severity: DiagnosticSeverity) {
33+
private generateDiagnostics(uris: string[], files: FilesDiagnostics, severity: DiagnosticSeverity) {
3834
return (line: string) => {
3935
const uri = uris.find((uri) => basename(fileURLToPath(uri)) === lineFilename.exec(line)![0]);
4036

@@ -73,8 +69,8 @@ export default class DiagnoticsProvider extends Provider {
7369

7470
private publish(uri: string) {
7571
return async () => {
76-
return await new Promise((resolve, reject) => {
77-
const { enabled, nwnHome, nwnInstallation, verbose } = this.server.config.compiler;
72+
return await new Promise<boolean>((resolve, reject) => {
73+
const { enabled, nwnHome, reportWarnings, nwnInstallation, verbose } = this.server.config.compiler;
7874
if (!enabled) {
7975
return resolve(true);
8076
}
@@ -149,67 +145,62 @@ export default class DiagnoticsProvider extends Provider {
149145
});
150146

151147
child.on("close", (_) => {
152-
try {
153-
const lines = stdout
154-
.toString()
155-
.split("\n")
156-
.filter((line) => line !== "\r" && line !== "\n" && Boolean(line));
157-
const errors: string[] = [];
158-
const warnings: string[] = [];
159-
160-
lines.forEach((line) => {
161-
if (verbose && !line.includes("Compiling:")) {
162-
this.server.logger.info(line);
163-
}
148+
const lines = stdout
149+
.toString()
150+
.split("\n")
151+
.filter((line) => line !== "\r" && line !== "\n" && Boolean(line));
152+
const errors: string[] = [];
153+
const warnings: string[] = [];
154+
155+
lines.forEach((line) => {
156+
if (verbose && !line.includes("Compiling:")) {
157+
this.server.logger.info(line);
158+
}
164159

165-
// Diagnostics
166-
if (line.includes("Error:")) {
167-
errors.push(line);
168-
}
169-
if (line.includes("Warning:")) {
170-
warnings.push(line);
171-
}
160+
// Diagnostics
161+
if (line.includes("Error:")) {
162+
errors.push(line);
163+
}
164+
if (reportWarnings && line.includes("Warning:")) {
165+
warnings.push(line);
166+
}
172167

173-
// Actual errors
174-
if (line.includes("NOTFOUND")) {
168+
// Actual errors
169+
if (line.includes("NOTFOUND")) {
170+
return this.server.logger.error(
171+
"Unable to resolve nwscript.nss. Are your Neverwinter Nights home and/or installation directories valid?",
172+
);
173+
}
174+
if (line.includes("Failed to open .key archive")) {
175+
return this.server.logger.error(
176+
"Unable to open nwn_base.key Is your Neverwinter Nights installation directory valid?",
177+
);
178+
}
179+
if (line.includes("Unable to read input file")) {
180+
if (Boolean(nwnHome) || Boolean(nwnInstallation)) {
175181
return this.server.logger.error(
176-
"Unable to resolve nwscript.nss. Are your Neverwinter Nights home and/or installation directories valid?",
182+
"Unable to resolve provided Neverwinter Nights home and/or installation directories. Ensure the paths are valid in the extension settings.",
177183
);
178-
}
179-
if (line.includes("Failed to open .key archive")) {
184+
} else {
180185
return this.server.logger.error(
181-
"Unable to open nwn_base.key Is your Neverwinter Nights installation directory valid?",
186+
"Unable to automatically resolve Neverwinter Nights home and/or installation directories.",
182187
);
183188
}
184-
if (line.includes("Unable to read input file")) {
185-
if (Boolean(nwnHome) || Boolean(nwnInstallation)) {
186-
return this.server.logger.error(
187-
"Unable to resolve provided Neverwinter Nights home and/or installation directories. Ensure the paths are valid in the extension settings.",
188-
);
189-
} else {
190-
return this.server.logger.error(
191-
"Unable to automatically resolve Neverwinter Nights home and/or installation directories.",
192-
);
193-
}
194-
}
195-
});
196-
197-
if (verbose) {
198-
this.server.logger.info("Done.\n");
199189
}
190+
});
191+
192+
if (verbose) {
193+
this.server.logger.info("Done.\n");
194+
}
200195

201-
uris.push(document.uri);
202-
errors.forEach(this.generateDiagnostic(uris, files, DiagnosticSeverity.Error));
203-
warnings.forEach(this.generateDiagnostic(uris, files, DiagnosticSeverity.Warning));
196+
uris.push(document.uri);
197+
errors.forEach(this.generateDiagnostics(uris, files, DiagnosticSeverity.Error));
198+
if (reportWarnings) warnings.forEach(this.generateDiagnostics(uris, files, DiagnosticSeverity.Warning));
204199

205-
for (const [uri, diagnostics] of Object.entries(files)) {
206-
this.sendDiagnostics(uri, diagnostics);
207-
}
208-
resolve(true);
209-
} catch (e: any) {
210-
this.server.logger.error(e.message);
211-
reject(e);
200+
for (const [uri, diagnostics] of Object.entries(files)) {
201+
this.server.connection.sendDiagnostics({ uri, diagnostics });
212202
}
203+
resolve(true);
213204
});
214205
});
215206
};

server/src/Providers/DocumentFormattingProvider.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,18 @@ export default class DocumentFormattingProvider extends Provider {
1818
const {
1919
textDocument: { uri },
2020
} = params;
21-
const { enabled, ignoredGlobs, style, executable } = this.server.config.formatter;
21+
const { enabled, verbose, ignoredGlobs, style, executable } = this.server.config.formatter;
2222
const clangFormatter = new ClangFormatter(
2323
this.server.workspaceFilesSystem,
24+
enabled,
25+
verbose,
2426
ignoredGlobs,
2527
executable,
2628
style,
2729
this.server.logger,
2830
);
2931

30-
if (!enabled || clangFormatter.isIgnoredFile(uri)) {
31-
return undefined;
32-
}
33-
3432
const liveDocument = this.server.liveDocumentsManager.get(uri);
35-
3633
if (liveDocument) {
3734
return await clangFormatter.formatDocument(liveDocument, null);
3835
}

server/src/Providers/DocumentRangeFormattingProvider.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,18 @@ export default class DocumentRangeFormattingProvider extends Provider {
1919
textDocument: { uri },
2020
range,
2121
} = params;
22-
const { enabled, ignoredGlobs, style, executable } = this.server.config.formatter;
22+
const { enabled, verbose, ignoredGlobs, style, executable } = this.server.config.formatter;
2323
const clangFormatter = new ClangFormatter(
2424
this.server.workspaceFilesSystem,
25+
enabled,
26+
verbose,
2527
ignoredGlobs,
2628
executable,
2729
style,
2830
this.server.logger,
2931
);
3032

31-
if (!enabled || clangFormatter.isIgnoredFile(uri)) {
32-
return undefined;
33-
}
34-
3533
const liveDocument = this.server.liveDocumentsManager.get(uri);
36-
3734
if (liveDocument) {
3835
return await clangFormatter.formatDocument(liveDocument, range);
3936
}

0 commit comments

Comments
 (0)