Skip to content

Commit 62514ce

Browse files
committed
Add diagnostics provider
1 parent 1dcf6c0 commit 62514ce

File tree

19 files changed

+369
-37
lines changed

19 files changed

+369
-37
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ tsconfig.tsbuildinfo
66
test/
77
server/resources/nwscript.nss
88
yarn-error.log
9-
.DS_Store
9+
.DS_Store
10+
TODO.txt

.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ test/**
1111
server/resources/nwscript.nss
1212
server/scripts
1313
images/**
14+
TODO.txt

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ All notable changes to the "nwscript-ee-language-server" extension will be docum
2222
- Is now performed in background, which means it is not blocking other features of the LSP.
2323
- Is now clustered - the number of processes depends on the number of cores on your machine.
2424
- Is now incremental, which means a file will be available as soon as it is indexed.
25+
26+
## [1.4.0]
27+
28+
- New provider: [Diagnostics](https://code.visualstudio.com/api/language-extensions/programmatic-language-features#provide-diagnostics).

README.md

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ While it seems to work well, even in bigger and older code bases, it is still an
1010

1111
[clang-format](https://clang.llvm.org/docs/ClangFormat.html).
1212

13+
### Diagnostics
14+
15+
Neverwinter Nights home and installation folders.
16+
1317
## Usage
1418

1519
Simply open a project with nss files and the extension installed. The extension will index your files and you will be ready to go - it can currently take up to 10-15 seconds to index big projects.
@@ -25,31 +29,31 @@ Notes:
2529

2630
```
2731
{
28-
"editor.formatOnSave": true,
29-
"files.associations": {
30-
"*.nss": "nwscript"
31-
},
32-
"[nwscript]": {
33-
"editor.defaultFormatter": "PhilippeChab.nwscript-ee-language-server"
34-
},
35-
"nwscript-ee-lsp.formatter": {
36-
"enabled": true,
37-
"executable": "clang-format",
38-
"ignoredGlobs": ["/folder/to/ignore/*.nss", "file/to/ignore/filename.nss"],
39-
"style": {
40-
"BasedOnStyle": "Google",
41-
"AlignTrailingComments": true,
42-
"AlignConsecutiveAssignments": true,
43-
"ColumnLimit": 250,
44-
"BreakBeforeBraces": "Allman",
45-
"AlignEscapedNewlinesLeft": true,
46-
"AlwaysBreakBeforeMultilineStrings": true,
47-
"MaxEmptyLinesToKeep": 1,
48-
"TabWidth": 4,
49-
"IndentWidth": 4,
50-
"UseTab": "Always"
51-
}
32+
"editor.formatOnSave": true,
33+
"files.associations": {
34+
"*.nss": "nwscript"
35+
},
36+
"[nwscript]": {
37+
"editor.defaultFormatter": "PhilippeChab.nwscript-ee-language-server"
38+
},
39+
"nwscript-ee-lsp.formatter": {
40+
"enabled": true,
41+
"executable": "clang-format",
42+
"ignoredGlobs": ["/folder/to/ignore/*.nss", "file/to/ignore/filename.nss"],
43+
"style": {
44+
"BasedOnStyle": "Google",
45+
"AlignTrailingComments": true,
46+
"AlignConsecutiveAssignments": true,
47+
"ColumnLimit": 250,
48+
"BreakBeforeBraces": "Allman",
49+
"AlignEscapedNewlinesLeft": true,
50+
"AlwaysBreakBeforeMultilineStrings": true,
51+
"MaxEmptyLinesToKeep": 1,
52+
"TabWidth": 4,
53+
"IndentWidth": 4,
54+
"UseTab": "Always"
5255
}
56+
}
5357
}
5458
```
5559

@@ -58,6 +62,28 @@ Notes:
5862
- The executable setting must either bet set to you path executable's identifier, or its absolute path.
5963
- The style object must respect clang-format [rules](https://clang.llvm.org/docs/ClangFormatStyleOptions.html).
6064

65+
### Diagnostics
66+
67+
```
68+
{
69+
"nwscript-ee-lsp.compiler": {
70+
"enabled": true,
71+
"verbose": false,
72+
"nwnHome": "C:\\Users\\YOUR_USERNAME\\Documents\\Neverwinter Nights",
73+
"nwnInstallation": "D:\\Program Files (x86)\\Steam\\steamapps\\common\\Neverwinter Nights"
74+
}
75+
}
76+
```
77+
78+
Notes:
79+
80+
- Diagnostics are provided by compiling the file with the [nwnsc](https://github.com/nwneetools/nwnsc) executable.
81+
- The compiler executable is provided for Windows, Darwin and Linux operating systems.
82+
- By default, the compiler will try to detect automatically your Neverwinter Nights home and installation folders if they are not specified. If it fails to do so, you can provide the paths in the extension settings like shown above - input paths are wrapped into quotes automatically.
83+
- In order to compile a file's includes, the compiler needs to know their directories. Files that had been requested a diagnostic while the project is being indexed are queued and processed once the indexing is done.
84+
- You can set the `verbose` setting to `true` if you wish to see detailed logs of the compilation process.
85+
- Big files with a lot of includes can take between half a second to a second to compile on older machines - it will not affect the client performances as the processing is done on the server.
86+
6187
## Features
6288

6389
Enhanced syntax highlighting - the following example is with the [One Dark Pro](https://marketplace.visualstudio.com/items?itemName=zhuangtongfa.Material-theme) theme:
@@ -81,6 +107,7 @@ Also:
81107
- Formatting
82108
- Range formatting
83109
- Signature help
110+
- Diagnostics
84111

85112
## Building and running
86113

package.json

Lines changed: 27 additions & 2 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.3.2",
11+
"version": "1.4.0",
1212
"author": {
1313
"name": "Philippe Chabot"
1414
},
@@ -86,7 +86,7 @@
8686
"type": "string"
8787
}
8888
},
89-
"nwscript-formatter.style": {
89+
"style": {
9090
"type": "object",
9191
"default": {
9292
"BasedOnStyle": "Google",
@@ -104,6 +104,31 @@
104104
"description": "Style for the formatter."
105105
}
106106
}
107+
},
108+
"nwscript-ee-lsp.compiler": {
109+
"type": "object",
110+
"properties": {
111+
"enabled": {
112+
"type": "boolean",
113+
"default": true,
114+
"description": "Whether the compiler is enabled or not."
115+
},
116+
"verbose": {
117+
"type": "boolean",
118+
"default": false,
119+
"description": "Print the compilation result in the output console."
120+
},
121+
"nwnHome": {
122+
"type": "string",
123+
"default": "",
124+
"description": "Your Neverwinter Nights home directory."
125+
},
126+
"nwnInstallation": {
127+
"type": "string",
128+
"default": "",
129+
"description": "Your Neverwinter Nights installation directory."
130+
}
131+
}
107132
}
108133
}
109134
}

server/resources/compiler/linux/nwnsc

12.4 MB
Binary file not shown.

server/resources/compiler/mac/nwnsc

1.84 MB
Binary file not shown.
860 KB
Binary file not shown.

server/src/Documents/Document.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { WorkspaceFilesSystem } from "../WorkspaceFilesSystem";
22
import type { ComplexToken, StructComplexToken } from "../Tokenizer/types";
33
import type DocumentsCollection from "./DocumentsCollection";
4+
import { Diagnostic } from "vscode-languageserver";
45

56
export type OwnedComplexTokens = { owner: string; tokens: ComplexToken[] };
67
export type OwnedStructComplexTokens = { owner: string; tokens: StructComplexToken[] };
@@ -18,6 +19,27 @@ export default class Document {
1819
return WorkspaceFilesSystem.getFileBasename(this.path);
1920
}
2021

22+
public getChildren(computedChildren: string[] = []): string[] {
23+
return this.children.concat(
24+
this.children.flatMap((child) => {
25+
// Cycling children or/and duplicates
26+
if (computedChildren.includes(child)) {
27+
return [];
28+
} else {
29+
computedChildren.push(child);
30+
}
31+
32+
const childDocument = this.collection.get(child);
33+
34+
if (!childDocument) {
35+
return [];
36+
}
37+
38+
return childDocument.getChildren(computedChildren);
39+
})
40+
);
41+
}
42+
2143
public getGlobalComplexTokensWithRef(computedChildren: string[] = []): OwnedComplexTokens[] {
2244
return [{ owner: this.path, tokens: this.complexTokens }].concat(
2345
this.children.flatMap((child) => {

server/src/Documents/DocumentsCollection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { GlobalScopeTokenizationResult, TokenizedScope } from "../Tokenizer/Toke
66
import { Dictionnary } from "../Utils";
77
import { WorkspaceFilesSystem } from "../WorkspaceFilesSystem";
88
import Document from "./Document";
9+
import { TextDocument } from "vscode-languageserver-textdocument";
910

1011
export default class DocumentsCollection extends Dictionnary<string, Document> {
1112
public readonly standardLibComplexTokens: ComplexToken[] = [];
@@ -34,10 +35,9 @@ export default class DocumentsCollection extends Dictionnary<string, Document> {
3435
this.addDocument(this.initializeDocument(filePath, globalScope));
3536
}
3637

37-
public updateDocument(uri: string, tokenizer: Tokenizer) {
38-
const filePath = WorkspaceFilesSystem.fileUriToPath(uri);
39-
const fileContent = WorkspaceFilesSystem.readFileSync(filePath).toString();
40-
const globalScope = tokenizer.tokenizeContent(fileContent, TokenizedScope.global);
38+
public updateDocument(document: TextDocument, tokenizer: Tokenizer) {
39+
const filePath = WorkspaceFilesSystem.fileUriToPath(document.uri);
40+
const globalScope = tokenizer.tokenizeContent(document.getText(), TokenizedScope.global);
4141

4242
this.overwriteDocument(this.initializeDocument(filePath, globalScope));
4343
}

0 commit comments

Comments
 (0)