brighterscript 0.68.4 → 0.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/BusyStatusTracker.d.ts +37 -7
- package/dist/BusyStatusTracker.js +73 -8
- package/dist/BusyStatusTracker.js.map +1 -1
- package/dist/DiagnosticCollection.d.ts +19 -5
- package/dist/DiagnosticCollection.js +67 -16
- package/dist/DiagnosticCollection.js.map +1 -1
- package/dist/LanguageServer.d.ts +82 -132
- package/dist/LanguageServer.js +403 -940
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Logger.d.ts +9 -4
- package/dist/Logger.js +30 -6
- package/dist/Logger.js.map +1 -1
- package/dist/PluginInterface.d.ts +1 -1
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +20 -2
- package/dist/Program.js +124 -49
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +21 -7
- package/dist/ProgramBuilder.js +45 -22
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.js +6 -3
- package/dist/Scope.js.map +1 -1
- package/dist/SemanticTokenUtils.js +1 -1
- package/dist/SemanticTokenUtils.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.js +2 -1
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.js +14 -4
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.js +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.js +9 -9
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/common/Sequencer.d.ts +27 -0
- package/dist/common/Sequencer.js +113 -0
- package/dist/common/Sequencer.js.map +1 -0
- package/dist/common/Sequencer.spec.d.ts +1 -0
- package/dist/common/Sequencer.spec.js +75 -0
- package/dist/common/Sequencer.spec.js.map +1 -0
- package/dist/deferred.d.ts +2 -0
- package/dist/deferred.js +10 -0
- package/dist/deferred.js.map +1 -1
- package/dist/files/BrsFile.d.ts +1 -1
- package/dist/files/BrsFile.js +10 -15
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +8 -0
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/interfaces.d.ts +22 -2
- package/dist/lexer/Lexer.js +1 -1
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/logging.d.ts +6 -1
- package/dist/logging.js +14 -1
- package/dist/logging.js.map +1 -1
- package/dist/lsp/ActionQueue.d.ts +35 -0
- package/dist/lsp/ActionQueue.js +115 -0
- package/dist/lsp/ActionQueue.js.map +1 -0
- package/dist/lsp/ActionQueue.spec.d.ts +1 -0
- package/dist/lsp/ActionQueue.spec.js +80 -0
- package/dist/lsp/ActionQueue.spec.js.map +1 -0
- package/dist/lsp/DocumentManager.d.ts +63 -0
- package/dist/lsp/DocumentManager.js +122 -0
- package/dist/lsp/DocumentManager.js.map +1 -0
- package/dist/lsp/DocumentManager.spec.d.ts +1 -0
- package/dist/lsp/DocumentManager.spec.js +103 -0
- package/dist/lsp/DocumentManager.spec.js.map +1 -0
- package/dist/lsp/LspProject.d.ts +231 -0
- package/dist/lsp/LspProject.js +3 -0
- package/dist/lsp/LspProject.js.map +1 -0
- package/dist/lsp/PathFilterer.d.ts +75 -0
- package/dist/lsp/PathFilterer.js +196 -0
- package/dist/lsp/PathFilterer.js.map +1 -0
- package/dist/lsp/PathFilterer.spec.d.ts +1 -0
- package/dist/lsp/PathFilterer.spec.js +182 -0
- package/dist/lsp/PathFilterer.spec.js.map +1 -0
- package/dist/lsp/Project.d.ts +178 -0
- package/dist/lsp/Project.js +438 -0
- package/dist/lsp/Project.js.map +1 -0
- package/dist/lsp/Project.spec.d.ts +1 -0
- package/dist/lsp/Project.spec.js +236 -0
- package/dist/lsp/Project.spec.js.map +1 -0
- package/dist/lsp/ProjectManager.d.ts +221 -0
- package/dist/lsp/ProjectManager.js +735 -0
- package/dist/lsp/ProjectManager.js.map +1 -0
- package/dist/lsp/ProjectManager.spec.d.ts +1 -0
- package/dist/lsp/ProjectManager.spec.js +756 -0
- package/dist/lsp/ProjectManager.spec.js.map +1 -0
- package/dist/lsp/ReaderWriterManager.d.ts +21 -0
- package/dist/lsp/ReaderWriterManager.js +60 -0
- package/dist/lsp/ReaderWriterManager.js.map +1 -0
- package/dist/lsp/worker/MessageHandler.d.ts +99 -0
- package/dist/lsp/worker/MessageHandler.js +138 -0
- package/dist/lsp/worker/MessageHandler.js.map +1 -0
- package/dist/lsp/worker/MessageHandler.spec.d.ts +1 -0
- package/dist/lsp/worker/MessageHandler.spec.js +64 -0
- package/dist/lsp/worker/MessageHandler.spec.js.map +1 -0
- package/dist/lsp/worker/WorkerPool.d.ts +38 -0
- package/dist/lsp/worker/WorkerPool.js +78 -0
- package/dist/lsp/worker/WorkerPool.js.map +1 -0
- package/dist/lsp/worker/WorkerPool.spec.d.ts +1 -0
- package/dist/lsp/worker/WorkerPool.spec.js +59 -0
- package/dist/lsp/worker/WorkerPool.spec.js.map +1 -0
- package/dist/lsp/worker/WorkerThreadProject.d.ts +144 -0
- package/dist/lsp/worker/WorkerThreadProject.js +181 -0
- package/dist/lsp/worker/WorkerThreadProject.js.map +1 -0
- package/dist/lsp/worker/WorkerThreadProject.spec.d.ts +2 -0
- package/dist/lsp/worker/WorkerThreadProject.spec.js +68 -0
- package/dist/lsp/worker/WorkerThreadProject.spec.js.map +1 -0
- package/dist/lsp/worker/WorkerThreadProjectRunner.d.ts +15 -0
- package/dist/lsp/worker/WorkerThreadProjectRunner.js +58 -0
- package/dist/lsp/worker/WorkerThreadProjectRunner.js.map +1 -0
- package/dist/util.d.ts +31 -5
- package/dist/util.js +117 -19
- package/dist/util.js.map +1 -1
- package/package.json +11 -1
package/dist/LanguageServer.js
CHANGED
|
@@ -7,39 +7,29 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.NotificationName = exports.CustomCommands = exports.LanguageServer = void 0;
|
|
10
|
-
require("array-flat-polyfill");
|
|
11
|
-
const fastGlob = require("fast-glob");
|
|
12
10
|
const path = require("path");
|
|
13
|
-
|
|
11
|
+
require("array-flat-polyfill");
|
|
14
12
|
const node_1 = require("vscode-languageserver/node");
|
|
15
13
|
const vscode_uri_1 = require("vscode-uri");
|
|
16
14
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
17
|
-
const deferred_1 = require("./deferred");
|
|
18
|
-
const DiagnosticMessages_1 = require("./DiagnosticMessages");
|
|
19
|
-
const ProgramBuilder_1 = require("./ProgramBuilder");
|
|
20
15
|
const util_1 = require("./util");
|
|
21
|
-
const Throttler_1 = require("./Throttler");
|
|
22
|
-
const KeyedThrottler_1 = require("./KeyedThrottler");
|
|
23
16
|
const DiagnosticCollection_1 = require("./DiagnosticCollection");
|
|
24
|
-
const reflection_1 = require("./astUtils/reflection");
|
|
25
17
|
const SemanticTokenUtils_1 = require("./SemanticTokenUtils");
|
|
26
|
-
const BusyStatusTracker_1 = require("./BusyStatusTracker");
|
|
27
18
|
const logging_1 = require("./logging");
|
|
19
|
+
const ignore_1 = require("ignore");
|
|
20
|
+
const micromatch = require("micromatch");
|
|
21
|
+
const PathFilterer_1 = require("./lsp/PathFilterer");
|
|
22
|
+
const ProjectManager_1 = require("./lsp/ProjectManager");
|
|
23
|
+
const fsExtra = require("fs-extra");
|
|
24
|
+
const WorkerThreadProject_1 = require("./lsp/worker/WorkerThreadProject");
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
26
|
+
const isEqual = require("lodash.isequal");
|
|
28
27
|
class LanguageServer {
|
|
29
28
|
constructor() {
|
|
30
|
-
this.connection = undefined;
|
|
31
|
-
this.projects = [];
|
|
32
29
|
/**
|
|
33
|
-
* The
|
|
30
|
+
* The language server protocol connection, used to send and receive all requests and responses
|
|
34
31
|
*/
|
|
35
|
-
this.
|
|
36
|
-
/**
|
|
37
|
-
* These projects are created on the fly whenever a file is opened that is not included
|
|
38
|
-
* in any of the workspace-based projects.
|
|
39
|
-
* Basically these are single-file projects to at least get parsing for standalone files.
|
|
40
|
-
* Also, they should only be created when the file is opened, and destroyed when the file is closed.
|
|
41
|
-
*/
|
|
42
|
-
this.standaloneFileProjects = {};
|
|
32
|
+
this.connection = undefined;
|
|
43
33
|
this.hasConfigurationCapability = false;
|
|
44
34
|
/**
|
|
45
35
|
* Indicates whether the client supports workspace folders
|
|
@@ -50,98 +40,79 @@ class LanguageServer {
|
|
|
50
40
|
* The text document manager supports full document sync only
|
|
51
41
|
*/
|
|
52
42
|
this.documents = new node_1.TextDocuments(vscode_languageserver_textdocument_1.TextDocument);
|
|
53
|
-
this.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.
|
|
57
|
-
this.busyStatusTracker = new BusyStatusTracker_1.BusyStatusTracker();
|
|
43
|
+
this.logger = (0, logging_1.createLogger)({
|
|
44
|
+
logLevel: logging_1.LogLevel.log
|
|
45
|
+
});
|
|
46
|
+
this.workspaceConfigsCache = new Map();
|
|
58
47
|
this.busyStatusIndex = -1;
|
|
59
|
-
|
|
60
|
-
* A unique project counter to help distinguish log entries in lsp mode
|
|
61
|
-
*/
|
|
62
|
-
this.projectCounter = 0;
|
|
48
|
+
this.pathFiltererDisposables = [];
|
|
63
49
|
this.diagnosticCollection = new DiagnosticCollection_1.DiagnosticCollection();
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
50
|
+
(0, logging_1.setLspLoggerProps)();
|
|
51
|
+
//replace the workerPool logger with our own so logging info can be synced
|
|
52
|
+
WorkerThreadProject_1.workerPool.logger = this.logger.createLogger();
|
|
53
|
+
this.pathFilterer = new PathFilterer_1.PathFilterer({ logger: this.logger });
|
|
54
|
+
this.projectManager = new ProjectManager_1.ProjectManager({
|
|
55
|
+
pathFilterer: this.pathFilterer,
|
|
56
|
+
logger: this.logger.createLogger()
|
|
57
|
+
});
|
|
58
|
+
//anytime a project emits a collection of diagnostics, send them to the client
|
|
59
|
+
this.projectManager.on('diagnostics', (event) => {
|
|
60
|
+
this.logger.debug(`Received ${event.diagnostics.length} diagnostics from project ${event.project.projectNumber}`);
|
|
61
|
+
this.sendDiagnostics(event).catch(logAndIgnoreError);
|
|
62
|
+
});
|
|
63
|
+
// Send all open document changes whenever a project is activated. This is necessary because at project startup, the project loads files from disk
|
|
64
|
+
// and may not have the latest unsaved file changes. Any existing projects that already use these files will just ignore the changes
|
|
65
|
+
// because the file contents haven't changed.
|
|
66
|
+
this.projectManager.on('project-activate', (event) => {
|
|
67
|
+
var _a;
|
|
68
|
+
//keep logLevel in sync with the most verbose log level found across all projects
|
|
69
|
+
this.syncLogLevel().catch(logAndIgnoreError);
|
|
70
|
+
//resend all open document changes
|
|
71
|
+
const documents = [...this.documents.all()];
|
|
72
|
+
if (documents.length > 0) {
|
|
73
|
+
this.logger.log(`[${(_a = event.project) === null || _a === void 0 ? void 0 : _a.projectIdentifier}] loaded or changed. Resending all open document changes.`, documents.map(x => x.uri));
|
|
74
|
+
for (const document of this.documents.all()) {
|
|
75
|
+
this.onTextDocumentDidChangeContent({
|
|
76
|
+
document: document
|
|
77
|
+
}).catch(logAndIgnoreError);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
this.projectManager.busyStatusTracker.on('active-runs-change', (event) => {
|
|
82
|
+
this.sendBusyStatus();
|
|
83
|
+
});
|
|
70
84
|
}
|
|
71
85
|
//run the server
|
|
72
86
|
run() {
|
|
87
|
+
var _a;
|
|
73
88
|
// Create a connection for the server. The connection uses Node's IPC as a transport.
|
|
74
|
-
|
|
75
|
-
this.connection = this.createConnection();
|
|
76
|
-
// Send the current status of the busyStatusTracker anytime it changes
|
|
77
|
-
this.busyStatusTracker.on('change', (status) => {
|
|
78
|
-
void this.sendBusyStatus(status);
|
|
79
|
-
});
|
|
89
|
+
this.connection = this.establishConnection();
|
|
80
90
|
//disable logger colors when running in LSP mode
|
|
81
91
|
logging_1.logger.enableColor = false;
|
|
82
92
|
//listen to all of the output log events and pipe them into the debug channel in the extension
|
|
83
93
|
this.loggerSubscription = logging_1.logger.subscribe((message) => {
|
|
84
94
|
this.connection.tracer.log(message.argsText);
|
|
85
95
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
//bind all our on* methods that share the same name from connection
|
|
97
|
+
for (const name of Object.getOwnPropertyNames(LanguageServer.prototype)) {
|
|
98
|
+
if (/on+/.test(name) && typeof ((_a = this.connection) === null || _a === void 0 ? void 0 : _a[name]) === 'function') {
|
|
99
|
+
this.connection[name](this[name].bind(this));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//Register semantic token requests. TODO switch to a more specific connection function call once they actually add it
|
|
103
|
+
this.connection.onRequest(node_1.SemanticTokensRequest.method, this.onFullSemanticTokens.bind(this));
|
|
90
104
|
// The content of a text document has changed. This event is emitted
|
|
91
105
|
// when the text document is first opened, when its content has changed,
|
|
92
106
|
// or when document is closed without saving (original contents are sent as a change)
|
|
93
107
|
//
|
|
94
|
-
this.documents.onDidChangeContent(this.
|
|
108
|
+
this.documents.onDidChangeContent(this.onTextDocumentDidChangeContent.bind(this));
|
|
95
109
|
//whenever a document gets closed
|
|
96
110
|
this.documents.onDidClose(this.onDocumentClose.bind(this));
|
|
97
|
-
// This handler provides the initial list of the completion items.
|
|
98
|
-
this.connection.onCompletion(this.onCompletion.bind(this));
|
|
99
|
-
// This handler resolves additional information for the item selected in
|
|
100
|
-
// the completion list.
|
|
101
|
-
this.connection.onCompletionResolve(this.onCompletionResolve.bind(this));
|
|
102
|
-
this.connection.onHover(this.onHover.bind(this));
|
|
103
|
-
this.connection.onExecuteCommand(this.onExecuteCommand.bind(this));
|
|
104
|
-
this.connection.onDefinition(this.onDefinition.bind(this));
|
|
105
|
-
this.connection.onDocumentSymbol(this.onDocumentSymbol.bind(this));
|
|
106
|
-
this.connection.onWorkspaceSymbol(this.onWorkspaceSymbol.bind(this));
|
|
107
|
-
this.connection.onSignatureHelp(this.onSignatureHelp.bind(this));
|
|
108
|
-
this.connection.onReferences(this.onReferences.bind(this));
|
|
109
|
-
this.connection.onCodeAction(this.onCodeAction.bind(this));
|
|
110
|
-
//TODO switch to a more specific connection function call once they actually add it
|
|
111
|
-
this.connection.onRequest(node_1.SemanticTokensRequest.method, this.onFullSemanticTokens.bind(this));
|
|
112
|
-
/*
|
|
113
|
-
this.connection.onDidOpenTextDocument((params) => {
|
|
114
|
-
// A text document got opened in VSCode.
|
|
115
|
-
// params.uri uniquely identifies the document. For documents stored on disk this is a file URI.
|
|
116
|
-
// params.text the initial full content of the document.
|
|
117
|
-
this.connection.console.log(`${params.textDocument.uri} opened.`);
|
|
118
|
-
});
|
|
119
|
-
this.connection.onDidChangeTextDocument((params) => {
|
|
120
|
-
// The content of a text document did change in VSCode.
|
|
121
|
-
// params.uri uniquely identifies the document.
|
|
122
|
-
// params.contentChanges describe the content changes to the document.
|
|
123
|
-
this.connection.console.log(`${params.textDocument.uri} changed: ${JSON.stringify(params.contentChanges)}`);
|
|
124
|
-
});
|
|
125
|
-
this.connection.onDidCloseTextDocument((params) => {
|
|
126
|
-
// A text document got closed in VSCode.
|
|
127
|
-
// params.uri uniquely identifies the document.
|
|
128
|
-
this.connection.console.log(`${params.textDocument.uri} closed.`);
|
|
129
|
-
});
|
|
130
|
-
*/
|
|
131
111
|
// listen for open, change and close text document events
|
|
132
112
|
this.documents.listen(this.connection);
|
|
133
113
|
// Listen on the connection
|
|
134
114
|
this.connection.listen();
|
|
135
115
|
}
|
|
136
|
-
async sendBusyStatus(status) {
|
|
137
|
-
this.busyStatusIndex = ++this.busyStatusIndex <= 0 ? 0 : this.busyStatusIndex;
|
|
138
|
-
await this.connection.sendNotification(NotificationName.busyStatus, {
|
|
139
|
-
status: status,
|
|
140
|
-
timestamp: Date.now(),
|
|
141
|
-
index: this.busyStatusIndex,
|
|
142
|
-
activeRuns: [...this.busyStatusTracker.activeRuns]
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
116
|
/**
|
|
146
117
|
* Called when the client starts initialization
|
|
147
118
|
*/
|
|
@@ -157,7 +128,7 @@ class LanguageServer {
|
|
|
157
128
|
textDocumentSync: node_1.TextDocumentSyncKind.Full,
|
|
158
129
|
// Tell the client that the server supports code completion
|
|
159
130
|
completionProvider: {
|
|
160
|
-
resolveProvider:
|
|
131
|
+
resolveProvider: false,
|
|
161
132
|
//anytime the user types a period, auto-show the completion results
|
|
162
133
|
triggerCharacters: ['.'],
|
|
163
134
|
allCommitCharacters: ['.', '@']
|
|
@@ -185,146 +156,38 @@ class LanguageServer {
|
|
|
185
156
|
}
|
|
186
157
|
};
|
|
187
158
|
}
|
|
188
|
-
/**
|
|
189
|
-
* Ask the client for the list of `files.exclude` patterns. Useful when determining if we should process a file
|
|
190
|
-
*/
|
|
191
|
-
async getWorkspaceExcludeGlobs(workspaceFolder) {
|
|
192
|
-
var _a;
|
|
193
|
-
let config = {
|
|
194
|
-
exclude: {}
|
|
195
|
-
};
|
|
196
|
-
//if supported, ask vscode for the `files.exclude` configuration
|
|
197
|
-
if (this.hasConfigurationCapability) {
|
|
198
|
-
//get any `files.exclude` globs to use to filter
|
|
199
|
-
config = await this.connection.workspace.getConfiguration({
|
|
200
|
-
scopeUri: workspaceFolder,
|
|
201
|
-
section: 'files'
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
return Object
|
|
205
|
-
.keys((_a = config === null || config === void 0 ? void 0 : config.exclude) !== null && _a !== void 0 ? _a : {})
|
|
206
|
-
.filter(x => { var _a; return (_a = config === null || config === void 0 ? void 0 : config.exclude) === null || _a === void 0 ? void 0 : _a[x]; })
|
|
207
|
-
//vscode files.exclude patterns support ignoring folders without needing to add `**/*`. So for our purposes, we need to
|
|
208
|
-
//append **/* to everything without a file extension or magic at the end
|
|
209
|
-
.map(pattern => [
|
|
210
|
-
//send the pattern as-is (this handles weird cases and exact file matches)
|
|
211
|
-
pattern,
|
|
212
|
-
//treat the pattern as a directory (no harm in doing this because if it's a file, the pattern will just never match anything)
|
|
213
|
-
`${pattern}/**/*`
|
|
214
|
-
])
|
|
215
|
-
.flat(1)
|
|
216
|
-
.concat([
|
|
217
|
-
//always ignore projects from node_modules
|
|
218
|
-
'**/node_modules/**/*'
|
|
219
|
-
]);
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Scan the workspace for all `bsconfig.json` files. If at least one is found, then only folders who have bsconfig.json are returned.
|
|
223
|
-
* If none are found, then the workspaceFolder itself is treated as a project
|
|
224
|
-
*/
|
|
225
|
-
async getProjectPaths(workspaceFolder) {
|
|
226
|
-
const excludes = (await this.getWorkspaceExcludeGlobs(workspaceFolder)).map(x => (0, util_1.standardizePath) `!${x}`);
|
|
227
|
-
const files = await roku_deploy_1.rokuDeploy.getFilePaths([
|
|
228
|
-
'**/bsconfig.json',
|
|
229
|
-
//exclude all files found in `files.exclude`
|
|
230
|
-
...excludes
|
|
231
|
-
], workspaceFolder);
|
|
232
|
-
//if we found at least one bsconfig.json, then ALL projects must have a bsconfig.json.
|
|
233
|
-
if (files.length > 0) {
|
|
234
|
-
return files.map(file => (0, util_1.standardizePath) `${path.dirname(file.src)}`);
|
|
235
|
-
}
|
|
236
|
-
//look for roku project folders
|
|
237
|
-
const rokuLikeDirs = (await Promise.all(
|
|
238
|
-
//find all folders containing a `manifest` file
|
|
239
|
-
(await roku_deploy_1.rokuDeploy.getFilePaths([
|
|
240
|
-
'**/manifest',
|
|
241
|
-
...excludes
|
|
242
|
-
//is there at least one .bs|.brs file under the `/source` folder?
|
|
243
|
-
], workspaceFolder)).map(async (manifestEntry) => {
|
|
244
|
-
const manifestDir = path.dirname(manifestEntry.src);
|
|
245
|
-
const files = await roku_deploy_1.rokuDeploy.getFilePaths([
|
|
246
|
-
'source/**/*.{brs,bs}',
|
|
247
|
-
...excludes
|
|
248
|
-
], manifestDir);
|
|
249
|
-
if (files.length > 0) {
|
|
250
|
-
return manifestDir;
|
|
251
|
-
}
|
|
252
|
-
})
|
|
253
|
-
//throw out nulls
|
|
254
|
-
)).filter(x => !!x);
|
|
255
|
-
if (rokuLikeDirs.length > 0) {
|
|
256
|
-
return rokuLikeDirs;
|
|
257
|
-
}
|
|
258
|
-
//treat the workspace folder as a brightscript project itself
|
|
259
|
-
return [workspaceFolder];
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Find all folders with bsconfig.json files in them, and treat each as a project.
|
|
263
|
-
* Treat workspaces that don't have a bsconfig.json as a project.
|
|
264
|
-
* Handle situations where bsconfig.json files were added or removed (to elevate/lower workspaceFolder projects accordingly)
|
|
265
|
-
* Leave existing projects alone if they are not affected by these changes
|
|
266
|
-
*/
|
|
267
|
-
async syncProjects() {
|
|
268
|
-
const workspacePaths = await this.getWorkspacePaths();
|
|
269
|
-
let projectPaths = (await Promise.all(workspacePaths.map(async (workspacePath) => {
|
|
270
|
-
const projectPaths = await this.getProjectPaths(workspacePath);
|
|
271
|
-
return projectPaths.map(projectPath => ({
|
|
272
|
-
projectPath: projectPath,
|
|
273
|
-
workspacePath: workspacePath
|
|
274
|
-
}));
|
|
275
|
-
}))).flat(1);
|
|
276
|
-
//delete projects not represented in the list
|
|
277
|
-
for (const project of this.getProjects()) {
|
|
278
|
-
if (!projectPaths.find(x => x.projectPath === project.projectPath)) {
|
|
279
|
-
this.removeProject(project);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
//exclude paths to projects we already have
|
|
283
|
-
projectPaths = projectPaths.filter(x => {
|
|
284
|
-
//only keep this project path if there's not a project with that path
|
|
285
|
-
return !this.projects.find(project => project.projectPath === x.projectPath);
|
|
286
|
-
});
|
|
287
|
-
//dedupe by project path
|
|
288
|
-
projectPaths = [
|
|
289
|
-
...projectPaths.reduce((acc, x) => acc.set(x.projectPath, x), new Map()).values()
|
|
290
|
-
];
|
|
291
|
-
//create missing projects
|
|
292
|
-
await Promise.all(projectPaths.map(x => this.createProject(x.projectPath, x.workspacePath)));
|
|
293
|
-
//flush diagnostics
|
|
294
|
-
await this.sendDiagnostics();
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Get all workspace paths from the client
|
|
298
|
-
*/
|
|
299
|
-
async getWorkspacePaths() {
|
|
300
|
-
var _a;
|
|
301
|
-
let workspaceFolders = (_a = await this.connection.workspace.getWorkspaceFolders()) !== null && _a !== void 0 ? _a : [];
|
|
302
|
-
return workspaceFolders.map((x) => {
|
|
303
|
-
return util_1.util.uriToPath(x.uri);
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
159
|
/**
|
|
307
160
|
* Called when the client has finished initializing
|
|
308
161
|
*/
|
|
309
162
|
async onInitialized() {
|
|
310
|
-
|
|
311
|
-
|
|
163
|
+
this.logger.log('onInitialized');
|
|
164
|
+
//cache a copy of all workspace configurations to use for comparison later
|
|
165
|
+
this.workspaceConfigsCache = new Map((await this.getWorkspaceConfigs()).map(x => [x.workspaceFolder, x]));
|
|
166
|
+
//set our logger to the most verbose logLevel found across any project
|
|
167
|
+
await this.syncLogLevel();
|
|
312
168
|
try {
|
|
313
169
|
if (this.hasConfigurationCapability) {
|
|
314
|
-
//
|
|
315
|
-
await this.connection.client.register(node_1.DidChangeConfigurationNotification.type,
|
|
170
|
+
// register for when the user changes workspace or user settings
|
|
171
|
+
await this.connection.client.register(node_1.DidChangeConfigurationNotification.type, {
|
|
172
|
+
//we only care about when these settings sections change
|
|
173
|
+
section: [
|
|
174
|
+
'brightscript',
|
|
175
|
+
'files'
|
|
176
|
+
]
|
|
177
|
+
});
|
|
316
178
|
}
|
|
179
|
+
//populate the path filterer with the client's include/exclude lists
|
|
180
|
+
await this.rebuildPathFilterer();
|
|
317
181
|
await this.syncProjects();
|
|
318
182
|
if (this.clientHasWorkspaceFolderCapability) {
|
|
183
|
+
//if the client changes their workspaces, we need to get our projects in sync
|
|
319
184
|
this.connection.workspace.onDidChangeWorkspaceFolders(async (evt) => {
|
|
320
185
|
await this.syncProjects();
|
|
321
186
|
});
|
|
322
187
|
}
|
|
323
|
-
await this.waitAllProjectFirstRuns(false);
|
|
324
|
-
projectCreatedDeferred.resolve();
|
|
325
188
|
}
|
|
326
189
|
catch (e) {
|
|
327
|
-
|
|
190
|
+
this.sendCriticalFailure(`Critical failure during BrighterScript language server startup.
|
|
328
191
|
Please file a github issue and include the contents of the 'BrighterScript Language Server' output channel.
|
|
329
192
|
|
|
330
193
|
Error message: ${e.message}`);
|
|
@@ -332,364 +195,63 @@ class LanguageServer {
|
|
|
332
195
|
}
|
|
333
196
|
}
|
|
334
197
|
/**
|
|
335
|
-
*
|
|
336
|
-
*/
|
|
337
|
-
async sendCriticalFailure(message) {
|
|
338
|
-
await this.connection.sendNotification('critical-failure', message);
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Wait for all programs' first run to complete
|
|
198
|
+
* Set our logLevel to the most verbose log level found across all projects and workspaces
|
|
342
199
|
*/
|
|
343
|
-
async
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
200
|
+
async syncLogLevel() {
|
|
201
|
+
var _a, _b;
|
|
202
|
+
/**
|
|
203
|
+
* helper to get the logLevel from a list of items and return the item and level (if found), or undefined if not
|
|
204
|
+
*/
|
|
205
|
+
const getLogLevel = async (items, fetcher) => {
|
|
206
|
+
const logLevels = await Promise.all(items.map(async (item) => {
|
|
207
|
+
let value = await fetcher(item);
|
|
208
|
+
//force string values to lower case (so we can support things like 'log' or 'Log' or 'LOG')
|
|
209
|
+
if (typeof value === 'string') {
|
|
210
|
+
value = value.toLowerCase();
|
|
211
|
+
}
|
|
212
|
+
const logLevelNumeric = this.logger.getLogLevelNumeric(value);
|
|
213
|
+
if (typeof logLevelNumeric === 'number') {
|
|
214
|
+
return logLevelNumeric;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
return -1;
|
|
218
|
+
}
|
|
219
|
+
}));
|
|
220
|
+
let idx = logLevels.findIndex(x => x > -1);
|
|
221
|
+
if (idx > -1) {
|
|
222
|
+
const mostVerboseLogLevel = Math.max(...logLevels);
|
|
223
|
+
return {
|
|
224
|
+
logLevel: mostVerboseLogLevel,
|
|
225
|
+
logLevelText: this.logger.getLogLevelText(mostVerboseLogLevel),
|
|
226
|
+
//find the first item having the most verbose logLevel
|
|
227
|
+
item: items[logLevels.findIndex(x => x === mostVerboseLogLevel)]
|
|
228
|
+
};
|
|
356
229
|
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
/**
|
|
360
|
-
* Event handler for when the program wants to load file contents.
|
|
361
|
-
* anytime the program wants to load a file, check with our in-memory document cache first
|
|
362
|
-
*/
|
|
363
|
-
documentFileResolver(srcPath) {
|
|
364
|
-
let pathUri = vscode_uri_1.URI.file(srcPath).toString();
|
|
365
|
-
let document = this.documents.get(pathUri);
|
|
366
|
-
if (document) {
|
|
367
|
-
return document.getText();
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
async getConfigFilePath(workspacePath) {
|
|
371
|
-
let scopeUri;
|
|
372
|
-
if (workspacePath.startsWith('file:')) {
|
|
373
|
-
scopeUri = vscode_uri_1.URI.parse(workspacePath).toString();
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
scopeUri = vscode_uri_1.URI.file(workspacePath).toString();
|
|
377
|
-
}
|
|
378
|
-
let config = {
|
|
379
|
-
configFile: undefined
|
|
380
230
|
};
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
let configFilePath;
|
|
389
|
-
//if there's a setting, we need to find the file or show error if it can't be found
|
|
390
|
-
if (config === null || config === void 0 ? void 0 : config.configFile) {
|
|
391
|
-
configFilePath = path.resolve(workspacePath, config.configFile);
|
|
392
|
-
if (await util_1.util.pathExists(configFilePath)) {
|
|
393
|
-
return configFilePath;
|
|
394
|
-
}
|
|
395
|
-
else {
|
|
396
|
-
await this.sendCriticalFailure(`Cannot find config file specified in user / workspace settings at '${configFilePath}'`);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
//default to config file path found in the root of the workspace
|
|
400
|
-
configFilePath = path.resolve(workspacePath, 'bsconfig.json');
|
|
401
|
-
if (await util_1.util.pathExists(configFilePath)) {
|
|
402
|
-
return configFilePath;
|
|
403
|
-
}
|
|
404
|
-
//look for the deprecated `brsconfig.json` file
|
|
405
|
-
configFilePath = path.resolve(workspacePath, 'brsconfig.json');
|
|
406
|
-
if (await util_1.util.pathExists(configFilePath)) {
|
|
407
|
-
return configFilePath;
|
|
408
|
-
}
|
|
409
|
-
//no config file could be found
|
|
410
|
-
return undefined;
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* @param projectPath path to the project
|
|
414
|
-
* @param workspacePath path to the workspace in which all project should reside or are referenced by
|
|
415
|
-
* @param projectNumber an optional project number to assign to the project. Used when reloading projects that should keep the same number
|
|
416
|
-
*/
|
|
417
|
-
async createProject(projectPath, workspacePath = projectPath, projectNumber) {
|
|
418
|
-
workspacePath !== null && workspacePath !== void 0 ? workspacePath : (workspacePath = projectPath);
|
|
419
|
-
let project = this.projects.find((x) => x.projectPath === projectPath);
|
|
420
|
-
//skip this project if we already have it
|
|
421
|
-
if (project) {
|
|
231
|
+
const workspaces = await this.getWorkspaceConfigs();
|
|
232
|
+
let workspaceResult = await getLogLevel(workspaces, workspace => { var _a; return (_a = workspace === null || workspace === void 0 ? void 0 : workspace.languageServer) === null || _a === void 0 ? void 0 : _a.logLevel; });
|
|
233
|
+
if (workspaceResult) {
|
|
234
|
+
this.logger.info(`Setting global logLevel to '${workspaceResult.logLevelText}' based on configuration from workspace '${(_a = workspaceResult === null || workspaceResult === void 0 ? void 0 : workspaceResult.item) === null || _a === void 0 ? void 0 : _a.workspaceFolder}'`);
|
|
235
|
+
this.logger.logLevel = workspaceResult.logLevel;
|
|
422
236
|
return;
|
|
423
237
|
}
|
|
424
|
-
let
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
builder.plugins.add({
|
|
430
|
-
name: 'bsc-language-server',
|
|
431
|
-
afterProgramValidate: () => {
|
|
432
|
-
void this.sendDiagnostics();
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
//prevent clearing the console on run...this isn't the CLI so we want to keep a full log of everything
|
|
436
|
-
builder.allowConsoleClearing = false;
|
|
437
|
-
//look for files in our in-memory cache before going to the file system
|
|
438
|
-
builder.addFileResolver(this.documentFileResolver.bind(this));
|
|
439
|
-
let configFilePath = await this.getConfigFilePath(projectPath);
|
|
440
|
-
let cwd = projectPath;
|
|
441
|
-
//if the config file exists, use it and its folder as cwd
|
|
442
|
-
if (configFilePath && await util_1.util.pathExists(configFilePath)) {
|
|
443
|
-
cwd = path.dirname(configFilePath);
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
//config file doesn't exist...let `brighterscript` resolve the default way
|
|
447
|
-
configFilePath = undefined;
|
|
448
|
-
}
|
|
449
|
-
const firstRunDeferred = new deferred_1.Deferred();
|
|
450
|
-
let newProject = {
|
|
451
|
-
projectNumber: projectNumber,
|
|
452
|
-
builder: builder,
|
|
453
|
-
firstRunPromise: firstRunDeferred.promise,
|
|
454
|
-
projectPath: projectPath,
|
|
455
|
-
workspacePath: workspacePath,
|
|
456
|
-
isFirstRunComplete: false,
|
|
457
|
-
isFirstRunSuccessful: false,
|
|
458
|
-
configFilePath: configFilePath,
|
|
459
|
-
isStandaloneFileProject: false
|
|
460
|
-
};
|
|
461
|
-
this.projects.push(newProject);
|
|
462
|
-
try {
|
|
463
|
-
await builder.run({
|
|
464
|
-
cwd: cwd,
|
|
465
|
-
project: configFilePath,
|
|
466
|
-
watch: false,
|
|
467
|
-
createPackage: false,
|
|
468
|
-
deploy: false,
|
|
469
|
-
copyToStaging: false,
|
|
470
|
-
showDiagnosticsInConsole: false
|
|
471
|
-
});
|
|
472
|
-
newProject.isFirstRunComplete = true;
|
|
473
|
-
newProject.isFirstRunSuccessful = true;
|
|
474
|
-
firstRunDeferred.resolve();
|
|
475
|
-
}
|
|
476
|
-
catch (e) {
|
|
477
|
-
builder.logger.error(e);
|
|
478
|
-
firstRunDeferred.reject(e);
|
|
479
|
-
newProject.isFirstRunComplete = true;
|
|
480
|
-
newProject.isFirstRunSuccessful = false;
|
|
481
|
-
}
|
|
482
|
-
//if we found a deprecated brsconfig.json, add a diagnostic warning the user
|
|
483
|
-
if (configFilePath && path.basename(configFilePath) === 'brsconfig.json') {
|
|
484
|
-
builder.addDiagnostic(configFilePath, Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.brsConfigJsonIsDeprecated()), { range: util_1.util.createRange(0, 0, 0, 0) }));
|
|
485
|
-
return this.sendDiagnostics();
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
async createStandaloneFileProject(srcPath) {
|
|
489
|
-
//skip this workspace if we already have it
|
|
490
|
-
if (this.standaloneFileProjects[srcPath]) {
|
|
491
|
-
return this.standaloneFileProjects[srcPath];
|
|
492
|
-
}
|
|
493
|
-
let builder = new ProgramBuilder_1.ProgramBuilder();
|
|
494
|
-
//prevent clearing the console on run...this isn't the CLI so we want to keep a full log of everything
|
|
495
|
-
builder.allowConsoleClearing = false;
|
|
496
|
-
//look for files in our in-memory cache before going to the file system
|
|
497
|
-
builder.addFileResolver(this.documentFileResolver.bind(this));
|
|
498
|
-
//get the path to the directory where this file resides
|
|
499
|
-
let cwd = path.dirname(srcPath);
|
|
500
|
-
//get the closest config file and use most of the settings from that
|
|
501
|
-
let configFilePath = await util_1.util.findClosestConfigFile(srcPath);
|
|
502
|
-
let project = {};
|
|
503
|
-
if (configFilePath) {
|
|
504
|
-
project = util_1.util.normalizeAndResolveConfig({ project: configFilePath });
|
|
505
|
-
}
|
|
506
|
-
//override the rootDir and files array
|
|
507
|
-
project.rootDir = cwd;
|
|
508
|
-
project.files = [{
|
|
509
|
-
src: srcPath,
|
|
510
|
-
dest: path.basename(srcPath)
|
|
511
|
-
}];
|
|
512
|
-
let firstRunPromise = builder.run(Object.assign(Object.assign({}, project), { cwd: cwd, project: configFilePath, watch: false, createPackage: false, deploy: false, copyToStaging: false, diagnosticFilters: [
|
|
513
|
-
//hide the "file not referenced by any other file" error..that's expected in a standalone file.
|
|
514
|
-
1013
|
|
515
|
-
] })).catch((err) => {
|
|
516
|
-
console.error(err);
|
|
517
|
-
});
|
|
518
|
-
let newProject = {
|
|
519
|
-
projectNumber: this.projectCounter++,
|
|
520
|
-
builder: builder,
|
|
521
|
-
firstRunPromise: firstRunPromise,
|
|
522
|
-
projectPath: srcPath,
|
|
523
|
-
workspacePath: srcPath,
|
|
524
|
-
isFirstRunComplete: false,
|
|
525
|
-
isFirstRunSuccessful: false,
|
|
526
|
-
configFilePath: configFilePath,
|
|
527
|
-
isStandaloneFileProject: true
|
|
528
|
-
};
|
|
529
|
-
this.standaloneFileProjects[srcPath] = newProject;
|
|
530
|
-
await firstRunPromise.then(() => {
|
|
531
|
-
newProject.isFirstRunComplete = true;
|
|
532
|
-
newProject.isFirstRunSuccessful = true;
|
|
533
|
-
}).catch(() => {
|
|
534
|
-
newProject.isFirstRunComplete = true;
|
|
535
|
-
newProject.isFirstRunSuccessful = false;
|
|
536
|
-
});
|
|
537
|
-
return newProject;
|
|
538
|
-
}
|
|
539
|
-
getProjects() {
|
|
540
|
-
let projects = this.projects.slice();
|
|
541
|
-
for (let key in this.standaloneFileProjects) {
|
|
542
|
-
projects.push(this.standaloneFileProjects[key]);
|
|
543
|
-
}
|
|
544
|
-
return projects;
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Provide a list of completion items based on the current cursor position
|
|
548
|
-
*/
|
|
549
|
-
async onCompletion(params) {
|
|
550
|
-
//ensure programs are initialized
|
|
551
|
-
await this.waitAllProjectFirstRuns();
|
|
552
|
-
let filePath = util_1.util.uriToPath(params.textDocument.uri);
|
|
553
|
-
//wait until the file has settled
|
|
554
|
-
await this.keyedThrottler.onIdleOnce(filePath, true);
|
|
555
|
-
let completions = this
|
|
556
|
-
.getProjects()
|
|
557
|
-
.flatMap(workspace => workspace.builder.program.getCompletions(filePath, params.position));
|
|
558
|
-
for (let completion of completions) {
|
|
559
|
-
completion.commitCharacters = ['.'];
|
|
560
|
-
}
|
|
561
|
-
return completions;
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* Provide a full completion item from the selection
|
|
565
|
-
*/
|
|
566
|
-
onCompletionResolve(item) {
|
|
567
|
-
if (item.data === 1) {
|
|
568
|
-
item.detail = 'TypeScript details';
|
|
569
|
-
item.documentation = 'TypeScript documentation';
|
|
570
|
-
}
|
|
571
|
-
else if (item.data === 2) {
|
|
572
|
-
item.detail = 'JavaScript details';
|
|
573
|
-
item.documentation = 'JavaScript documentation';
|
|
574
|
-
}
|
|
575
|
-
return item;
|
|
576
|
-
}
|
|
577
|
-
async onCodeAction(params) {
|
|
578
|
-
var _a;
|
|
579
|
-
//ensure programs are initialized
|
|
580
|
-
await this.waitAllProjectFirstRuns();
|
|
581
|
-
let srcPath = util_1.util.uriToPath(params.textDocument.uri);
|
|
582
|
-
//wait until the file has settled
|
|
583
|
-
await this.keyedThrottler.onIdleOnce(srcPath, true);
|
|
584
|
-
const codeActions = this
|
|
585
|
-
.getProjects()
|
|
586
|
-
//skip programs that don't have this file
|
|
587
|
-
.filter(x => { var _a, _b; return (_b = (_a = x.builder) === null || _a === void 0 ? void 0 : _a.program) === null || _b === void 0 ? void 0 : _b.hasFile(srcPath); })
|
|
588
|
-
.flatMap(workspace => workspace.builder.program.getCodeActions(srcPath, params.range));
|
|
589
|
-
//clone the diagnostics for each code action, since certain diagnostics can have circular reference properties that kill the language server if serialized
|
|
590
|
-
for (const codeAction of codeActions) {
|
|
591
|
-
if (codeAction.diagnostics) {
|
|
592
|
-
codeAction.diagnostics = (_a = codeAction.diagnostics) === null || _a === void 0 ? void 0 : _a.map(x => util_1.util.toDiagnostic(x, params.textDocument.uri));
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
return codeActions;
|
|
596
|
-
}
|
|
597
|
-
/**
|
|
598
|
-
* Remove a project from the language server
|
|
599
|
-
*/
|
|
600
|
-
removeProject(project) {
|
|
601
|
-
var _a;
|
|
602
|
-
const idx = this.projects.indexOf(project);
|
|
603
|
-
if (idx > -1) {
|
|
604
|
-
this.projects.splice(idx, 1);
|
|
605
|
-
}
|
|
606
|
-
(_a = project === null || project === void 0 ? void 0 : project.builder) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
607
|
-
}
|
|
608
|
-
/**
|
|
609
|
-
* Reload each of the specified workspaces
|
|
610
|
-
*/
|
|
611
|
-
async reloadProjects(projects) {
|
|
612
|
-
await Promise.all(projects.map(async (project) => {
|
|
613
|
-
//ensure the workspace has finished starting up
|
|
614
|
-
try {
|
|
615
|
-
await project.firstRunPromise;
|
|
616
|
-
}
|
|
617
|
-
catch (e) { }
|
|
618
|
-
//handle standard workspace
|
|
619
|
-
if (project.isStandaloneFileProject === false) {
|
|
620
|
-
this.removeProject(project);
|
|
621
|
-
//create a new workspace/brs program
|
|
622
|
-
await this.createProject(project.projectPath, project.workspacePath, project.projectNumber);
|
|
623
|
-
//handle temp workspace
|
|
624
|
-
}
|
|
625
|
-
else {
|
|
626
|
-
project.builder.dispose();
|
|
627
|
-
delete this.standaloneFileProjects[project.projectPath];
|
|
628
|
-
await this.createStandaloneFileProject(project.projectPath);
|
|
629
|
-
}
|
|
630
|
-
}));
|
|
631
|
-
if (projects.length > 0) {
|
|
632
|
-
//wait for all of the programs to finish starting up
|
|
633
|
-
await this.waitAllProjectFirstRuns();
|
|
634
|
-
// valdiate all workspaces
|
|
635
|
-
this.validateAllThrottled(); //eslint-disable-line
|
|
238
|
+
let projectResult = await getLogLevel(this.projectManager.projects, (project) => project.logger.logLevel);
|
|
239
|
+
if (projectResult) {
|
|
240
|
+
this.logger.info(`Setting global logLevel to '${projectResult.logLevelText}' based on project #${(_b = projectResult === null || projectResult === void 0 ? void 0 : projectResult.item) === null || _b === void 0 ? void 0 : _b.projectNumber}`);
|
|
241
|
+
this.logger.logLevel = projectResult.logLevel;
|
|
242
|
+
return;
|
|
636
243
|
}
|
|
244
|
+
//use a default level if no other level was found
|
|
245
|
+
this.logger.logLevel = logging_1.LogLevel.log;
|
|
637
246
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
* included in an actual program now.
|
|
647
|
-
*
|
|
648
|
-
* Sometimes files that used to be included are now excluded, so those open files need to be re-processed as standalone
|
|
649
|
-
*/
|
|
650
|
-
async synchronizeStandaloneProjects() {
|
|
651
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
652
|
-
//remove standalone workspaces that are now included in projects
|
|
653
|
-
for (let standaloneFilePath in this.standaloneFileProjects) {
|
|
654
|
-
let standaloneProject = this.standaloneFileProjects[standaloneFilePath];
|
|
655
|
-
for (let project of this.projects) {
|
|
656
|
-
await standaloneProject.firstRunPromise;
|
|
657
|
-
let dest = roku_deploy_1.rokuDeploy.getDestPath(standaloneFilePath, (_d = (_c = (_b = (_a = project === null || project === void 0 ? void 0 : project.builder) === null || _a === void 0 ? void 0 : _a.program) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.files) !== null && _d !== void 0 ? _d : [], this.getRootDir(project));
|
|
658
|
-
//destroy this standalone workspace because the file has now been included in an actual workspace,
|
|
659
|
-
//or if the workspace wants the file
|
|
660
|
-
if (((_f = (_e = project === null || project === void 0 ? void 0 : project.builder) === null || _e === void 0 ? void 0 : _e.program) === null || _f === void 0 ? void 0 : _f.hasFile(standaloneFilePath)) || dest) {
|
|
661
|
-
standaloneProject.builder.dispose();
|
|
662
|
-
delete this.standaloneFileProjects[standaloneFilePath];
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
//create standalone projects for open files that no longer have a project
|
|
667
|
-
let textDocuments = this.documents.all();
|
|
668
|
-
outer: for (let textDocument of textDocuments) {
|
|
669
|
-
let filePath = vscode_uri_1.URI.parse(textDocument.uri).fsPath;
|
|
670
|
-
for (let project of this.getProjects()) {
|
|
671
|
-
let dest = roku_deploy_1.rokuDeploy.getDestPath(filePath, (_k = (_j = (_h = (_g = project === null || project === void 0 ? void 0 : project.builder) === null || _g === void 0 ? void 0 : _g.program) === null || _h === void 0 ? void 0 : _h.options) === null || _j === void 0 ? void 0 : _j.files) !== null && _k !== void 0 ? _k : [], this.getRootDir(project));
|
|
672
|
-
//if this project has the file, or it wants the file, do NOT make a standaloneProject for this file
|
|
673
|
-
if (((_m = (_l = project === null || project === void 0 ? void 0 : project.builder) === null || _l === void 0 ? void 0 : _l.program) === null || _m === void 0 ? void 0 : _m.hasFile(filePath)) || dest) {
|
|
674
|
-
continue outer;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
//if we got here, no workspace has this file, so make a standalone file workspace
|
|
678
|
-
let project = await this.createStandaloneFileProject(filePath);
|
|
679
|
-
await project.firstRunPromise;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
async onDidChangeConfiguration() {
|
|
683
|
-
if (this.hasConfigurationCapability) {
|
|
684
|
-
//if the user changes any config value, just mass-reload all projects
|
|
685
|
-
await this.reloadProjects(this.getProjects());
|
|
686
|
-
// Reset all cached document settings
|
|
687
|
-
}
|
|
688
|
-
else {
|
|
689
|
-
// this.globalSettings = <ExampleSettings>(
|
|
690
|
-
// (change.settings.languageServerExample || this.defaultSettings)
|
|
691
|
-
// );
|
|
692
|
-
}
|
|
247
|
+
async onTextDocumentDidChangeContent(event) {
|
|
248
|
+
this.logger.debug('onTextDocumentDidChangeContent', event.document.uri);
|
|
249
|
+
await this.projectManager.handleFileChanges([{
|
|
250
|
+
srcPath: vscode_uri_1.URI.parse(event.document.uri).fsPath,
|
|
251
|
+
type: node_1.FileChangeType.Changed,
|
|
252
|
+
fileContents: event.document.getText(),
|
|
253
|
+
allowStandaloneProject: true
|
|
254
|
+
}]);
|
|
693
255
|
}
|
|
694
256
|
/**
|
|
695
257
|
* Called when watched files changed (add/change/delete).
|
|
@@ -698,446 +260,353 @@ class LanguageServer {
|
|
|
698
260
|
* file types are watched (.brs,.bs,.xml,manifest, and any json/text/image files)
|
|
699
261
|
*/
|
|
700
262
|
async onDidChangeWatchedFiles(params) {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
263
|
+
const workspacePaths = (await this.connection.workspace.getWorkspaceFolders()).map(x => util_1.util.uriToPath(x.uri));
|
|
264
|
+
let changes = params.changes
|
|
265
|
+
.map(x => ({
|
|
266
|
+
srcPath: util_1.util.uriToPath(x.uri),
|
|
267
|
+
type: x.type,
|
|
268
|
+
//if this is an open document, allow this file to be loaded in a standalone project (if applicable)
|
|
269
|
+
allowStandaloneProject: this.documents.get(x.uri) !== undefined
|
|
270
|
+
}))
|
|
271
|
+
//exclude all explicit top-level workspace folder paths (to fix a weird macos fs watcher bug that emits events for the workspace folder itself)
|
|
272
|
+
.filter(x => !workspacePaths.includes(x.srcPath));
|
|
273
|
+
this.logger.debug('onDidChangeWatchedFiles', changes);
|
|
274
|
+
//if the client changed any files containing include/exclude patterns, rebuild the path filterer before processing these changes
|
|
275
|
+
if (micromatch.some(changes.map(x => x.srcPath), [
|
|
276
|
+
'**/.gitignore',
|
|
277
|
+
'**/.vscode/settings.json',
|
|
278
|
+
'**/*bsconfig*.json'
|
|
279
|
+
], {
|
|
280
|
+
dot: true
|
|
281
|
+
})) {
|
|
282
|
+
await this.rebuildPathFilterer();
|
|
283
|
+
}
|
|
284
|
+
//handle the file changes
|
|
285
|
+
await this.projectManager.handleFileChanges(changes);
|
|
286
|
+
}
|
|
287
|
+
async onDocumentClose(event) {
|
|
288
|
+
this.logger.debug('onDocumentClose', event.document.uri);
|
|
289
|
+
await this.projectManager.handleFileClose({
|
|
290
|
+
srcPath: util_1.util.uriToPath(event.document.uri)
|
|
710
291
|
});
|
|
711
|
-
let keys = changes.map(x => x.srcPath);
|
|
712
|
-
//filter the list of changes to only the ones that made it through the debounce unscathed
|
|
713
|
-
changes = changes.filter(x => keys.includes(x.srcPath));
|
|
714
|
-
//if we have changes to work with
|
|
715
|
-
if (changes.length > 0) {
|
|
716
|
-
//if any bsconfig files were added or deleted, re-sync all projects instead of the more specific approach below
|
|
717
|
-
if (changes.find(x => (x.type === node_1.FileChangeType.Created || x.type === node_1.FileChangeType.Deleted) && path.basename(x.srcPath).toLowerCase() === 'bsconfig.json')) {
|
|
718
|
-
return this.syncProjects();
|
|
719
|
-
}
|
|
720
|
-
//reload any workspace whose bsconfig.json file has changed
|
|
721
|
-
{
|
|
722
|
-
let projectsToReload = [];
|
|
723
|
-
//get the file paths as a string array
|
|
724
|
-
let filePaths = changes.map((x) => x.srcPath);
|
|
725
|
-
for (let project of projects) {
|
|
726
|
-
if (project.configFilePath && filePaths.includes(project.configFilePath)) {
|
|
727
|
-
projectsToReload.push(project);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
if (projectsToReload.length > 0) {
|
|
731
|
-
//vsc can generate a ton of these changes, for vsc system files, so we need to bail if there's no work to do on any of our actual project files
|
|
732
|
-
//reload any projects that need to be reloaded
|
|
733
|
-
await this.reloadProjects(projectsToReload);
|
|
734
|
-
}
|
|
735
|
-
//reassign `projects` to the non-reloaded projects
|
|
736
|
-
projects = projects.filter(x => !projectsToReload.includes(x));
|
|
737
|
-
}
|
|
738
|
-
//convert created folders into a list of files of their contents
|
|
739
|
-
const directoryChanges = changes
|
|
740
|
-
//get only creation items
|
|
741
|
-
.filter(change => change.type === node_1.FileChangeType.Created)
|
|
742
|
-
//keep only the directories
|
|
743
|
-
.filter(change => util_1.util.isDirectorySync(change.srcPath));
|
|
744
|
-
//remove the created directories from the changes array (we will add back each of their files next)
|
|
745
|
-
changes = changes.filter(x => !directoryChanges.includes(x));
|
|
746
|
-
//look up every file in each of the newly added directories
|
|
747
|
-
const newFileChanges = directoryChanges
|
|
748
|
-
//take just the path
|
|
749
|
-
.map(x => x.srcPath)
|
|
750
|
-
//exclude the roku deploy staging folder
|
|
751
|
-
.filter(dirPath => !dirPath.includes('.roku-deploy-staging'))
|
|
752
|
-
//get the files for each folder recursively
|
|
753
|
-
.flatMap(dirPath => {
|
|
754
|
-
//look up all files
|
|
755
|
-
let files = fastGlob.sync('**/*', {
|
|
756
|
-
absolute: true,
|
|
757
|
-
cwd: roku_deploy_1.util.toForwardSlashes(dirPath)
|
|
758
|
-
});
|
|
759
|
-
return files.map(x => {
|
|
760
|
-
return {
|
|
761
|
-
type: node_1.FileChangeType.Created,
|
|
762
|
-
srcPath: (0, util_1.standardizePath) `${x}`
|
|
763
|
-
};
|
|
764
|
-
});
|
|
765
|
-
});
|
|
766
|
-
//add the new file changes to the changes array.
|
|
767
|
-
changes.push(...newFileChanges);
|
|
768
|
-
//give every workspace the chance to handle file changes
|
|
769
|
-
await Promise.all(projects.map((project) => this.handleFileChanges(project, changes)));
|
|
770
|
-
}
|
|
771
292
|
}
|
|
772
293
|
/**
|
|
773
|
-
*
|
|
774
|
-
* any file changes you receive with no unexpected side-effects
|
|
294
|
+
* Provide a list of completion items based on the current cursor position
|
|
775
295
|
*/
|
|
776
|
-
async
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
if (consumeCount > 0) {
|
|
786
|
-
await this.validateAllThrottled();
|
|
787
|
-
}
|
|
296
|
+
async onCompletion(params, cancellationToken, workDoneProgress, resultProgress) {
|
|
297
|
+
this.logger.debug('onCompletion', params, cancellationToken);
|
|
298
|
+
const srcPath = util_1.util.uriToPath(params.textDocument.uri);
|
|
299
|
+
const completions = await this.projectManager.getCompletions({
|
|
300
|
+
srcPath: srcPath,
|
|
301
|
+
position: params.position,
|
|
302
|
+
cancellationToken: cancellationToken
|
|
303
|
+
});
|
|
304
|
+
return completions;
|
|
788
305
|
}
|
|
789
306
|
/**
|
|
790
|
-
*
|
|
791
|
-
*
|
|
307
|
+
* Get a list of workspaces, and their configurations.
|
|
308
|
+
* Get only the settings for the workspace that are relevant to the language server. We do this so we can cache this object for use in change detection in the future.
|
|
792
309
|
*/
|
|
793
|
-
async
|
|
794
|
-
const { program, options, rootDir } = project.builder;
|
|
795
|
-
//deleted
|
|
796
|
-
if (change.type === node_1.FileChangeType.Deleted) {
|
|
797
|
-
//try to act on this path as a directory
|
|
798
|
-
project.builder.removeFilesInFolder(change.srcPath);
|
|
799
|
-
//if this is a file loaded in the program, remove it
|
|
800
|
-
if (program.hasFile(change.srcPath)) {
|
|
801
|
-
program.removeFile(change.srcPath);
|
|
802
|
-
return true;
|
|
803
|
-
}
|
|
804
|
-
else {
|
|
805
|
-
return false;
|
|
806
|
-
}
|
|
807
|
-
//created
|
|
808
|
-
}
|
|
809
|
-
else if (change.type === node_1.FileChangeType.Created) {
|
|
810
|
-
// thanks to `onDidChangeWatchedFiles`, we can safely assume that all "Created" changes are file paths, (not directories)
|
|
811
|
-
//get the dest path for this file.
|
|
812
|
-
let destPath = roku_deploy_1.rokuDeploy.getDestPath(change.srcPath, options.files, rootDir);
|
|
813
|
-
//if we got a dest path, then the program wants this file
|
|
814
|
-
if (destPath) {
|
|
815
|
-
program.setFile({
|
|
816
|
-
src: change.srcPath,
|
|
817
|
-
dest: roku_deploy_1.rokuDeploy.getDestPath(change.srcPath, options.files, rootDir)
|
|
818
|
-
}, await project.builder.getFileContents(change.srcPath));
|
|
819
|
-
return true;
|
|
820
|
-
}
|
|
821
|
-
else {
|
|
822
|
-
//no dest path means the program doesn't want this file
|
|
823
|
-
return false;
|
|
824
|
-
}
|
|
825
|
-
//changed
|
|
826
|
-
}
|
|
827
|
-
else if (program.hasFile(change.srcPath)) {
|
|
828
|
-
//sometimes "changed" events are emitted on files that were actually deleted,
|
|
829
|
-
//so determine file existance and act accordingly
|
|
830
|
-
if (await util_1.util.pathExists(change.srcPath)) {
|
|
831
|
-
program.setFile({
|
|
832
|
-
src: change.srcPath,
|
|
833
|
-
dest: roku_deploy_1.rokuDeploy.getDestPath(change.srcPath, options.files, rootDir)
|
|
834
|
-
}, await project.builder.getFileContents(change.srcPath));
|
|
835
|
-
}
|
|
836
|
-
else {
|
|
837
|
-
program.removeFile(change.srcPath);
|
|
838
|
-
}
|
|
839
|
-
return true;
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
async onHover(params) {
|
|
310
|
+
async getWorkspaceConfigs() {
|
|
843
311
|
var _a;
|
|
844
|
-
//
|
|
845
|
-
await this.
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
.map(x => {
|
|
857
|
-
return Array.isArray(x === null || x === void 0 ? void 0 : x.contents) ? x === null || x === void 0 ? void 0 : x.contents : [x === null || x === void 0 ? void 0 : x.contents];
|
|
858
|
-
}).flat()
|
|
859
|
-
//remove nulls
|
|
860
|
-
.filter(x => !!x)
|
|
861
|
-
//dedupe hovers across all projects
|
|
862
|
-
.reduce((set, content) => set.add(content), new Set()).values()
|
|
863
|
-
];
|
|
864
|
-
if (contents.length > 0) {
|
|
865
|
-
let hover = {
|
|
866
|
-
//use the range from the first hover
|
|
867
|
-
range: (_a = hovers[0]) === null || _a === void 0 ? void 0 : _a.range,
|
|
868
|
-
//the contents of all hovers
|
|
869
|
-
contents: contents
|
|
870
|
-
};
|
|
871
|
-
return hover;
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
async onDocumentClose(event) {
|
|
875
|
-
const { document } = event;
|
|
876
|
-
let filePath = vscode_uri_1.URI.parse(document.uri).fsPath;
|
|
877
|
-
let standaloneFileProject = this.standaloneFileProjects[filePath];
|
|
878
|
-
//if this was a temp file, close it
|
|
879
|
-
if (standaloneFileProject) {
|
|
880
|
-
await standaloneFileProject.firstRunPromise;
|
|
881
|
-
standaloneFileProject.builder.dispose();
|
|
882
|
-
delete this.standaloneFileProjects[filePath];
|
|
883
|
-
await this.sendDiagnostics();
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
async validateTextDocument(event) {
|
|
887
|
-
const { document } = event;
|
|
888
|
-
//ensure programs are initialized
|
|
889
|
-
await this.waitAllProjectFirstRuns();
|
|
890
|
-
let filePath = vscode_uri_1.URI.parse(document.uri).fsPath;
|
|
891
|
-
try {
|
|
892
|
-
//throttle file processing. first call is run immediately, and then the last call is processed.
|
|
893
|
-
await this.keyedThrottler.run(filePath, () => {
|
|
894
|
-
var _a;
|
|
895
|
-
let documentText = document.getText();
|
|
896
|
-
for (const project of this.getProjects()) {
|
|
897
|
-
//only add or replace existing files. All of the files in the project should
|
|
898
|
-
//have already been loaded by other means
|
|
899
|
-
if (project.builder.program.hasFile(filePath)) {
|
|
900
|
-
let rootDir = (_a = project.builder.program.options.rootDir) !== null && _a !== void 0 ? _a : project.builder.program.options.cwd;
|
|
901
|
-
let dest = roku_deploy_1.rokuDeploy.getDestPath(filePath, project.builder.program.options.files, rootDir);
|
|
902
|
-
project.builder.program.setFile({
|
|
903
|
-
src: filePath,
|
|
904
|
-
dest: dest
|
|
905
|
-
}, documentText);
|
|
906
|
-
}
|
|
312
|
+
//get all workspace folders (we'll use these to get settings)
|
|
313
|
+
let workspaces = await Promise.all(((_a = await this.connection.workspace.getWorkspaceFolders()) !== null && _a !== void 0 ? _a : []).map(async (x) => {
|
|
314
|
+
var _a, _b, _c;
|
|
315
|
+
const workspaceFolder = util_1.util.uriToPath(x.uri);
|
|
316
|
+
const brightscriptConfig = await this.getClientConfiguration(x.uri, 'brightscript');
|
|
317
|
+
return {
|
|
318
|
+
workspaceFolder: workspaceFolder,
|
|
319
|
+
excludePatterns: await this.getWorkspaceExcludeGlobs(workspaceFolder),
|
|
320
|
+
bsconfigPath: brightscriptConfig.configFile,
|
|
321
|
+
languageServer: {
|
|
322
|
+
enableThreading: (_b = (_a = brightscriptConfig.languageServer) === null || _a === void 0 ? void 0 : _a.enableThreading) !== null && _b !== void 0 ? _b : LanguageServer.enableThreadingDefault,
|
|
323
|
+
logLevel: (_c = brightscriptConfig === null || brightscriptConfig === void 0 ? void 0 : brightscriptConfig.languageServer) === null || _c === void 0 ? void 0 : _c.logLevel
|
|
907
324
|
}
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
325
|
+
};
|
|
326
|
+
}));
|
|
327
|
+
return workspaces;
|
|
328
|
+
}
|
|
329
|
+
async onDidChangeConfiguration(args) {
|
|
330
|
+
this.logger.log('onDidChangeConfiguration', 'Reloading all projects');
|
|
331
|
+
const configs = new Map((await this.getWorkspaceConfigs()).map(x => [x.workspaceFolder, x]));
|
|
332
|
+
//find any changed configs. This includes newly created workspaces, deleted workspaces, etc.
|
|
333
|
+
//TODO: enhance this to only reload specific projects, depending on the change
|
|
334
|
+
if (!isEqual(configs, this.workspaceConfigsCache)) {
|
|
335
|
+
//now that we've processed any config diffs, update the cached copy of them
|
|
336
|
+
this.workspaceConfigsCache = configs;
|
|
337
|
+
//if configuration changed, rebuild the path filterer
|
|
338
|
+
await this.rebuildPathFilterer();
|
|
339
|
+
//if the user changes any user/workspace config settings, just mass-reload all projects
|
|
340
|
+
await this.syncProjects(true);
|
|
914
341
|
}
|
|
915
342
|
}
|
|
916
|
-
async
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
let projects = this.getProjects();
|
|
922
|
-
//validate all programs
|
|
923
|
-
await Promise.all(projects.map((project) => {
|
|
924
|
-
project.builder.program.validate();
|
|
925
|
-
return project;
|
|
926
|
-
}));
|
|
927
|
-
}
|
|
928
|
-
catch (e) {
|
|
929
|
-
this.connection.console.error(e);
|
|
930
|
-
await this.sendCriticalFailure(`Critical error validating project: ${e.message}${(_a = e.stack) !== null && _a !== void 0 ? _a : ''}`);
|
|
931
|
-
}
|
|
343
|
+
async onHover(params) {
|
|
344
|
+
this.logger.debug('onHover', params);
|
|
345
|
+
const srcPath = util_1.util.uriToPath(params.textDocument.uri);
|
|
346
|
+
const result = await this.projectManager.getHover({ srcPath: srcPath, position: params.position });
|
|
347
|
+
return result;
|
|
932
348
|
}
|
|
933
349
|
async onWorkspaceSymbol(params) {
|
|
934
|
-
|
|
935
|
-
const
|
|
936
|
-
|
|
937
|
-
})), c => c);
|
|
938
|
-
// Remove duplicates
|
|
939
|
-
const allSymbols = Object.values(results.reduce((map, symbol) => {
|
|
940
|
-
const key = symbol.location.uri + symbol.name;
|
|
941
|
-
map[key] = symbol;
|
|
942
|
-
return map;
|
|
943
|
-
}, {}));
|
|
944
|
-
return allSymbols;
|
|
350
|
+
this.logger.debug('onWorkspaceSymbol', params);
|
|
351
|
+
const result = await this.projectManager.getWorkspaceSymbol();
|
|
352
|
+
return result;
|
|
945
353
|
}
|
|
946
354
|
async onDocumentSymbol(params) {
|
|
947
|
-
|
|
948
|
-
await this.keyedThrottler.onIdleOnce(util_1.util.uriToPath(params.textDocument.uri), true);
|
|
355
|
+
this.logger.debug('onDocumentSymbol', params);
|
|
949
356
|
const srcPath = util_1.util.uriToPath(params.textDocument.uri);
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
if ((0, reflection_1.isBrsFile)(file)) {
|
|
953
|
-
return file.getDocumentSymbols();
|
|
954
|
-
}
|
|
955
|
-
}
|
|
357
|
+
const result = await this.projectManager.getDocumentSymbol({ srcPath: srcPath });
|
|
358
|
+
return result;
|
|
956
359
|
}
|
|
957
360
|
async onDefinition(params) {
|
|
958
|
-
|
|
361
|
+
this.logger.debug('onDefinition', params);
|
|
959
362
|
const srcPath = util_1.util.uriToPath(params.textDocument.uri);
|
|
960
|
-
const
|
|
961
|
-
|
|
962
|
-
})), c => c);
|
|
963
|
-
return results;
|
|
363
|
+
const result = this.projectManager.getDefinition({ srcPath: srcPath, position: params.position });
|
|
364
|
+
return result;
|
|
964
365
|
}
|
|
965
366
|
async onSignatureHelp(params) {
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
const
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
const signatures = util_1.util.flatMap(await Promise.all(this.getProjects().map(project => project.builder.program.getSignatureHelp(filepath, params.position))), c => c);
|
|
972
|
-
const activeSignature = signatures.length > 0 ? 0 : null;
|
|
973
|
-
const activeParameter = activeSignature !== null ? (_a = signatures[activeSignature]) === null || _a === void 0 ? void 0 : _a.index : null;
|
|
974
|
-
let results = {
|
|
975
|
-
signatures: signatures.map((s) => s.signature),
|
|
976
|
-
activeSignature: activeSignature,
|
|
977
|
-
activeParameter: activeParameter
|
|
978
|
-
};
|
|
979
|
-
return results;
|
|
367
|
+
this.logger.debug('onSignatureHelp', params);
|
|
368
|
+
const srcPath = util_1.util.uriToPath(params.textDocument.uri);
|
|
369
|
+
const result = await this.projectManager.getSignatureHelp({ srcPath: srcPath, position: params.position });
|
|
370
|
+
if (result) {
|
|
371
|
+
return result;
|
|
980
372
|
}
|
|
981
|
-
|
|
982
|
-
this.connection.console.error(`error in onSignatureHelp: ${(_c = (_b = e.stack) !== null && _b !== void 0 ? _b : e.message) !== null && _c !== void 0 ? _c : e}`);
|
|
373
|
+
else {
|
|
983
374
|
return {
|
|
984
375
|
signatures: [],
|
|
985
|
-
activeSignature:
|
|
986
|
-
activeParameter:
|
|
376
|
+
activeSignature: null,
|
|
377
|
+
activeParameter: null
|
|
987
378
|
};
|
|
988
379
|
}
|
|
989
380
|
}
|
|
990
381
|
async onReferences(params) {
|
|
991
|
-
|
|
992
|
-
const position = params.position;
|
|
382
|
+
this.logger.debug('onReferences', params);
|
|
993
383
|
const srcPath = util_1.util.uriToPath(params.textDocument.uri);
|
|
994
|
-
const
|
|
995
|
-
|
|
996
|
-
})), c => c !== null && c !== void 0 ? c : []);
|
|
997
|
-
return results.filter((r) => r);
|
|
998
|
-
}
|
|
999
|
-
onValidateSettled() {
|
|
1000
|
-
return Promise.all([
|
|
1001
|
-
//wait for the validator to start running (or timeout if it never did)
|
|
1002
|
-
this.validateThrottler.onRunOnce(100),
|
|
1003
|
-
//wait for the validator to stop running (or resolve immediately if it's already idle)
|
|
1004
|
-
this.validateThrottler.onIdleOnce(true)
|
|
1005
|
-
]);
|
|
384
|
+
const result = await this.projectManager.getReferences({ srcPath: srcPath, position: params.position });
|
|
385
|
+
return result !== null && result !== void 0 ? result : [];
|
|
1006
386
|
}
|
|
1007
387
|
async onFullSemanticTokens(params) {
|
|
1008
|
-
|
|
1009
|
-
//wait for the file to settle (in case there are multiple file changes in quick succession)
|
|
1010
|
-
await this.keyedThrottler.onIdleOnce(util_1.util.uriToPath(params.textDocument.uri), true);
|
|
1011
|
-
//wait for the validation cycle to settle
|
|
1012
|
-
await this.onValidateSettled();
|
|
388
|
+
this.logger.debug('onFullSemanticTokens', params);
|
|
1013
389
|
const srcPath = util_1.util.uriToPath(params.textDocument.uri);
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
if (semanticTokens !== undefined) {
|
|
1019
|
-
return {
|
|
1020
|
-
data: (0, SemanticTokenUtils_1.encodeSemanticTokens)(semanticTokens)
|
|
1021
|
-
};
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
390
|
+
const result = await this.projectManager.getSemanticTokens({ srcPath: srcPath });
|
|
391
|
+
return {
|
|
392
|
+
data: (0, SemanticTokenUtils_1.encodeSemanticTokens)(result)
|
|
393
|
+
};
|
|
1025
394
|
}
|
|
1026
|
-
async
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
const patch = this.diagnosticCollection.getPatch(this.projects);
|
|
1032
|
-
for (let filePath in patch) {
|
|
1033
|
-
const uri = vscode_uri_1.URI.file(filePath).toString();
|
|
1034
|
-
const diagnostics = patch[filePath].map(d => util_1.util.toDiagnostic(d, uri));
|
|
1035
|
-
await this.connection.sendDiagnostics({
|
|
1036
|
-
uri: uri,
|
|
1037
|
-
diagnostics: diagnostics
|
|
1038
|
-
});
|
|
1039
|
-
}
|
|
1040
|
-
});
|
|
395
|
+
async onCodeAction(params) {
|
|
396
|
+
this.logger.debug('onCodeAction', params);
|
|
397
|
+
const srcPath = util_1.util.uriToPath(params.textDocument.uri);
|
|
398
|
+
const result = await this.projectManager.getCodeActions({ srcPath: srcPath, range: params.range });
|
|
399
|
+
return result;
|
|
1041
400
|
}
|
|
1042
401
|
async onExecuteCommand(params) {
|
|
1043
|
-
|
|
402
|
+
this.logger.debug('onExecuteCommand', params);
|
|
1044
403
|
if (params.command === CustomCommands.TranspileFile) {
|
|
1045
|
-
const
|
|
404
|
+
const args = {
|
|
405
|
+
srcPath: params.arguments[0]
|
|
406
|
+
};
|
|
407
|
+
const result = await this.projectManager.transpileFile(args);
|
|
1046
408
|
//back-compat: include `pathAbsolute` property so older vscode versions still work
|
|
1047
409
|
result.pathAbsolute = result.srcPath;
|
|
1048
410
|
return result;
|
|
1049
411
|
}
|
|
1050
412
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
413
|
+
/**
|
|
414
|
+
* Establish a connection to the client if not already connected
|
|
415
|
+
*/
|
|
416
|
+
establishConnection() {
|
|
417
|
+
if (!this.connection) {
|
|
418
|
+
this.connection = (0, node_1.createConnection)(node_1.ProposedFeatures.all);
|
|
419
|
+
}
|
|
420
|
+
return this.connection;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Send a new busy status notification to the client based on the current busy status
|
|
424
|
+
*/
|
|
425
|
+
sendBusyStatus() {
|
|
426
|
+
var _a;
|
|
427
|
+
this.busyStatusIndex = ++this.busyStatusIndex <= 0 ? 0 : this.busyStatusIndex;
|
|
428
|
+
(_a = this.connection.sendNotification(NotificationName.busyStatus, {
|
|
429
|
+
status: this.projectManager.busyStatusTracker.status,
|
|
430
|
+
timestamp: Date.now(),
|
|
431
|
+
index: this.busyStatusIndex,
|
|
432
|
+
activeRuns: [
|
|
433
|
+
//extract only specific information from the active run so we know what's going on
|
|
434
|
+
...this.projectManager.busyStatusTracker.activeRuns.map(x => {
|
|
435
|
+
var _a;
|
|
436
|
+
return ({
|
|
437
|
+
scope: (_a = x.scope) === null || _a === void 0 ? void 0 : _a.projectIdentifier,
|
|
438
|
+
label: x.label,
|
|
439
|
+
startTime: x.startTime.getTime()
|
|
440
|
+
});
|
|
441
|
+
})
|
|
442
|
+
]
|
|
443
|
+
})) === null || _a === void 0 ? void 0 : _a.catch(logAndIgnoreError);
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Populate the path filterer with the client's include/exclude lists and the projects include lists
|
|
447
|
+
* @returns the instance of the path filterer
|
|
448
|
+
*/
|
|
449
|
+
async rebuildPathFilterer() {
|
|
450
|
+
var _a;
|
|
451
|
+
//dispose of any previous pathFilterer disposables
|
|
452
|
+
(_a = this.pathFiltererDisposables) === null || _a === void 0 ? void 0 : _a.forEach(dispose => dispose());
|
|
453
|
+
//keep track of all the pathFilterer disposables so we can dispose them later
|
|
454
|
+
this.pathFiltererDisposables = [];
|
|
455
|
+
const workspaceConfigs = await this.getWorkspaceConfigs();
|
|
456
|
+
await Promise.all(workspaceConfigs.map(async (workspaceConfig) => {
|
|
457
|
+
const rootDir = util_1.util.uriToPath(workspaceConfig.workspaceFolder);
|
|
458
|
+
//always exclude everything from these common folders
|
|
459
|
+
this.pathFiltererDisposables.push(this.pathFilterer.registerExcludeList(rootDir, [
|
|
460
|
+
'**/node_modules/**/*',
|
|
461
|
+
'**/.git/**/*',
|
|
462
|
+
'out/**/*',
|
|
463
|
+
'**/.roku-deploy-staging/**/*'
|
|
464
|
+
]));
|
|
465
|
+
//get any `files.exclude` patterns from the client from this workspace
|
|
466
|
+
this.pathFiltererDisposables.push(this.pathFilterer.registerExcludeList(rootDir, workspaceConfig.excludePatterns));
|
|
467
|
+
//get any .gitignore patterns from the client from this workspace
|
|
468
|
+
const gitignorePath = path.resolve(rootDir, '.gitignore');
|
|
469
|
+
if (await fsExtra.pathExists(gitignorePath)) {
|
|
470
|
+
const matcher = (0, ignore_1.default)({ ignoreCase: true }).add(fsExtra.readFileSync(gitignorePath).toString());
|
|
471
|
+
this.pathFiltererDisposables.push(this.pathFilterer.registerExcludeMatcher((p) => {
|
|
472
|
+
const relPath = path.relative(rootDir, p);
|
|
473
|
+
if (ignore_1.default.isPathValid(relPath)) {
|
|
474
|
+
return matcher.test(relPath).ignored;
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
//we do not have a valid relative path, so we cannot determine if it is ignored...thus it is NOT ignored
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
}));
|
|
1058
481
|
}
|
|
482
|
+
}));
|
|
483
|
+
this.logger.log('pathFilterer successfully reconstructed');
|
|
484
|
+
return this.pathFilterer;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Ask the client for the list of `files.exclude` patterns. Useful when determining if we should process a file
|
|
488
|
+
*/
|
|
489
|
+
async getWorkspaceExcludeGlobs(workspaceFolder) {
|
|
490
|
+
var _a;
|
|
491
|
+
const config = await this.getClientConfiguration(workspaceFolder, 'files');
|
|
492
|
+
const result = Object
|
|
493
|
+
.keys((_a = config === null || config === void 0 ? void 0 : config.exclude) !== null && _a !== void 0 ? _a : {})
|
|
494
|
+
.filter(x => { var _a; return (_a = config === null || config === void 0 ? void 0 : config.exclude) === null || _a === void 0 ? void 0 : _a[x]; })
|
|
495
|
+
//vscode files.exclude patterns support ignoring folders without needing to add `**/*`. So for our purposes, we need to
|
|
496
|
+
//append **/* to everything without a file extension or magic at the end
|
|
497
|
+
.map(pattern => [
|
|
498
|
+
//send the pattern as-is (this handles weird cases and exact file matches)
|
|
499
|
+
pattern,
|
|
500
|
+
//treat the pattern as a directory (no harm in doing this because if it's a file, the pattern will just never match anything)
|
|
501
|
+
`${pattern}/**/*`
|
|
502
|
+
])
|
|
503
|
+
.flat(1);
|
|
504
|
+
return result;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Ask the project manager to sync all projects found within the list of workspaces
|
|
508
|
+
* @param forceReload if true, all projects are discarded and recreated from scratch
|
|
509
|
+
*/
|
|
510
|
+
async syncProjects(forceReload = false) {
|
|
511
|
+
const workspaces = await this.getWorkspaceConfigs();
|
|
512
|
+
await this.projectManager.syncProjects(workspaces, forceReload);
|
|
513
|
+
//set our logLevel to the most verbose log level found across all projects and workspaces
|
|
514
|
+
await this.syncLogLevel();
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Given a workspaceFolder path, get the specified configuration from the client (if applicable).
|
|
518
|
+
* Be sure to use optional chaining to traverse the result in case that configuration doesn't exist or the client doesn't support `getConfiguration`
|
|
519
|
+
* @param workspaceFolder the folder for the workspace in the client
|
|
520
|
+
*/
|
|
521
|
+
async getClientConfiguration(workspaceFolder, section) {
|
|
522
|
+
const scopeUri = util_1.util.pathToUri(workspaceFolder);
|
|
523
|
+
let config = {};
|
|
524
|
+
//if the client supports configuration, look for config group called "brightscript"
|
|
525
|
+
if (this.hasConfigurationCapability) {
|
|
526
|
+
config = await this.connection.workspace.getConfiguration({
|
|
527
|
+
scopeUri: scopeUri,
|
|
528
|
+
section: section
|
|
529
|
+
});
|
|
1059
530
|
}
|
|
531
|
+
return config;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Send a critical failure notification to the client, which should show a notification of some kind
|
|
535
|
+
*/
|
|
536
|
+
sendCriticalFailure(message) {
|
|
537
|
+
this.connection.sendNotification('critical-failure', message).catch(logAndIgnoreError);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Send diagnostics to the client
|
|
541
|
+
*/
|
|
542
|
+
async sendDiagnostics(options) {
|
|
543
|
+
const patch = this.diagnosticCollection.getPatch(options.project.projectNumber, options.diagnostics);
|
|
544
|
+
await Promise.all(Object.keys(patch).map(async (srcPath) => {
|
|
545
|
+
const uri = vscode_uri_1.URI.file(srcPath).toString();
|
|
546
|
+
const diagnostics = patch[srcPath].map(d => util_1.util.toDiagnostic(d, uri));
|
|
547
|
+
await this.connection.sendDiagnostics({
|
|
548
|
+
uri: uri,
|
|
549
|
+
diagnostics: diagnostics
|
|
550
|
+
});
|
|
551
|
+
}));
|
|
1060
552
|
}
|
|
1061
553
|
dispose() {
|
|
1062
|
-
var _a;
|
|
554
|
+
var _a, _b, _c;
|
|
1063
555
|
(_a = this.loggerSubscription) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
1064
|
-
this.
|
|
556
|
+
(_c = (_b = this.projectManager) === null || _b === void 0 ? void 0 : _b.dispose) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
1065
557
|
}
|
|
1066
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* The default threading setting for the language server. Can be overridden by per-workspace settings
|
|
561
|
+
*/
|
|
562
|
+
LanguageServer.enableThreadingDefault = true;
|
|
1067
563
|
__decorate([
|
|
1068
564
|
AddStackToErrorMessage
|
|
1069
565
|
], LanguageServer.prototype, "onInitialize", null);
|
|
1070
566
|
__decorate([
|
|
1071
|
-
|
|
1072
|
-
], LanguageServer.prototype, "getProjectPaths", null);
|
|
1073
|
-
__decorate([
|
|
1074
|
-
TrackBusyStatus
|
|
1075
|
-
], LanguageServer.prototype, "syncProjects", null);
|
|
1076
|
-
__decorate([
|
|
1077
|
-
AddStackToErrorMessage,
|
|
1078
|
-
TrackBusyStatus
|
|
567
|
+
AddStackToErrorMessage
|
|
1079
568
|
], LanguageServer.prototype, "onInitialized", null);
|
|
1080
569
|
__decorate([
|
|
1081
|
-
|
|
1082
|
-
], LanguageServer.prototype, "
|
|
570
|
+
AddStackToErrorMessage
|
|
571
|
+
], LanguageServer.prototype, "onTextDocumentDidChangeContent", null);
|
|
1083
572
|
__decorate([
|
|
1084
|
-
AddStackToErrorMessage
|
|
1085
|
-
|
|
1086
|
-
], LanguageServer.prototype, "onCompletion", null);
|
|
573
|
+
AddStackToErrorMessage
|
|
574
|
+
], LanguageServer.prototype, "onDidChangeWatchedFiles", null);
|
|
1087
575
|
__decorate([
|
|
1088
576
|
AddStackToErrorMessage
|
|
1089
|
-
], LanguageServer.prototype, "
|
|
577
|
+
], LanguageServer.prototype, "onDocumentClose", null);
|
|
1090
578
|
__decorate([
|
|
1091
|
-
AddStackToErrorMessage
|
|
1092
|
-
|
|
1093
|
-
], LanguageServer.prototype, "onCodeAction", null);
|
|
579
|
+
AddStackToErrorMessage
|
|
580
|
+
], LanguageServer.prototype, "onCompletion", null);
|
|
1094
581
|
__decorate([
|
|
1095
582
|
AddStackToErrorMessage
|
|
1096
583
|
], LanguageServer.prototype, "onDidChangeConfiguration", null);
|
|
1097
|
-
__decorate([
|
|
1098
|
-
AddStackToErrorMessage,
|
|
1099
|
-
TrackBusyStatus
|
|
1100
|
-
], LanguageServer.prototype, "onDidChangeWatchedFiles", null);
|
|
1101
584
|
__decorate([
|
|
1102
585
|
AddStackToErrorMessage
|
|
1103
586
|
], LanguageServer.prototype, "onHover", null);
|
|
1104
587
|
__decorate([
|
|
1105
588
|
AddStackToErrorMessage
|
|
1106
|
-
], LanguageServer.prototype, "onDocumentClose", null);
|
|
1107
|
-
__decorate([
|
|
1108
|
-
AddStackToErrorMessage,
|
|
1109
|
-
TrackBusyStatus
|
|
1110
|
-
], LanguageServer.prototype, "validateTextDocument", null);
|
|
1111
|
-
__decorate([
|
|
1112
|
-
TrackBusyStatus
|
|
1113
|
-
], LanguageServer.prototype, "validateAll", null);
|
|
1114
|
-
__decorate([
|
|
1115
|
-
AddStackToErrorMessage,
|
|
1116
|
-
TrackBusyStatus
|
|
1117
589
|
], LanguageServer.prototype, "onWorkspaceSymbol", null);
|
|
1118
590
|
__decorate([
|
|
1119
|
-
AddStackToErrorMessage
|
|
1120
|
-
TrackBusyStatus
|
|
591
|
+
AddStackToErrorMessage
|
|
1121
592
|
], LanguageServer.prototype, "onDocumentSymbol", null);
|
|
1122
593
|
__decorate([
|
|
1123
|
-
AddStackToErrorMessage
|
|
1124
|
-
TrackBusyStatus
|
|
594
|
+
AddStackToErrorMessage
|
|
1125
595
|
], LanguageServer.prototype, "onDefinition", null);
|
|
1126
596
|
__decorate([
|
|
1127
|
-
AddStackToErrorMessage
|
|
1128
|
-
TrackBusyStatus
|
|
597
|
+
AddStackToErrorMessage
|
|
1129
598
|
], LanguageServer.prototype, "onSignatureHelp", null);
|
|
1130
599
|
__decorate([
|
|
1131
|
-
AddStackToErrorMessage
|
|
1132
|
-
TrackBusyStatus
|
|
600
|
+
AddStackToErrorMessage
|
|
1133
601
|
], LanguageServer.prototype, "onReferences", null);
|
|
1134
602
|
__decorate([
|
|
1135
|
-
AddStackToErrorMessage
|
|
1136
|
-
TrackBusyStatus
|
|
603
|
+
AddStackToErrorMessage
|
|
1137
604
|
], LanguageServer.prototype, "onFullSemanticTokens", null);
|
|
1138
605
|
__decorate([
|
|
1139
|
-
AddStackToErrorMessage
|
|
1140
|
-
|
|
606
|
+
AddStackToErrorMessage
|
|
607
|
+
], LanguageServer.prototype, "onCodeAction", null);
|
|
608
|
+
__decorate([
|
|
609
|
+
AddStackToErrorMessage
|
|
1141
610
|
], LanguageServer.prototype, "onExecuteCommand", null);
|
|
1142
611
|
exports.LanguageServer = LanguageServer;
|
|
1143
612
|
var CustomCommands;
|
|
@@ -1179,16 +648,10 @@ function AddStackToErrorMessage(target, propertyKey, descriptor) {
|
|
|
1179
648
|
}
|
|
1180
649
|
};
|
|
1181
650
|
}
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
//wrapping the original method
|
|
1188
|
-
descriptor.value = function value(...args) {
|
|
1189
|
-
return this.busyStatusTracker.run(() => {
|
|
1190
|
-
return originalMethod.apply(this, args);
|
|
1191
|
-
}, originalMethod.name);
|
|
1192
|
-
};
|
|
651
|
+
function logAndIgnoreError(error) {
|
|
652
|
+
if (error === null || error === void 0 ? void 0 : error.stack) {
|
|
653
|
+
error.message = error.stack;
|
|
654
|
+
}
|
|
655
|
+
console.error(error);
|
|
1193
656
|
}
|
|
1194
657
|
//# sourceMappingURL=LanguageServer.js.map
|