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
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import type { Diagnostic, Position, Range, Location, DocumentSymbol, WorkspaceSymbol, CodeAction, CompletionList } from 'vscode-languageserver-protocol';
|
|
2
|
+
import type { Hover, MaybePromise, SemanticToken } from '../interfaces';
|
|
3
|
+
import type { DocumentAction, DocumentActionWithStatus } from './DocumentManager';
|
|
4
|
+
import type { FileTranspileResult, SignatureInfoObj } from '../Program';
|
|
5
|
+
import type { Logger, LogLevel } from '../logging';
|
|
6
|
+
/**
|
|
7
|
+
* Defines the contract between the ProjectManager and the main or worker thread Project classes
|
|
8
|
+
*/
|
|
9
|
+
export interface LspProject {
|
|
10
|
+
/**
|
|
11
|
+
* Is this a standalone project?
|
|
12
|
+
*/
|
|
13
|
+
isStandaloneProject: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* A logger instance used for logging in this project
|
|
16
|
+
*/
|
|
17
|
+
logger: Logger;
|
|
18
|
+
/**
|
|
19
|
+
* The config used to activate this project
|
|
20
|
+
*/
|
|
21
|
+
activateOptions: ProjectConfig;
|
|
22
|
+
/**
|
|
23
|
+
* The path to where the project resides
|
|
24
|
+
*/
|
|
25
|
+
projectPath: string;
|
|
26
|
+
/**
|
|
27
|
+
* A unique number for this project, generated during this current language server session. Mostly used so we can identify which project is doing logging
|
|
28
|
+
*/
|
|
29
|
+
projectNumber: number;
|
|
30
|
+
/**
|
|
31
|
+
* A unique name for this project used in logs to help keep track of everything
|
|
32
|
+
*/
|
|
33
|
+
projectIdentifier: string;
|
|
34
|
+
/**
|
|
35
|
+
* The root directory of the project.
|
|
36
|
+
* Only available after `.activate()` has completed
|
|
37
|
+
*/
|
|
38
|
+
rootDir: string;
|
|
39
|
+
/**
|
|
40
|
+
* The file patterns from bsconfig.json that were used to find all files for this project
|
|
41
|
+
*/
|
|
42
|
+
filePatterns: string[];
|
|
43
|
+
/**
|
|
44
|
+
* Path to a bsconfig.json file that will be used for this project.
|
|
45
|
+
* Only available after `.activate()` has completed
|
|
46
|
+
*/
|
|
47
|
+
bsconfigPath?: string;
|
|
48
|
+
/**
|
|
49
|
+
* The contents of the bsconfig.json file. This is used to detect when the bsconfig file has not actually been changed (even if the fs says it did).
|
|
50
|
+
*
|
|
51
|
+
* Only available after `.activate()` has completed.
|
|
52
|
+
* @deprecated do not depend on this property. This will certainly be removed in a future release
|
|
53
|
+
*/
|
|
54
|
+
bsconfigFileContents?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Initialize and start running the project. This will scan for all files, and build a full project in memory, then validate the project
|
|
57
|
+
* @param options
|
|
58
|
+
*/
|
|
59
|
+
activate(options: ProjectConfig): MaybePromise<ActivateResponse>;
|
|
60
|
+
/**
|
|
61
|
+
* Get a promise that resolves when the project finishes activating
|
|
62
|
+
*/
|
|
63
|
+
whenActivated(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Validate the project. This will trigger a full validation on any scopes that were changed since the last validation,
|
|
66
|
+
* and will also eventually emit a new 'diagnostics' event that includes all diagnostics for the project
|
|
67
|
+
*/
|
|
68
|
+
validate(): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Cancel any active validation that's running
|
|
71
|
+
*/
|
|
72
|
+
cancelValidate(): MaybePromise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Get the list of all diagnostics from this project
|
|
75
|
+
*/
|
|
76
|
+
getDiagnostics(): MaybePromise<LspDiagnostic[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Get the full list of semantic tokens for the given file path
|
|
79
|
+
* @param srcPath absolute path to the source file
|
|
80
|
+
*/
|
|
81
|
+
getSemanticTokens(options: {
|
|
82
|
+
srcPath: string;
|
|
83
|
+
}): MaybePromise<SemanticToken[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Transpile the specified file
|
|
86
|
+
* @param srcPath
|
|
87
|
+
*/
|
|
88
|
+
transpileFile(options: {
|
|
89
|
+
srcPath: string;
|
|
90
|
+
}): MaybePromise<FileTranspileResult>;
|
|
91
|
+
/**
|
|
92
|
+
* Get the hover information for the specified position in the specified file
|
|
93
|
+
*/
|
|
94
|
+
getHover(options: {
|
|
95
|
+
srcPath: string;
|
|
96
|
+
position: Position;
|
|
97
|
+
}): MaybePromise<Hover[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Get the locations where the symbol at the specified position is defined
|
|
100
|
+
* @param options the file path and position to get the definition for
|
|
101
|
+
*/
|
|
102
|
+
getDefinition(options: {
|
|
103
|
+
srcPath: string;
|
|
104
|
+
position: Position;
|
|
105
|
+
}): MaybePromise<Location[]>;
|
|
106
|
+
/**
|
|
107
|
+
* Get the locations where the symbol at the specified position is defined
|
|
108
|
+
* @param options the file path and position to get the definition for
|
|
109
|
+
*/
|
|
110
|
+
getSignatureHelp(options: {
|
|
111
|
+
srcPath: string;
|
|
112
|
+
position: Position;
|
|
113
|
+
}): MaybePromise<SignatureInfoObj[]>;
|
|
114
|
+
/**
|
|
115
|
+
* Get the list of symbols for the specified file
|
|
116
|
+
*/
|
|
117
|
+
getDocumentSymbol(options: {
|
|
118
|
+
srcPath: string;
|
|
119
|
+
}): MaybePromise<DocumentSymbol[]>;
|
|
120
|
+
/**
|
|
121
|
+
* Get the list of symbols for the entire workspace
|
|
122
|
+
*/
|
|
123
|
+
getWorkspaceSymbol(): Promise<WorkspaceSymbol[]>;
|
|
124
|
+
/**
|
|
125
|
+
* Get the list of references for the specified file and position
|
|
126
|
+
*/
|
|
127
|
+
getReferences(options: {
|
|
128
|
+
srcPath: string;
|
|
129
|
+
position: Position;
|
|
130
|
+
}): MaybePromise<Location[]>;
|
|
131
|
+
/**
|
|
132
|
+
* Get all of the code actions for the specified file and range
|
|
133
|
+
*/
|
|
134
|
+
getCodeActions(options: {
|
|
135
|
+
srcPath: string;
|
|
136
|
+
range: Range;
|
|
137
|
+
}): Promise<CodeAction[]>;
|
|
138
|
+
/**
|
|
139
|
+
* Get the completions for the specified file and position
|
|
140
|
+
*/
|
|
141
|
+
getCompletions(options: {
|
|
142
|
+
srcPath: string;
|
|
143
|
+
position: Position;
|
|
144
|
+
}): Promise<CompletionList>;
|
|
145
|
+
/**
|
|
146
|
+
* Apply a series of file changes to the program.
|
|
147
|
+
* This will cancel any active validation.
|
|
148
|
+
* @param documentActions
|
|
149
|
+
* @returns a boolean indicating whether this project accepted any of the file changes. If false, then this project didn't recognize any of the files and thus did nothing
|
|
150
|
+
*/
|
|
151
|
+
applyFileChanges(documentActions: DocumentAction[]): Promise<DocumentActionWithStatus[]>;
|
|
152
|
+
/**
|
|
153
|
+
* An event that is emitted anytime the diagnostics for the project have changed (typically after a validate cycle has finished)
|
|
154
|
+
* @param eventName
|
|
155
|
+
* @param handler
|
|
156
|
+
*/
|
|
157
|
+
on(eventName: 'diagnostics', handler: (data: {
|
|
158
|
+
diagnostics: LspDiagnostic[];
|
|
159
|
+
}) => void): any;
|
|
160
|
+
on(eventName: 'all', handler: (eventName: string, data: Record<string, any>) => void): any;
|
|
161
|
+
/**
|
|
162
|
+
* List of items to dispose when this project is disposed
|
|
163
|
+
*/
|
|
164
|
+
disposables: Array<{
|
|
165
|
+
dispose(): void;
|
|
166
|
+
}>;
|
|
167
|
+
/**
|
|
168
|
+
* Release all resources so this file can be safely garbage collected
|
|
169
|
+
*/
|
|
170
|
+
dispose(): void;
|
|
171
|
+
}
|
|
172
|
+
export interface ProjectConfig {
|
|
173
|
+
/**
|
|
174
|
+
* Path to the project
|
|
175
|
+
*/
|
|
176
|
+
projectPath: string;
|
|
177
|
+
/**
|
|
178
|
+
* Path to the workspace in which all project files reside or are referenced by
|
|
179
|
+
*/
|
|
180
|
+
workspaceFolder: string;
|
|
181
|
+
/**
|
|
182
|
+
* A list of glob patterns used to _exclude_ files from various bsconfig searches
|
|
183
|
+
*/
|
|
184
|
+
excludePatterns?: string[];
|
|
185
|
+
/**
|
|
186
|
+
* An optional project number to assign to the project within the context of a language server. reloaded projects should keep the same number if possible
|
|
187
|
+
*/
|
|
188
|
+
projectNumber?: number;
|
|
189
|
+
/**
|
|
190
|
+
* Path to a bsconfig that should be used instead of the auto-discovery algorithm. If this is present, no bsconfig discovery should be used. and an error should be emitted if this file is missing
|
|
191
|
+
*/
|
|
192
|
+
bsconfigPath?: string;
|
|
193
|
+
/**
|
|
194
|
+
* Should this project run in its own dedicated worker thread
|
|
195
|
+
* TODO - is there a better name for this?
|
|
196
|
+
*/
|
|
197
|
+
enableThreading?: boolean;
|
|
198
|
+
/**
|
|
199
|
+
* If present, this will override any files array found in bsconfig or the default.
|
|
200
|
+
*
|
|
201
|
+
* The list of file globs used to find all files for the project
|
|
202
|
+
* If using the {src;dest;} format, you can specify a different destination directory
|
|
203
|
+
* for the matched files in src.
|
|
204
|
+
*
|
|
205
|
+
*/
|
|
206
|
+
files?: Array<string | {
|
|
207
|
+
src: string | string[];
|
|
208
|
+
dest?: string;
|
|
209
|
+
}>;
|
|
210
|
+
}
|
|
211
|
+
export interface LspDiagnostic extends Diagnostic {
|
|
212
|
+
uri: string;
|
|
213
|
+
}
|
|
214
|
+
export interface ActivateResponse {
|
|
215
|
+
/**
|
|
216
|
+
* The root directory of the project
|
|
217
|
+
*/
|
|
218
|
+
rootDir: string;
|
|
219
|
+
/**
|
|
220
|
+
* The path to the config file (i.e. `bsconfig.json`) that was used to load this project
|
|
221
|
+
*/
|
|
222
|
+
bsconfigPath: string;
|
|
223
|
+
/**
|
|
224
|
+
* The file patterns from bsconfig.json that were used to find all files for this project
|
|
225
|
+
*/
|
|
226
|
+
filePatterns: string[];
|
|
227
|
+
/**
|
|
228
|
+
* The logLevel used for this project's logger
|
|
229
|
+
*/
|
|
230
|
+
logLevel: LogLevel;
|
|
231
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LspProject.js","sourceRoot":"","sources":["../../src/lsp/LspProject.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Logger } from '../logging';
|
|
2
|
+
/**
|
|
3
|
+
* Manage collections of glob patterns used to filter paths.
|
|
4
|
+
*
|
|
5
|
+
* excludeLists are evaluated first to see if a path should be excluded. If the path is excluded, we then test it against the includeLists.
|
|
6
|
+
* If the path matches an includeList, it will be included. If not, it will remain excluded.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PathFilterer {
|
|
9
|
+
constructor(options?: {
|
|
10
|
+
logger?: Logger;
|
|
11
|
+
});
|
|
12
|
+
private logger;
|
|
13
|
+
private includeCollections;
|
|
14
|
+
private excludeCollections;
|
|
15
|
+
/**
|
|
16
|
+
* Filter the given list of entries based on the registered include and exclude lists.
|
|
17
|
+
* @param entries the list of paths (or objects having paths) to filter
|
|
18
|
+
* @param fetcher a function that can extract the path from the entry if it's not a string
|
|
19
|
+
* @returns the filtered list of entries
|
|
20
|
+
*/
|
|
21
|
+
filter<T = string>(entries: T[], fetcher?: (path: T) => string): T[];
|
|
22
|
+
/**
|
|
23
|
+
* Does the path match at least one of the exclusions lists
|
|
24
|
+
*/
|
|
25
|
+
private isExclusionsMatch;
|
|
26
|
+
/**
|
|
27
|
+
* Does the path match at least one of the inclusions lists
|
|
28
|
+
*/
|
|
29
|
+
private isInclusionsMatch;
|
|
30
|
+
/**
|
|
31
|
+
* Register a list of inclusive globs that should be evaluated together
|
|
32
|
+
* These should be things like the `files` array from a bsconfig.json
|
|
33
|
+
*/
|
|
34
|
+
registerIncludeList(rootDir: string, globs: string[]): () => void;
|
|
35
|
+
/**
|
|
36
|
+
* Register glob patterns for files that should be _excluded_. positive patterns mean a file is excluded,
|
|
37
|
+
* and negative patterns mean a file that was previously matched (excluded) should be unmatched (included)
|
|
38
|
+
* These should be things like .gitignore or vscode's `files.exclude`.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* [
|
|
43
|
+
* '.git',
|
|
44
|
+
* 'node_modules'
|
|
45
|
+
* '!node_modules/@rokucommunity/bslib'
|
|
46
|
+
* ]
|
|
47
|
+
* ```
|
|
48
|
+
* would exclude all files in the `.git` and `node_modules` directories, but would include the `node_modules/@rokucommunity/bslib` directory
|
|
49
|
+
*/
|
|
50
|
+
registerExcludeList(rootDir: string, globs: string[]): () => void;
|
|
51
|
+
registerExcludeMatcher(matcher: (path: string) => boolean): () => void;
|
|
52
|
+
private removeCollection;
|
|
53
|
+
/**
|
|
54
|
+
* Remove all registered collections
|
|
55
|
+
*/
|
|
56
|
+
clear(): void;
|
|
57
|
+
}
|
|
58
|
+
export declare class PathCollection {
|
|
59
|
+
options: {
|
|
60
|
+
rootDir: string;
|
|
61
|
+
globs: string[];
|
|
62
|
+
} | {
|
|
63
|
+
matcher: (path: string) => boolean;
|
|
64
|
+
isExcludePattern: boolean;
|
|
65
|
+
};
|
|
66
|
+
constructor(options: {
|
|
67
|
+
rootDir: string;
|
|
68
|
+
globs: string[];
|
|
69
|
+
} | {
|
|
70
|
+
matcher: (path: string) => boolean;
|
|
71
|
+
isExcludePattern: boolean;
|
|
72
|
+
});
|
|
73
|
+
private matchers;
|
|
74
|
+
isMatch(path: string): boolean;
|
|
75
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PathCollection = exports.PathFilterer = void 0;
|
|
4
|
+
const micromatch = require("micromatch");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const logging_1 = require("../logging");
|
|
7
|
+
const util_1 = require("../util");
|
|
8
|
+
/**
|
|
9
|
+
* Manage collections of glob patterns used to filter paths.
|
|
10
|
+
*
|
|
11
|
+
* excludeLists are evaluated first to see if a path should be excluded. If the path is excluded, we then test it against the includeLists.
|
|
12
|
+
* If the path matches an includeList, it will be included. If not, it will remain excluded.
|
|
13
|
+
*/
|
|
14
|
+
class PathFilterer {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
var _a;
|
|
17
|
+
this.includeCollections = [];
|
|
18
|
+
this.excludeCollections = [];
|
|
19
|
+
this.logger = (_a = options === null || options === void 0 ? void 0 : options.logger) !== null && _a !== void 0 ? _a : (0, logging_1.createLogger)();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Filter the given list of entries based on the registered include and exclude lists.
|
|
23
|
+
* @param entries the list of paths (or objects having paths) to filter
|
|
24
|
+
* @param fetcher a function that can extract the path from the entry if it's not a string
|
|
25
|
+
* @returns the filtered list of entries
|
|
26
|
+
*/
|
|
27
|
+
filter(entries, fetcher) {
|
|
28
|
+
var _a;
|
|
29
|
+
//if there are no exclude lists, then all files should be included
|
|
30
|
+
if (this.excludeCollections.length === 0) {
|
|
31
|
+
return entries;
|
|
32
|
+
}
|
|
33
|
+
let results = [];
|
|
34
|
+
//process each path
|
|
35
|
+
for (let entry of entries) {
|
|
36
|
+
let srcPath = (_a = fetcher === null || fetcher === void 0 ? void 0 : fetcher(entry)) !== null && _a !== void 0 ? _a : entry;
|
|
37
|
+
//if this path is excluded
|
|
38
|
+
if (this.isExclusionsMatch(srcPath)) {
|
|
39
|
+
//if this path is re-included, keep it
|
|
40
|
+
if (this.isInclusionsMatch(srcPath)) {
|
|
41
|
+
results.push(entry);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
//this path should be excluded
|
|
45
|
+
}
|
|
46
|
+
//this path is not excluded, so keep it
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
results.push(entry);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return results;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Does the path match at least one of the exclusions lists
|
|
56
|
+
*/
|
|
57
|
+
isExclusionsMatch(path) {
|
|
58
|
+
//does this path match an exclusion list?
|
|
59
|
+
for (const collection of this.excludeCollections) {
|
|
60
|
+
if (collection.isMatch(path)) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Does the path match at least one of the inclusions lists
|
|
68
|
+
*/
|
|
69
|
+
isInclusionsMatch(path) {
|
|
70
|
+
//does this path match an exclusion list?
|
|
71
|
+
for (const collection of this.includeCollections) {
|
|
72
|
+
if (collection.isMatch(path)) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Register a list of inclusive globs that should be evaluated together
|
|
80
|
+
* These should be things like the `files` array from a bsconfig.json
|
|
81
|
+
*/
|
|
82
|
+
registerIncludeList(rootDir, globs) {
|
|
83
|
+
this.logger.debug('registerIncludeList', { rootDir: rootDir, globs: globs });
|
|
84
|
+
let collection = new PathCollection({
|
|
85
|
+
rootDir: rootDir,
|
|
86
|
+
globs: globs
|
|
87
|
+
});
|
|
88
|
+
this.includeCollections.push(collection);
|
|
89
|
+
return () => {
|
|
90
|
+
this.removeCollection(collection);
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Register glob patterns for files that should be _excluded_. positive patterns mean a file is excluded,
|
|
95
|
+
* and negative patterns mean a file that was previously matched (excluded) should be unmatched (included)
|
|
96
|
+
* These should be things like .gitignore or vscode's `files.exclude`.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* [
|
|
101
|
+
* '.git',
|
|
102
|
+
* 'node_modules'
|
|
103
|
+
* '!node_modules/@rokucommunity/bslib'
|
|
104
|
+
* ]
|
|
105
|
+
* ```
|
|
106
|
+
* would exclude all files in the `.git` and `node_modules` directories, but would include the `node_modules/@rokucommunity/bslib` directory
|
|
107
|
+
*/
|
|
108
|
+
registerExcludeList(rootDir, globs) {
|
|
109
|
+
this.logger.debug('registerExcludeList', { rootDir: rootDir, globs: globs });
|
|
110
|
+
let collection = new PathCollection({
|
|
111
|
+
rootDir: rootDir,
|
|
112
|
+
globs: globs
|
|
113
|
+
});
|
|
114
|
+
this.excludeCollections.push(collection);
|
|
115
|
+
return () => {
|
|
116
|
+
this.removeCollection(collection);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
registerExcludeMatcher(matcher) {
|
|
120
|
+
this.logger.debug('registerExcludeMatcher', matcher);
|
|
121
|
+
const collection = new PathCollection({
|
|
122
|
+
matcher: matcher,
|
|
123
|
+
isExcludePattern: false
|
|
124
|
+
});
|
|
125
|
+
this.excludeCollections.push(collection);
|
|
126
|
+
return () => {
|
|
127
|
+
this.removeCollection(collection);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
removeCollection(collection) {
|
|
131
|
+
let idx = this.includeCollections.indexOf(collection);
|
|
132
|
+
if (idx > -1) {
|
|
133
|
+
this.includeCollections.splice(idx, 1);
|
|
134
|
+
}
|
|
135
|
+
idx = this.excludeCollections.indexOf(collection);
|
|
136
|
+
if (idx > -1) {
|
|
137
|
+
this.excludeCollections.splice(idx, 1);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Remove all registered collections
|
|
142
|
+
*/
|
|
143
|
+
clear() {
|
|
144
|
+
this.includeCollections = [];
|
|
145
|
+
this.excludeCollections = [];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.PathFilterer = PathFilterer;
|
|
149
|
+
class PathCollection {
|
|
150
|
+
constructor(options) {
|
|
151
|
+
var _a;
|
|
152
|
+
this.options = options;
|
|
153
|
+
this.matchers = [];
|
|
154
|
+
if ('globs' in options) {
|
|
155
|
+
//build matcher patterns from the globs
|
|
156
|
+
for (let glob of (_a = options.globs) !== null && _a !== void 0 ? _a : []) {
|
|
157
|
+
let isExcludePattern = glob.startsWith('!');
|
|
158
|
+
if (isExcludePattern) {
|
|
159
|
+
glob = glob.substring(1);
|
|
160
|
+
}
|
|
161
|
+
const pattern = path.resolve(options.rootDir, glob).replace(/\\+/g, '/');
|
|
162
|
+
this.matchers.push({
|
|
163
|
+
pattern: pattern,
|
|
164
|
+
isMatch: micromatch.matcher(pattern),
|
|
165
|
+
isExcludePattern: isExcludePattern
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
this.matchers.push({
|
|
171
|
+
isMatch: options.matcher,
|
|
172
|
+
isExcludePattern: options.isExcludePattern
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
isMatch(path) {
|
|
177
|
+
let keep = false;
|
|
178
|
+
//coerce the path into a normalized form and unix slashes
|
|
179
|
+
path = util_1.default.standardizePath(path).replace(/\\+/g, '/');
|
|
180
|
+
for (let matcher of this.matchers) {
|
|
181
|
+
//exclusion pattern: do not keep the path if it matches
|
|
182
|
+
if (matcher.isExcludePattern) {
|
|
183
|
+
if (matcher.isMatch(path)) {
|
|
184
|
+
keep = false;
|
|
185
|
+
}
|
|
186
|
+
//inclusion pattern: keep the path if it matches
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
keep = keep || matcher.isMatch(path);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return keep;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.PathCollection = PathCollection;
|
|
196
|
+
//# sourceMappingURL=PathFilterer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PathFilterer.js","sourceRoot":"","sources":["../../src/lsp/PathFilterer.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,6BAA6B;AAE7B,wCAA0C;AAC1C,kCAA2B;AAE3B;;;;;GAKG;AACH,MAAa,YAAY;IACrB,YACI,OAEC;;QAOG,uBAAkB,GAAqB,EAAE,CAAC;QAE1C,uBAAkB,GAAqB,EAAE,CAAC;QAP9C,IAAI,CAAC,MAAM,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,mCAAI,IAAA,sBAAY,GAAE,CAAC;IACpD,CAAC;IAQD;;;;;OAKG;IACI,MAAM,CAAa,OAAY,EAAE,OAA6B;;QACjE,kEAAkE;QAClE,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAAE;YACtC,OAAO,OAAO,CAAC;SAClB;QAED,IAAI,OAAO,GAAQ,EAAE,CAAC;QAEtB,mBAA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