@zzzen/pyright-internal 1.2.0-dev.20230312 → 1.2.0-dev.20230319
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/dist/analyzer/backgroundAnalysisProgram.d.ts +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/cacheManager.d.ts +4 -0
- package/dist/analyzer/cacheManager.js +13 -0
- package/dist/analyzer/cacheManager.js.map +1 -1
- package/dist/analyzer/checker.d.ts +2 -1
- package/dist/analyzer/checker.js +70 -26
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +17 -11
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/program.d.ts +1 -1
- package/dist/analyzer/program.js +16 -15
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +0 -1
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/service.d.ts +2 -1
- package/dist/analyzer/service.js +9 -3
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +2 -2
- package/dist/analyzer/sourceFile.js +2 -2
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.d.ts +1 -0
- package/dist/analyzer/sourceFileInfoUtils.js +17 -1
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +48 -54
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +0 -2
- package/dist/analyzer/typeEvaluatorTypes.js +0 -3
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +2 -0
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.js +20 -0
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +27 -0
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +4 -1
- package/dist/analyzer/types.js +3 -1
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +4 -4
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/commands/quickActionCommand.js +2 -2
- package/dist/commands/quickActionCommand.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -0
- package/dist/common/configOptions.js +4 -0
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/console.d.ts +1 -0
- package/dist/common/console.js +19 -1
- package/dist/common/console.js.map +1 -1
- package/dist/common/diagnosticRules.d.ts +2 -1
- package/dist/common/diagnosticRules.js +1 -0
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/common/extensibility.d.ts +2 -2
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/extensions.js +3 -1
- package/dist/common/extensions.js.map +1 -1
- package/dist/languageServerBase.d.ts +21 -46
- package/dist/languageServerBase.js +109 -151
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.d.ts +4 -3
- package/dist/languageService/analyzerServiceExecutor.js +9 -7
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/codeActionProvider.d.ts +2 -2
- package/dist/languageService/codeActionProvider.js +4 -4
- package/dist/languageService/codeActionProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +3 -5
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +1 -1
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +2 -1
- package/dist/languageService/documentSymbolCollector.js +23 -2
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +2 -1
- package/dist/languageService/hoverProvider.js +21 -5
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +3 -2
- package/dist/languageService/referencesProvider.js +4 -4
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +14 -6
- package/dist/localization/localize.js +5 -4
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +7 -6
- package/dist/parser/parser.js +4 -2
- package/dist/parser/parser.js.map +1 -1
- package/dist/server.d.ts +3 -2
- package/dist/server.js +1 -4
- package/dist/server.js.map +1 -1
- package/dist/tests/cacheManager.test.d.ts +1 -0
- package/dist/tests/cacheManager.test.js +69 -0
- package/dist/tests/cacheManager.test.js.map +1 -0
- package/dist/tests/checker.test.js +2 -2
- package/dist/tests/completions.test.js +2 -2
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/fourslash/missingTypeStub.command.trycatchImport.fourslash.d.ts +7 -0
- package/dist/tests/fourslash/missingTypeStub.command.trycatchImport.fourslash.js +45 -0
- package/dist/tests/fourslash/missingTypeStub.command.trycatchImport.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +7 -6
- package/dist/tests/harness/fourslash/testLanguageService.js +14 -13
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +5 -4
- package/dist/tests/harness/fourslash/testState.js +14 -13
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/moveSymbol.misc.test.js +1 -1
- package/dist/tests/moveSymbol.misc.test.js.map +1 -1
- package/dist/tests/service.test.js +4 -4
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/signatureHelp.test.js +2 -2
- package/dist/tests/signatureHelp.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +3 -3
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +2 -2
- package/dist/tests/typeEvaluator3.test.js +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator5.test.js +12 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +2 -2
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +72 -0
- package/dist/workspaceFactory.js +421 -0
- package/dist/workspaceFactory.js.map +1 -0
- package/package.json +4 -4
- package/dist/workspaceMap.d.ts +0 -14
- package/dist/workspaceMap.js +0 -172
- package/dist/workspaceMap.js.map +0 -1
@@ -0,0 +1,421 @@
|
|
1
|
+
"use strict";
|
2
|
+
/*
|
3
|
+
* workspaceFactory.ts
|
4
|
+
*
|
5
|
+
* Workspace management related functionality.
|
6
|
+
*/
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
8
|
+
exports.WorkspaceFactory = exports.createInitStatus = exports.WorkspacePythonPathKind = exports.WellKnownWorkspaceKinds = void 0;
|
9
|
+
const deferred_1 = require("./common/deferred");
|
10
|
+
let WorkspaceFactoryIdCounter = 0;
|
11
|
+
var WellKnownWorkspaceKinds;
|
12
|
+
(function (WellKnownWorkspaceKinds) {
|
13
|
+
WellKnownWorkspaceKinds["Default"] = "default";
|
14
|
+
WellKnownWorkspaceKinds["Regular"] = "regular";
|
15
|
+
WellKnownWorkspaceKinds["Limited"] = "limited";
|
16
|
+
WellKnownWorkspaceKinds["Cloned"] = "cloned";
|
17
|
+
WellKnownWorkspaceKinds["Test"] = "test";
|
18
|
+
})(WellKnownWorkspaceKinds = exports.WellKnownWorkspaceKinds || (exports.WellKnownWorkspaceKinds = {}));
|
19
|
+
var WorkspacePythonPathKind;
|
20
|
+
(function (WorkspacePythonPathKind) {
|
21
|
+
WorkspacePythonPathKind["Immutable"] = "immutable";
|
22
|
+
WorkspacePythonPathKind["Mutable"] = "mutable";
|
23
|
+
})(WorkspacePythonPathKind = exports.WorkspacePythonPathKind || (exports.WorkspacePythonPathKind = {}));
|
24
|
+
function createInitStatus() {
|
25
|
+
// Due to the way we get `python path`, `include/exclude` from settings to initialize workspace,
|
26
|
+
// we need to wait for getSettings to finish before letting IDE features to use workspace (`isInitialized` field).
|
27
|
+
// So most of cases, whenever we create new workspace, we send request to workspace/configuration right way
|
28
|
+
// except one place which is `initialize` LSP call.
|
29
|
+
// In `initialize` method where we create `initial workspace`, we can't do that since LSP spec doesn't allow
|
30
|
+
// LSP server from sending any request to client until `initialized` method is called.
|
31
|
+
// This flag indicates whether we had our initial updateSetting call or not after `initialized` call.
|
32
|
+
let called = false;
|
33
|
+
const deferred = (0, deferred_1.createDeferred)();
|
34
|
+
const self = {
|
35
|
+
promise: deferred.promise,
|
36
|
+
resolve: () => {
|
37
|
+
called = true;
|
38
|
+
deferred.resolve();
|
39
|
+
},
|
40
|
+
markCalled: () => {
|
41
|
+
called = true;
|
42
|
+
},
|
43
|
+
reset: () => {
|
44
|
+
if (!called) {
|
45
|
+
return self;
|
46
|
+
}
|
47
|
+
return createInitStatus();
|
48
|
+
},
|
49
|
+
resolved: () => {
|
50
|
+
return deferred.resolved;
|
51
|
+
},
|
52
|
+
};
|
53
|
+
return self;
|
54
|
+
}
|
55
|
+
exports.createInitStatus = createInitStatus;
|
56
|
+
class WorkspaceFactory {
|
57
|
+
constructor(_console, _uriParser, _createService, _isPythonPathImmutable, _onWorkspaceCreated) {
|
58
|
+
this._console = _console;
|
59
|
+
this._uriParser = _uriParser;
|
60
|
+
this._createService = _createService;
|
61
|
+
this._isPythonPathImmutable = _isPythonPathImmutable;
|
62
|
+
this._onWorkspaceCreated = _onWorkspaceCreated;
|
63
|
+
this._defaultWorkspacePath = '<default>';
|
64
|
+
this._map = new Map();
|
65
|
+
this._id = WorkspaceFactoryIdCounter++;
|
66
|
+
this._console.log(`WorkspaceFactory ${this._id} created`);
|
67
|
+
}
|
68
|
+
handleInitialize(params) {
|
69
|
+
// Create a service instance for each of the workspace folders.
|
70
|
+
if (params.workspaceFolders) {
|
71
|
+
params.workspaceFolders.forEach((folder) => {
|
72
|
+
const path = this._uriParser.decodeTextDocumentUri(folder.uri);
|
73
|
+
this._add(folder.uri, path, folder.name, undefined, WorkspacePythonPathKind.Mutable, [
|
74
|
+
WellKnownWorkspaceKinds.Regular,
|
75
|
+
]);
|
76
|
+
});
|
77
|
+
}
|
78
|
+
else if (params.rootPath) {
|
79
|
+
this._add(params.rootPath, params.rootPath, params.rootPath, undefined, WorkspacePythonPathKind.Mutable, [
|
80
|
+
WellKnownWorkspaceKinds.Regular,
|
81
|
+
]);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
handleWorkspaceFoldersChanged(params) {
|
85
|
+
params.removed.forEach((workspaceInfo) => {
|
86
|
+
const rootPath = this._uriParser.decodeTextDocumentUri(workspaceInfo.uri);
|
87
|
+
// Delete all workspaces for this folder. Even the ones generated for notebook kernels.
|
88
|
+
const workspaces = this.getNonDefaultWorkspaces().filter((w) => w.rootPath === rootPath);
|
89
|
+
workspaces.forEach((w) => {
|
90
|
+
this._remove(w);
|
91
|
+
});
|
92
|
+
});
|
93
|
+
params.added.forEach((workspaceInfo) => {
|
94
|
+
const rootPath = this._uriParser.decodeTextDocumentUri(workspaceInfo.uri);
|
95
|
+
this._add(workspaceInfo.uri, rootPath, workspaceInfo.name, undefined, WorkspacePythonPathKind.Mutable, [
|
96
|
+
WellKnownWorkspaceKinds.Regular,
|
97
|
+
]);
|
98
|
+
});
|
99
|
+
}
|
100
|
+
items() {
|
101
|
+
return [...this._map.values()];
|
102
|
+
}
|
103
|
+
applyPythonPath(workspace, newPythonPath) {
|
104
|
+
// See if were allowed to apply the new python path
|
105
|
+
if (workspace.pythonPathKind === WorkspacePythonPathKind.Mutable && newPythonPath) {
|
106
|
+
const originalPythonPath = workspace.pythonPath;
|
107
|
+
workspace.pythonPath = newPythonPath;
|
108
|
+
// This may not be the workspace in our map. Update the workspace in the map too.
|
109
|
+
// This can happen during startup were the Initialize creates a workspace and then
|
110
|
+
// onDidChangeConfiguration is called right away.
|
111
|
+
const key = this._getWorkspaceKey(workspace);
|
112
|
+
const workspaceInMap = this._map.get(key);
|
113
|
+
if (workspaceInMap) {
|
114
|
+
workspaceInMap.pythonPath = newPythonPath;
|
115
|
+
}
|
116
|
+
// If the python path has changed, we may need to move the immutable files to the correct workspace.
|
117
|
+
if (originalPythonPath && originalPythonPath !== newPythonPath && workspaceInMap) {
|
118
|
+
// Potentially move immutable files from one workspace to another.
|
119
|
+
this._moveImmutableFilesToCorrectWorkspace(originalPythonPath, workspaceInMap);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
// Return the python path that should be used (whether hardcoded or configured)
|
123
|
+
return workspace.pythonPath;
|
124
|
+
}
|
125
|
+
clear() {
|
126
|
+
this._map.forEach((workspace) => {
|
127
|
+
workspace.isInitialized.resolve();
|
128
|
+
workspace.service.dispose();
|
129
|
+
});
|
130
|
+
this._map.clear();
|
131
|
+
this._console.log(`WorkspaceFactory ${this._id} clear`);
|
132
|
+
}
|
133
|
+
hasMultipleWorkspaces(kind) {
|
134
|
+
if (this._map.size === 0 || this._map.size === 1) {
|
135
|
+
return false;
|
136
|
+
}
|
137
|
+
let count = 0;
|
138
|
+
for (const kv of this._map) {
|
139
|
+
if (!kind || kv[1].kinds.some((k) => k === kind)) {
|
140
|
+
count++;
|
141
|
+
}
|
142
|
+
if (count > 1) {
|
143
|
+
return true;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
return false;
|
147
|
+
}
|
148
|
+
getContainingWorkspace(filePath, pythonPath) {
|
149
|
+
return this._getBestRegularWorkspace(this.getNonDefaultWorkspaces(WellKnownWorkspaceKinds.Regular).filter((w) => filePath.startsWith(w.rootPath)), pythonPath);
|
150
|
+
}
|
151
|
+
moveFiles(filePaths, fromWorkspace, toWorkspace) {
|
152
|
+
if (fromWorkspace === toWorkspace) {
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
try {
|
156
|
+
filePaths.forEach((f) => {
|
157
|
+
var _a;
|
158
|
+
const fileInfo = fromWorkspace.service.backgroundAnalysisProgram.program.getSourceFileInfo(f);
|
159
|
+
if (fileInfo) {
|
160
|
+
// Copy the source file data (closing can destroy the sourceFile)
|
161
|
+
const version = fileInfo.sourceFile.getClientVersion() || null;
|
162
|
+
const content = fileInfo.sourceFile.getFileContent() || '';
|
163
|
+
const ipythonMode = fileInfo.sourceFile.getIPythonMode();
|
164
|
+
const chainedSourceFile = (_a = fileInfo.chainedSourceFile) === null || _a === void 0 ? void 0 : _a.sourceFile.getFilePath();
|
165
|
+
const realFilePath = fileInfo.sourceFile.getRealFilePath();
|
166
|
+
// Remove the file from the old workspace first (closing will propagate to the toWorkspace automatically).
|
167
|
+
fromWorkspace.service.setFileClosed(f, /*isTracked*/ false);
|
168
|
+
// Then open it in the toWorkspace so that it is marked tracked there.
|
169
|
+
toWorkspace.service.setFileOpened(f, version, content, ipythonMode, chainedSourceFile, realFilePath);
|
170
|
+
}
|
171
|
+
});
|
172
|
+
// If the fromWorkspace has no more files in it (and it's an immutable pythonPath), then remove it.
|
173
|
+
this.removeUnused(fromWorkspace);
|
174
|
+
}
|
175
|
+
catch (e) {
|
176
|
+
this._console.error(e.toString());
|
177
|
+
}
|
178
|
+
}
|
179
|
+
getNonDefaultWorkspaces(kind) {
|
180
|
+
const workspaces = [];
|
181
|
+
this._map.forEach((workspace) => {
|
182
|
+
if (!workspace.rootPath) {
|
183
|
+
return;
|
184
|
+
}
|
185
|
+
if (kind && !workspace.kinds.some((k) => k === kind)) {
|
186
|
+
return;
|
187
|
+
}
|
188
|
+
workspaces.push(workspace);
|
189
|
+
});
|
190
|
+
return workspaces;
|
191
|
+
}
|
192
|
+
// Returns the best workspace for a file. Waits for the workspace to be finished handling other events before
|
193
|
+
// returning the appropriate workspace.
|
194
|
+
async getWorkspaceForFile(filePath, pythonPath) {
|
195
|
+
// Wait for all workspaces to be initialized before attempting to find the best workspace. Otherwise
|
196
|
+
// the list of files won't be complete and the `contains` check might fail.
|
197
|
+
await Promise.all(this.items().map((w) => w.isInitialized.promise));
|
198
|
+
// Find or create best match.
|
199
|
+
const workspace = await this._getOrCreateBestWorkspaceForFile(filePath, pythonPath);
|
200
|
+
// The workspace may have just been created. Wait for it to be initialized before returning it.
|
201
|
+
await workspace.isInitialized.promise;
|
202
|
+
return workspace;
|
203
|
+
}
|
204
|
+
async getContainingWorkspacesForFile(filePath) {
|
205
|
+
// Wait for all workspaces to be initialized before attempting to find the best workspace. Otherwise
|
206
|
+
// the list of files won't be complete and the `contains` check might fail.
|
207
|
+
await Promise.all(this.items().map((w) => w.isInitialized.promise));
|
208
|
+
// All workspaces that track the file should be considered.
|
209
|
+
let workspaces = this.items().filter((w) => w.service.isTracked(filePath));
|
210
|
+
// If that list is empty, get the best workspace
|
211
|
+
if (workspaces.length === 0) {
|
212
|
+
workspaces.push(this._getOrCreateBestWorkspaceFileSync(filePath, undefined));
|
213
|
+
}
|
214
|
+
// If the file is immutable, then only return that workspace.
|
215
|
+
if (this._isPythonPathImmutable(filePath)) {
|
216
|
+
workspaces = workspaces.filter((w) => w.pythonPathKind === WorkspacePythonPathKind.Immutable);
|
217
|
+
}
|
218
|
+
// The workspaces may have just been created, wait for them all to be initialized
|
219
|
+
await Promise.all(workspaces.map((w) => w.isInitialized.promise));
|
220
|
+
return workspaces;
|
221
|
+
}
|
222
|
+
removeUnused(workspace) {
|
223
|
+
// Only remove this workspace is it's not being used for immutable files and it's an immutable path kind.
|
224
|
+
if (workspace.service.getOpenFiles().filter((f) => this._isPythonPathImmutable(f)).length === 0 &&
|
225
|
+
workspace.pythonPathKind === WorkspacePythonPathKind.Immutable) {
|
226
|
+
// Destroy the workspace since it only had immutable files in it.
|
227
|
+
this._remove(workspace);
|
228
|
+
}
|
229
|
+
}
|
230
|
+
async _moveImmutableFilesToCorrectWorkspace(oldPythonPath, mutableWorkspace) {
|
231
|
+
// If the python path changes we may need to move some immutable files around.
|
232
|
+
// For example, if a notebook had the old python path, we need to create a new workspace
|
233
|
+
// for the notebook.
|
234
|
+
// If a notebook has the new python path but is currently in a workspace with the path hardcoded, we need to move it to
|
235
|
+
// this workspace.
|
236
|
+
const oldPathFiles = [
|
237
|
+
...new Set(mutableWorkspace.service.getOpenFiles().filter((f) => this._isPythonPathImmutable(f))),
|
238
|
+
];
|
239
|
+
const exitingWorkspaceWithSamePath = this.items().find((w) => w.pythonPath === mutableWorkspace.pythonPath && w !== mutableWorkspace);
|
240
|
+
const newPathFiles = new Set(exitingWorkspaceWithSamePath === null || exitingWorkspaceWithSamePath === void 0 ? void 0 : exitingWorkspaceWithSamePath.service.getOpenFiles().filter((f) => this._isPythonPathImmutable(f)));
|
241
|
+
// Immutable files that were in this mutableWorkspace have to be moved
|
242
|
+
// to a (potentially) new workspace (with the old path).
|
243
|
+
if (oldPathFiles.length > 0) {
|
244
|
+
// Given that all of these files were in the same workspace, there should be only
|
245
|
+
// one immutable workspace for all of them. So we can just use the first file.
|
246
|
+
const workspace = this._getOrCreateBestWorkspaceFileSync(oldPathFiles[0], oldPythonPath);
|
247
|
+
if (workspace !== mutableWorkspace) {
|
248
|
+
this.moveFiles(oldPathFiles, mutableWorkspace, workspace);
|
249
|
+
}
|
250
|
+
}
|
251
|
+
// Immutable files from a different workspace (with the same path as the new path)
|
252
|
+
// have to be moved to the mutable workspace (which now has the new path)
|
253
|
+
if (exitingWorkspaceWithSamePath) {
|
254
|
+
this.moveFiles([...newPathFiles], exitingWorkspaceWithSamePath, mutableWorkspace);
|
255
|
+
this.removeUnused(exitingWorkspaceWithSamePath);
|
256
|
+
}
|
257
|
+
}
|
258
|
+
_add(rootUri, rootPath, name, pythonPath, pythonPathKind, kinds) {
|
259
|
+
// Update the kind based of the uri is local or not
|
260
|
+
if (!this._uriParser.isLocal(rootUri)) {
|
261
|
+
// Web based workspace should be limited.
|
262
|
+
kinds = [...kinds, WellKnownWorkspaceKinds.Limited];
|
263
|
+
}
|
264
|
+
const result = {
|
265
|
+
workspaceName: name,
|
266
|
+
rootPath,
|
267
|
+
uri: rootUri,
|
268
|
+
kinds,
|
269
|
+
pythonPath,
|
270
|
+
pythonPathKind,
|
271
|
+
service: this._createService(name, rootPath, rootUri, kinds),
|
272
|
+
disableLanguageServices: false,
|
273
|
+
disableOrganizeImports: false,
|
274
|
+
disableWorkspaceSymbol: false,
|
275
|
+
isInitialized: createInitStatus(),
|
276
|
+
searchPathsToWatch: [],
|
277
|
+
};
|
278
|
+
// Tell our owner we added something
|
279
|
+
this._onWorkspaceCreated(result);
|
280
|
+
// Stick in our map
|
281
|
+
const key = this._getWorkspaceKey(result);
|
282
|
+
// Make sure to delete existing workspaces if there are any.
|
283
|
+
this._remove(result);
|
284
|
+
this._console.log(`WorkspaceFactory ${this._id} add ${key}`);
|
285
|
+
this._map.set(key, result);
|
286
|
+
return result;
|
287
|
+
}
|
288
|
+
_remove(value) {
|
289
|
+
const key = this._getWorkspaceKey(value);
|
290
|
+
const workspace = this._map.get(key);
|
291
|
+
if (workspace) {
|
292
|
+
workspace.isInitialized.resolve();
|
293
|
+
workspace.service.dispose();
|
294
|
+
this._console.log(`WorkspaceFactory ${this._id} remove ${key}`);
|
295
|
+
this._map.delete(key);
|
296
|
+
}
|
297
|
+
}
|
298
|
+
_getDefaultWorskpaceKey(pythonPath) {
|
299
|
+
return `${this._defaultWorkspacePath}:${pythonPath ? pythonPath : WorkspacePythonPathKind.Mutable}`;
|
300
|
+
}
|
301
|
+
_getWorkspaceKey(value) {
|
302
|
+
// Special the root path for the default workspace. It will be created
|
303
|
+
// without a root path
|
304
|
+
const rootPath = value.kinds.includes(WellKnownWorkspaceKinds.Default)
|
305
|
+
? this._defaultWorkspacePath
|
306
|
+
: value.rootPath;
|
307
|
+
// Key is defined by the rootPath and the pythonPath. We might include platform in this, but for now
|
308
|
+
// platform is only used by the import resolver.
|
309
|
+
return `${rootPath}:${value.pythonPathKind === WorkspacePythonPathKind.Mutable ? value.pythonPathKind : value.pythonPath}`;
|
310
|
+
}
|
311
|
+
async _getOrCreateBestWorkspaceForFile(filePath, pythonPath) {
|
312
|
+
// Find the current best workspace (without creating a new one)
|
313
|
+
let bestInstance = this._getBestWorkspaceForFile(filePath, pythonPath);
|
314
|
+
// Make sure the best instance is initialized so that it has its pythonPath.
|
315
|
+
await bestInstance.isInitialized.promise;
|
316
|
+
// If this best instance doesn't match the pythonPath, then we need to create a new one.
|
317
|
+
if (pythonPath && bestInstance.pythonPath !== pythonPath) {
|
318
|
+
bestInstance = this._createImmutableCopy(bestInstance, pythonPath);
|
319
|
+
}
|
320
|
+
return bestInstance;
|
321
|
+
}
|
322
|
+
_getOrCreateBestWorkspaceFileSync(filePath, pythonPath) {
|
323
|
+
// Find the current best workspace (without creating a new one)
|
324
|
+
let bestInstance = this._getBestWorkspaceForFile(filePath, pythonPath);
|
325
|
+
// If this best instance doesn't match the pythonPath, then we need to create a new one.
|
326
|
+
if (pythonPath && bestInstance.pythonPath !== pythonPath) {
|
327
|
+
bestInstance = this._createImmutableCopy(bestInstance, pythonPath);
|
328
|
+
}
|
329
|
+
return bestInstance;
|
330
|
+
}
|
331
|
+
_createImmutableCopy(workspace, pythonPath) {
|
332
|
+
var _a;
|
333
|
+
const result = this._add(workspace.uri, workspace.rootPath, workspace.workspaceName, pythonPath, WorkspacePythonPathKind.Immutable, workspace.kinds);
|
334
|
+
// All mutable open files in the first workspace should be opened in the new workspace.
|
335
|
+
// Immutable files should stay where they are since they're tied to a specific workspace.
|
336
|
+
const files = workspace.service.getOpenFiles().filter((f) => !this._isPythonPathImmutable(f));
|
337
|
+
for (const file of files) {
|
338
|
+
const sourceFileInfo = workspace.service.backgroundAnalysisProgram.program.getSourceFileInfo(file);
|
339
|
+
if (sourceFileInfo) {
|
340
|
+
const sourceFile = sourceFileInfo.sourceFile;
|
341
|
+
const fileContents = sourceFile.getFileContent();
|
342
|
+
result.service.setFileOpened(file, sourceFile.getClientVersion() || null, fileContents || '', sourceFile.getIPythonMode(), (_a = sourceFileInfo.chainedSourceFile) === null || _a === void 0 ? void 0 : _a.sourceFile.getFilePath(), sourceFile.getRealFilePath());
|
343
|
+
}
|
344
|
+
}
|
345
|
+
return result;
|
346
|
+
}
|
347
|
+
_getBestWorkspaceForFile(filePath, pythonPath) {
|
348
|
+
let bestInstance;
|
349
|
+
// The order of how we find the best matching workspace for the given file is
|
350
|
+
// 1. The given file is the workspace itself (ex, a file being a virtual workspace itself).
|
351
|
+
// 2. The given file matches the fileSpec of the service under the workspace
|
352
|
+
// (the file is a user file the workspace provides LSP service for).
|
353
|
+
// 3. The given file doesn't match anything but we have only 1 regular workspace
|
354
|
+
// (ex, open a library file from the workspace).
|
355
|
+
// 4. The given file doesn't match anything and there are multiple workspaces but one of workspaces
|
356
|
+
// contains the file (ex, open a library file already imported by a workspace).
|
357
|
+
// 5. If none of the above works, then it matches the default workspace.
|
358
|
+
// First find the workspaces that are tracking the file
|
359
|
+
const regularWorkspaces = this.getNonDefaultWorkspaces(WellKnownWorkspaceKinds.Regular);
|
360
|
+
const trackingWorkspaces = this.items().filter((w) => w.service.isTracked(filePath));
|
361
|
+
// Then find the best in all of those that actually matches the pythonPath.
|
362
|
+
bestInstance = this._getBestRegularWorkspace(trackingWorkspaces, pythonPath);
|
363
|
+
// If it's not in a tracked workspace, see if we only have regular workspaces with the same
|
364
|
+
// length root path
|
365
|
+
if (bestInstance === undefined &&
|
366
|
+
regularWorkspaces.every((w) => w.rootPath.length === regularWorkspaces[0].rootPath.length)) {
|
367
|
+
bestInstance = this._getBestRegularWorkspace(regularWorkspaces, pythonPath);
|
368
|
+
}
|
369
|
+
// If the regular workspaces don't all have the same length, then try the workspaces that already have the file open or scanned.
|
370
|
+
if (bestInstance === undefined) {
|
371
|
+
bestInstance = this._getBestRegularWorkspace(regularWorkspaces.filter((w) => w.service.hasSourceFile(filePath)), pythonPath);
|
372
|
+
}
|
373
|
+
// If that still didn't work, that must mean we don't have a workspace. Create a default one.
|
374
|
+
if (bestInstance === undefined) {
|
375
|
+
bestInstance = this._getOrCreateDefaultWorkspace(pythonPath);
|
376
|
+
}
|
377
|
+
return bestInstance;
|
378
|
+
}
|
379
|
+
_getOrCreateDefaultWorkspace(pythonPath) {
|
380
|
+
// Default key depends upon the pythonPath
|
381
|
+
let defaultWorkspace = this._map.get(this._getDefaultWorskpaceKey(pythonPath));
|
382
|
+
if (!defaultWorkspace) {
|
383
|
+
// Create a default workspace for files that are outside
|
384
|
+
// of all workspaces.
|
385
|
+
defaultWorkspace = this._add('', '', this._defaultWorkspacePath, pythonPath, pythonPath ? WorkspacePythonPathKind.Immutable : WorkspacePythonPathKind.Mutable, [WellKnownWorkspaceKinds.Default]);
|
386
|
+
}
|
387
|
+
return defaultWorkspace;
|
388
|
+
}
|
389
|
+
_getLongestPathWorkspace(workspaces) {
|
390
|
+
const longestPath = workspaces.reduce((previousPath, currentWorkspace) => {
|
391
|
+
if (!previousPath) {
|
392
|
+
return currentWorkspace.rootPath;
|
393
|
+
}
|
394
|
+
if (currentWorkspace.rootPath.length > previousPath.length) {
|
395
|
+
return currentWorkspace.rootPath;
|
396
|
+
}
|
397
|
+
return previousPath;
|
398
|
+
}, '');
|
399
|
+
return workspaces.find((w) => w.rootPath === longestPath);
|
400
|
+
}
|
401
|
+
_getBestRegularWorkspace(workspaces, pythonPath) {
|
402
|
+
if (workspaces.length === 0) {
|
403
|
+
return undefined;
|
404
|
+
}
|
405
|
+
// If there's only one, then it's the best.
|
406
|
+
if (workspaces.length === 1) {
|
407
|
+
return workspaces[0];
|
408
|
+
}
|
409
|
+
// If there's any that match the python path, take the one with the longest path from those.
|
410
|
+
if (pythonPath) {
|
411
|
+
const matchingWorkspaces = workspaces.filter((w) => w.pythonPath === pythonPath);
|
412
|
+
if (matchingWorkspaces.length > 0) {
|
413
|
+
return this._getLongestPathWorkspace(matchingWorkspaces);
|
414
|
+
}
|
415
|
+
}
|
416
|
+
// Otherwise, just take the longest path.
|
417
|
+
return this._getLongestPathWorkspace(workspaces);
|
418
|
+
}
|
419
|
+
}
|
420
|
+
exports.WorkspaceFactory = WorkspaceFactory;
|
421
|
+
//# sourceMappingURL=workspaceFactory.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"workspaceFactory.js","sourceRoot":"","sources":["../../src/workspaceFactory.ts"],"names":[],"mappings":";A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C,EAAE;YACzB,OAAO,SAAS,CAAC;SACpB;QAED,2CAA2C;QAC3C,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;SACxB;QAED,4FAA4F;QAC5F,IAAI,UAAU,EAAE;YACZ,MAAM,kBAAkB,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;YACjF,IAAI,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC/B,OAAO,IAAI,CAAC,wBAAwB,CAAC,kBAAkB,CAAC,CAAC;aAC5D;SACJ;QAED,yCAAyC;QACzC,OAAO,IAAI,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAC;IACrD,CAAC;CACJ;AA/eD,4CA+eC"}
|
package/package.json
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
"name": "@zzzen/pyright-internal",
|
3
3
|
"displayName": "pyright",
|
4
4
|
"description": "Type checker for the Python language",
|
5
|
-
"version": "1.2.0-dev.
|
5
|
+
"version": "1.2.0-dev.20230319",
|
6
6
|
"license": "MIT",
|
7
7
|
"private": false,
|
8
8
|
"files": [
|
@@ -26,10 +26,10 @@
|
|
26
26
|
"source-map-support": "^0.5.21",
|
27
27
|
"tmp": "^0.2.1",
|
28
28
|
"typescript-char": "^0.0.0",
|
29
|
-
"vscode-jsonrpc": "8.1.0
|
30
|
-
"vscode-languageserver": "8.1.0
|
29
|
+
"vscode-jsonrpc": "8.1.0",
|
30
|
+
"vscode-languageserver": "8.1.0",
|
31
31
|
"vscode-languageserver-textdocument": "^1.0.9",
|
32
|
-
"vscode-languageserver-types": "3.17.
|
32
|
+
"vscode-languageserver-types": "3.17.3",
|
33
33
|
"vscode-uri": "^3.0.7"
|
34
34
|
},
|
35
35
|
"devDependencies": {
|
package/dist/workspaceMap.d.ts
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
import { LanguageServerBase, WorkspaceServiceInstance } from './languageServerBase';
|
2
|
-
export declare class WorkspaceMap extends Map<string, WorkspaceServiceInstance> {
|
3
|
-
private _defaultWorkspacePath;
|
4
|
-
set(key: string, value: WorkspaceServiceInstance): this;
|
5
|
-
delete(key: string): boolean;
|
6
|
-
hasMultipleWorkspaces(kind?: string): boolean;
|
7
|
-
getNonDefaultWorkspaces(kind?: string): WorkspaceServiceInstance[];
|
8
|
-
getWorkspaceForFile(ls: LanguageServerBase, filePath: string): Promise<WorkspaceServiceInstance>;
|
9
|
-
getContainingWorkspace(filePath: string): WorkspaceServiceInstance | undefined;
|
10
|
-
getDefaultWorkspace(): WorkspaceServiceInstance | undefined;
|
11
|
-
private _getBestWorkspaceForFile;
|
12
|
-
private _createDefaultWorkspace;
|
13
|
-
private _getBestWorkspace;
|
14
|
-
}
|
package/dist/workspaceMap.js
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
/*
|
3
|
-
* workspaceMap.ts
|
4
|
-
*
|
5
|
-
* Workspace management related functionality.
|
6
|
-
*/
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
8
|
-
exports.WorkspaceMap = void 0;
|
9
|
-
const languageServerBase_1 = require("./languageServerBase");
|
10
|
-
class WorkspaceMap extends Map {
|
11
|
-
constructor() {
|
12
|
-
super(...arguments);
|
13
|
-
this._defaultWorkspacePath = '<default>';
|
14
|
-
}
|
15
|
-
set(key, value) {
|
16
|
-
// Make sure to delete existing workspace if there is one.
|
17
|
-
this.delete(key);
|
18
|
-
return super.set(key, value);
|
19
|
-
}
|
20
|
-
delete(key) {
|
21
|
-
const workspace = this.get(key);
|
22
|
-
if (!workspace) {
|
23
|
-
return false;
|
24
|
-
}
|
25
|
-
// Make sure to unblock if there is someone waiting this workspace.
|
26
|
-
workspace.isInitialized.resolve();
|
27
|
-
// Properly dispose of the service instance.
|
28
|
-
workspace.serviceInstance.dispose();
|
29
|
-
return super.delete(key);
|
30
|
-
}
|
31
|
-
hasMultipleWorkspaces(kind) {
|
32
|
-
if (this.size === 0 || this.size === 1) {
|
33
|
-
return false;
|
34
|
-
}
|
35
|
-
let count = 0;
|
36
|
-
for (const kv of this) {
|
37
|
-
if (!kind || kv[1].kinds.some((k) => k === kind)) {
|
38
|
-
count++;
|
39
|
-
}
|
40
|
-
if (count > 1) {
|
41
|
-
return true;
|
42
|
-
}
|
43
|
-
}
|
44
|
-
return false;
|
45
|
-
}
|
46
|
-
getNonDefaultWorkspaces(kind) {
|
47
|
-
const workspaces = [];
|
48
|
-
this.forEach((workspace) => {
|
49
|
-
if (!workspace.path) {
|
50
|
-
return;
|
51
|
-
}
|
52
|
-
if (kind && !workspace.kinds.some((k) => k === kind)) {
|
53
|
-
return;
|
54
|
-
}
|
55
|
-
workspaces.push(workspace);
|
56
|
-
});
|
57
|
-
return workspaces;
|
58
|
-
}
|
59
|
-
// Returns the best workspace for a file. Waits for the workspace to be finished handling other events before
|
60
|
-
// returning the appropriate workspace.
|
61
|
-
async getWorkspaceForFile(ls, filePath) {
|
62
|
-
// Make sure we always have a default workspace.
|
63
|
-
const defaultWorkspace = this._createDefaultWorkspace(ls);
|
64
|
-
// Wait for all workspaces to be initialized before attempting to find the best workspace. Otherwise
|
65
|
-
// the list of files won't be complete and the `contains` check might fail.
|
66
|
-
await Promise.all([...this.values()].map((w) => w.isInitialized.promise));
|
67
|
-
// Find best match.
|
68
|
-
const workspace = this._getBestWorkspaceForFile(ls, filePath, defaultWorkspace);
|
69
|
-
// During the previous await we might have reset to being uninitialized again, wait before returning
|
70
|
-
await workspace.isInitialized.promise;
|
71
|
-
return workspace;
|
72
|
-
}
|
73
|
-
getContainingWorkspace(filePath) {
|
74
|
-
return this._getBestWorkspace(this.getNonDefaultWorkspaces(languageServerBase_1.WellKnownWorkspaceKinds.Regular).filter((w) => filePath.startsWith(w.path)));
|
75
|
-
}
|
76
|
-
getDefaultWorkspace() {
|
77
|
-
return this.get(this._defaultWorkspacePath);
|
78
|
-
}
|
79
|
-
_getBestWorkspaceForFile(ls, filePath, defaultWorkspace) {
|
80
|
-
let bestRootPath;
|
81
|
-
let bestInstance;
|
82
|
-
// The order of how we find the best matching workspace for the given file is
|
83
|
-
// 1. The given file is the workspace itself (ex, a file being a virtual workspace itself).
|
84
|
-
// 2. The given file matches the fileSpec of the service under the workspace
|
85
|
-
// (the file is a user file the workspace provides LSP service for).
|
86
|
-
// 3. The given file doesn't match anything but we have only 1 regular workspace
|
87
|
-
// (ex, open a library file from the workspace).
|
88
|
-
// 4. The given file doesn't match anything and there are multiple workspaces but one of workspaces
|
89
|
-
// contains the file (ex, open a library file already imported by a workspace).
|
90
|
-
// 5. If none of the above works, then it matches the default workspace.
|
91
|
-
this.forEach((workspace) => {
|
92
|
-
if (workspace.path) {
|
93
|
-
if (workspace.path !== filePath && !workspace.serviceInstance.isTracked(filePath)) {
|
94
|
-
return;
|
95
|
-
}
|
96
|
-
// Among workspaces that own the file, make sure we return the inner most one which
|
97
|
-
// we consider as the best workspace.
|
98
|
-
if (bestRootPath === undefined || workspace.path.startsWith(bestRootPath)) {
|
99
|
-
bestRootPath = workspace.path;
|
100
|
-
bestInstance = workspace;
|
101
|
-
}
|
102
|
-
}
|
103
|
-
});
|
104
|
-
// If there were multiple workspaces or we couldn't find any,
|
105
|
-
// use the default one.
|
106
|
-
if (bestInstance === undefined) {
|
107
|
-
const regularWorkspaces = this.getNonDefaultWorkspaces(languageServerBase_1.WellKnownWorkspaceKinds.Regular);
|
108
|
-
// If we have only 1 regular workspace, then use that.
|
109
|
-
if (regularWorkspaces.length === 1) {
|
110
|
-
bestInstance = regularWorkspaces[0];
|
111
|
-
}
|
112
|
-
else {
|
113
|
-
// If we have multiple workspaces, see whether we can at least find one that contains the file.
|
114
|
-
// the file might not be tracked (user file), but still belongs to a workspace as a library file or as an orphan file to the workspace.
|
115
|
-
const containingWorkspace = this._getBestWorkspace(regularWorkspaces.filter((w) => w.serviceInstance.contains(filePath)));
|
116
|
-
if (containingWorkspace) {
|
117
|
-
bestInstance = containingWorkspace;
|
118
|
-
}
|
119
|
-
else {
|
120
|
-
// If no workspace contains it, then it belongs to the default workspace.
|
121
|
-
bestInstance = defaultWorkspace;
|
122
|
-
}
|
123
|
-
}
|
124
|
-
}
|
125
|
-
return bestInstance;
|
126
|
-
}
|
127
|
-
_createDefaultWorkspace(ls) {
|
128
|
-
let defaultWorkspace = this.get(this._defaultWorkspacePath);
|
129
|
-
if (!defaultWorkspace) {
|
130
|
-
// Create a default workspace for files that are outside
|
131
|
-
// of all workspaces.
|
132
|
-
defaultWorkspace = {
|
133
|
-
workspaceName: '',
|
134
|
-
rootPath: '',
|
135
|
-
path: '',
|
136
|
-
uri: '',
|
137
|
-
serviceInstance: ls.createAnalyzerService(this._defaultWorkspacePath),
|
138
|
-
kinds: [languageServerBase_1.WellKnownWorkspaceKinds.Default],
|
139
|
-
disableLanguageServices: false,
|
140
|
-
disableOrganizeImports: false,
|
141
|
-
disableWorkspaceSymbol: false,
|
142
|
-
isInitialized: (0, languageServerBase_1.createInitStatus)(),
|
143
|
-
searchPathsToWatch: [],
|
144
|
-
};
|
145
|
-
this.set(this._defaultWorkspacePath, defaultWorkspace);
|
146
|
-
// Do not await this. let isInitialized.promise to await. Otherwise, ordering
|
147
|
-
// will get messed up. The very first call will run last.
|
148
|
-
ls.updateSettingsForWorkspace(defaultWorkspace, defaultWorkspace.isInitialized).ignoreErrors();
|
149
|
-
}
|
150
|
-
return defaultWorkspace;
|
151
|
-
}
|
152
|
-
_getBestWorkspace(workspaces) {
|
153
|
-
if (workspaces.length === 0) {
|
154
|
-
return undefined;
|
155
|
-
}
|
156
|
-
if (workspaces.length === 1) {
|
157
|
-
return workspaces[0];
|
158
|
-
}
|
159
|
-
// Best workspace is the inner most workspace.
|
160
|
-
return workspaces.reduce((previousWorkspace, currentWorkspace) => {
|
161
|
-
if (!previousWorkspace) {
|
162
|
-
return currentWorkspace;
|
163
|
-
}
|
164
|
-
if (currentWorkspace.path.startsWith(previousWorkspace.path)) {
|
165
|
-
return currentWorkspace;
|
166
|
-
}
|
167
|
-
return previousWorkspace;
|
168
|
-
}, workspaces[0]);
|
169
|
-
}
|
170
|
-
}
|
171
|
-
exports.WorkspaceMap = WorkspaceMap;
|
172
|
-
//# sourceMappingURL=workspaceMap.js.map
|