Skip to content

Commit adacb68

Browse files
authored
Add root-file setting. (#83)
Add a new optional `Root File` setting to control the FASTBuild root `fbuild.bff` file. The root file normally does not need to be specified in the settings because it is detected automatically when it is in a parent directory. But it is necessary to set when invoking FASTBuild with the `-config <path>` command line option, which overrides the root file. For example, if you have the following files and run FASTBuild with `fbuild -config <workspace_root>/Projects/fbuild.bff`: ``` <workspace_root>/Projects/fbuild.bff <workspace_root>/Projects/HelloWorld/HelloWorld.bff <workspace_root>/External/MSVC/MSVC.bff ``` In this example, `MSVC.bff` by default cannot find the root `fbuild.bff`. So it is necessary to use the `Root File` setting to manually specify the root. This new setting is the first that the user can set to an invalid value (an invalid path). Handle that by adding settings validation and output of settings-error diagnostics. This is also the first time that changing a setting can invalidate already-evaluated data. So clear the cached results when the settings change. Now that getting the root file relies on settings, which arrives async, various other functions need to also become async. Fixes #82.
1 parent 52c4821 commit adacb68

File tree

5 files changed

+204
-63
lines changed

5 files changed

+204
-63
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# v0.16.0
2+
3+
## New Features
4+
5+
* ([#82](https://github.com/harrisont/fastbuild-vscode/issues/82)) Add a new optional `Root File` setting to control the FASTBuild root `fbuild.bff` file. The root file normally does not need to be specified in the settings because it is detected automatically when it is in a parent directory. But it is necessary to set when invoking FASTBuild with the `-config <path>` command line option, which overrides the root file.
6+
7+
For example, if you have the following files and run FASTBuild with `fbuild -config <workspace_root>/Projects/fbuild.bff`:
8+
```
9+
<workspace_root>/Projects/fbuild.bff
10+
<workspace_root>/Projects/HelloWorld/HelloWorld.bff
11+
<workspace_root>/External/MSVC/MSVC.bff
12+
```
13+
In this example, `MSVC.bff` by default cannot find the root `fbuild.bff`. So it is necessary to use the `Root File` setting to manually specify the root.
14+
115
# v0.15.0
216

317
## New Features

package.json

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "fastbuild-support",
33
"displayName": "FASTBuild Support",
44
"description": "FASTBuild language support. Includes go-to definition, find references, variable evaluation, syntax errors, etc.",
5-
"version": "0.15.0",
5+
"version": "0.16.0",
66
"preview": true,
77
"publisher": "HarrisonT",
88
"author": {
@@ -52,7 +52,23 @@
5252
"type": "object",
5353
"title": "FASTBuild",
5454
"properties": {
55+
"fastbuild.inputDebounceDelay": {
56+
"order": 0,
57+
"scope": "window",
58+
"type": "number",
59+
"minimum": 0,
60+
"default": 500,
61+
"description": "Delay, in milliseconds, after changing a document before re-evaluating it. A lower value can result in faster feedback, but too low of a value will result in high resource usage when typing quickly."
62+
},
63+
"fastbuild.rootFile": {
64+
"order": 1,
65+
"scope": "window",
66+
"type": "string",
67+
"default": "",
68+
"markdownDescription": "Optional absolute path to the root `fbuild.bff` file. Set when running FASTBuild with the `-config <path>` command line option. The root is automatically found when it is in a parent directory, so it is not necessary to specify in that case."
69+
},
5570
"fastbuild.trace.server": {
71+
"order": 2,
5672
"scope": "window",
5773
"type": "string",
5874
"enum": [
@@ -69,17 +85,11 @@
6985
"description": "[Extension debugging] Traces the communication between the extension and the language server."
7086
},
7187
"fastbuild.logPerformanceMetrics": {
88+
"order": 3,
7289
"scope": "window",
7390
"type": "boolean",
7491
"default": false,
7592
"description": "[Extension debugging] Log performance metrics."
76-
},
77-
"fastbuild.inputDebounceDelay": {
78-
"scope": "window",
79-
"type": "number",
80-
"minimum": 0,
81-
"default": 500,
82-
"description": "Delay, in milliseconds, after changing a document before re-evaluating it. A lower value can result in faster feedback, but too low of a value will result in high resource usage when typing quickly."
8393
}
8494
}
8595
}

server/src/features/diagnosticProvider.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import {
2020
InternalEvaluationError,
2121
} from '../evaluator';
2222

23+
import {
24+
SettingsError
25+
} from '../settings';
26+
2327
const SOURCE_NAME = 'FASTBuild';
2428

2529
type UriStr = string;
@@ -52,14 +56,24 @@ function convertErrorRelatedInformation(info: ErrorRelatedInformation): Diagnost
5256
};
5357
}
5458

59+
// The settings are not a URI that we know, so just use a made-up URI.
60+
const SETTINGS_URI = "Settings";
61+
5562
export class DiagnosticProvider {
5663
hasDiagnosticRelatedInformationCapability = false;
5764
readonly _documentRootToDocumentsWithDiagnosticsMap = new Map<UriStr, Set<UriStr>>();
5865

66+
setSettingsErrorDiagnostic(errors: SettingsError[], connection: Connection): void {
67+
const range: Range = Range.create(0, 0, 0, 0);
68+
const relatedInformation: DiagnosticRelatedInformation[] = [];
69+
const diagnostics = errors.map(error => createDiagnosticError(error.message, range, relatedInformation));
70+
connection.sendDiagnostics({ uri: SETTINGS_URI, diagnostics });
71+
}
72+
5973
setParseErrorDiagnostic(rootUri: UriStr, error: ParseError, connection: Connection): void {
6074
const relatedInformation: DiagnosticRelatedInformation[] = [];
6175
const diagnostic = createDiagnosticError(error.message, error.range, relatedInformation);
62-
this._setDiagnostic(rootUri, error.fileUri, [diagnostic], connection);
76+
this._setFileDiagnostic(rootUri, error.fileUri, [diagnostic], connection);
6377
}
6478

6579
setEvaluationErrorDiagnostic(rootUri: UriStr, errors: EvaluationError[], connection: Connection): void {
@@ -82,7 +96,7 @@ export class DiagnosticProvider {
8296
}
8397

8498
for (const [uri, diagnostics] of uriToDiagnostics) {
85-
this._setDiagnostic(rootUri, uri, diagnostics, connection);
99+
this._setFileDiagnostic(rootUri, uri, diagnostics, connection);
86100
}
87101
}
88102

@@ -92,10 +106,10 @@ export class DiagnosticProvider {
92106
const message = `Internal error: ${error.stack ?? error.message}`;
93107
const relatedInformation: DiagnosticRelatedInformation[] = [];
94108
const diagnostic = createDiagnosticError(message, Range.create(0, 0, 0, 0), relatedInformation);
95-
this._setDiagnostic(rootUri, uri, [diagnostic], connection);
109+
this._setFileDiagnostic(rootUri, uri, [diagnostic], connection);
96110
}
97111

98-
private _setDiagnostic(rootUri: UriStr, uri: UriStr, diagnostics: Diagnostic[], connection: Connection): void {
112+
private _setFileDiagnostic(rootUri: UriStr, uri: UriStr, diagnostics: Diagnostic[], connection: Connection): void {
99113
const publishDiagnosticsParams: PublishDiagnosticsParams = { uri, diagnostics };
100114
connection.sendDiagnostics(publishDiagnosticsParams);
101115
const documentsForRoot = this._documentRootToDocumentsWithDiagnosticsMap.get(rootUri);
@@ -107,13 +121,19 @@ export class DiagnosticProvider {
107121
}
108122

109123
clearDiagnostics(connection: Connection): void {
124+
this.clearSettingsDiagnostics(connection);
125+
110126
for (const documentsForRoot of this._documentRootToDocumentsWithDiagnosticsMap.values()) {
111127
for (const uri of documentsForRoot) {
112128
connection.sendDiagnostics({ uri, diagnostics: [] });
113129
}
114130
}
115131
}
116132

133+
clearSettingsDiagnostics(connection: Connection): void {
134+
connection.sendDiagnostics({ uri: SETTINGS_URI, diagnostics: [] });
135+
}
136+
117137
clearDiagnosticsForRoot(rootUri: UriStr, connection: Connection): void {
118138
const documentsForRoot = this._documentRootToDocumentsWithDiagnosticsMap.get(rootUri);
119139
if (documentsForRoot === undefined) {

0 commit comments

Comments
 (0)