@zzzen/pyright-internal 1.2.0-dev.20230423 → 1.2.0-dev.20230507
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/analyzerFileInfo.d.ts +4 -1
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +7 -4
- package/dist/analyzer/backgroundAnalysisProgram.js +22 -7
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.js +12 -7
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -0
- package/dist/analyzer/checker.js +58 -7
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +6 -0
- package/dist/analyzer/constructors.js +456 -0
- package/dist/analyzer/constructors.js.map +1 -0
- package/dist/analyzer/dataClasses.js +89 -2
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.d.ts +6 -1
- package/dist/analyzer/declarationUtils.js +10 -8
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/enums.js +54 -8
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +15 -15
- package/dist/analyzer/importResolver.js +477 -477
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.d.ts +2 -2
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.d.ts +1 -1
- package/dist/analyzer/namedTuples.js +30 -42
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.d.ts +16 -0
- package/dist/analyzer/operations.js +749 -0
- package/dist/analyzer/operations.js.map +1 -0
- package/dist/analyzer/packageTypeReport.d.ts +2 -1
- package/dist/analyzer/packageTypeReport.js +2 -1
- package/dist/analyzer/packageTypeReport.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.d.ts +1 -1
- package/dist/analyzer/packageTypeVerifier.js +27 -13
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +4 -2
- package/dist/analyzer/parseTreeUtils.js +32 -1
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +16 -0
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +29 -53
- package/dist/analyzer/program.js +1050 -1649
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/protocols.js +1 -1
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.d.ts +14 -35
- package/dist/analyzer/service.js +92 -121
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +14 -49
- package/dist/analyzer/sourceFile.js +271 -291
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.d.ts +2 -2
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +417 -1570
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +44 -9
- package/dist/analyzer/typeEvaluatorTypes.js +33 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +5 -9
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +3 -0
- package/dist/analyzer/typeUtils.js +66 -9
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +5 -5
- package/dist/analyzer/typeVarContext.js +7 -0
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typedDicts.js +2 -2
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +4 -2
- package/dist/analyzer/types.js +7 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +10 -11
- package/dist/backgroundAnalysisBase.js +87 -87
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +8 -8
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/commands/quickActionCommand.js +4 -1
- package/dist/commands/quickActionCommand.js.map +1 -1
- package/dist/common/cancellationUtils.d.ts +1 -1
- package/dist/common/cancellationUtils.js +9 -9
- package/dist/common/cancellationUtils.js.map +1 -1
- package/dist/common/commandLineOptions.d.ts +1 -2
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -2
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/console.d.ts +5 -9
- package/dist/common/console.js +46 -33
- package/dist/common/console.js.map +1 -1
- package/dist/common/deferred.js +10 -10
- package/dist/common/deferred.js.map +1 -1
- package/dist/common/extensibility.d.ts +27 -5
- package/dist/common/extensibility.js +1 -1
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileBasedCancellationUtils.js +5 -5
- package/dist/common/fileBasedCancellationUtils.js.map +1 -1
- package/dist/common/fileSystem.d.ts +12 -10
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/fullAccessHost.d.ts +3 -3
- package/dist/common/fullAccessHost.js +6 -6
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/pathUtils.d.ts +13 -13
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.js +12 -7
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/uriParser.d.ts +2 -2
- package/dist/common/uriParser.js +3 -3
- package/dist/common/uriParser.js.map +1 -1
- package/dist/common/workspaceEditUtils.d.ts +5 -5
- package/dist/common/workspaceEditUtils.js +7 -4
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +32 -31
- package/dist/languageServerBase.js +278 -345
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.js +0 -1
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.d.ts +16 -12
- package/dist/languageService/callHierarchyProvider.js +125 -41
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +10 -13
- package/dist/languageService/completionProvider.js +21 -10
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +23 -9
- package/dist/languageService/definitionProvider.js +116 -91
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentHighlightProvider.d.ts +8 -3
- package/dist/languageService/documentHighlightProvider.js +17 -6
- package/dist/languageService/documentHighlightProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +6 -7
- package/dist/languageService/documentSymbolCollector.js +21 -11
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/documentSymbolProvider.js +5 -3
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +4 -3
- package/dist/languageService/hoverProvider.js +30 -36
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/navigationUtils.d.ts +6 -0
- package/dist/languageService/navigationUtils.js +28 -0
- package/dist/languageService/navigationUtils.js.map +1 -0
- package/dist/languageService/quickActions.d.ts +2 -2
- package/dist/languageService/quickActions.js +12 -1
- package/dist/languageService/quickActions.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +13 -12
- package/dist/languageService/referencesProvider.js +102 -16
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.d.ts +17 -0
- package/dist/languageService/renameProvider.js +143 -0
- package/dist/languageService/renameProvider.js.map +1 -0
- package/dist/languageService/signatureHelpProvider.d.ts +19 -23
- package/dist/languageService/signatureHelpProvider.js +111 -18
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +17 -14
- package/dist/localization/localize.js +4 -6
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +5 -6
- package/dist/parser/characterStream.d.ts +3 -3
- package/dist/parser/characterStream.js +12 -12
- package/dist/parser/characterStream.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -1
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +57 -54
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +1 -1
- package/dist/pyrightFileSystem.js +21 -21
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +6 -6
- package/dist/readonlyAugmentedFileSystem.js +28 -28
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +6 -6
- package/dist/server.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +1 -1
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/checker.test.js +1 -1
- package/dist/tests/documentSymbolCollector.test.js +3 -3
- package/dist/tests/documentSymbolCollector.test.js.map +1 -1
- package/dist/tests/fourslash/fourslash.d.ts +4 -4
- package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js +1 -1
- package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +3 -3
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +11 -11
- package/dist/tests/harness/fourslash/testState.js +123 -113
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +8 -8
- package/dist/tests/harness/vfs/filesystem.js +68 -68
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +34 -0
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/signatureHelp.test.js +5 -1
- package/dist/tests/signatureHelp.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +2 -2
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/testStateUtils.d.ts +2 -2
- package/dist/tests/testStateUtils.js +39 -9
- package/dist/tests/testStateUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +8 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +13 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +2 -2
- package/dist/tests/typeEvaluator4.test.js +9 -1
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +4 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +84 -0
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/package.json +4 -4
- package/dist/languageService/indentationUtils.d.ts +0 -16
- package/dist/languageService/indentationUtils.js +0 -727
- package/dist/languageService/indentationUtils.js.map +0 -1
- package/dist/languageService/insertionPointUtils.d.ts +0 -9
- package/dist/languageService/insertionPointUtils.js +0 -132
- package/dist/languageService/insertionPointUtils.js.map +0 -1
- package/dist/languageService/renameModuleProvider.d.ts +0 -65
- package/dist/languageService/renameModuleProvider.js +0 -939
- package/dist/languageService/renameModuleProvider.js.map +0 -1
- package/dist/tests/indentationUtils.ptvs.test.d.ts +0 -1
- package/dist/tests/indentationUtils.ptvs.test.js +0 -324
- package/dist/tests/indentationUtils.ptvs.test.js.map +0 -1
- package/dist/tests/indentationUtils.reindent.test.d.ts +0 -1
- package/dist/tests/indentationUtils.reindent.test.js +0 -372
- package/dist/tests/indentationUtils.reindent.test.js.map +0 -1
- package/dist/tests/indentationUtils.test.d.ts +0 -1
- package/dist/tests/indentationUtils.test.js +0 -502
- package/dist/tests/indentationUtils.test.js.map +0 -1
- package/dist/tests/insertionPointUtils.test.d.ts +0 -1
- package/dist/tests/insertionPointUtils.test.js +0 -154
- package/dist/tests/insertionPointUtils.test.js.map +0 -1
- package/dist/tests/moveSymbol.importAdder.test.d.ts +0 -1
- package/dist/tests/moveSymbol.importAdder.test.js +0 -298
- package/dist/tests/moveSymbol.importAdder.test.js.map +0 -1
- package/dist/tests/moveSymbol.insertion.test.d.ts +0 -1
- package/dist/tests/moveSymbol.insertion.test.js +0 -537
- package/dist/tests/moveSymbol.insertion.test.js.map +0 -1
- package/dist/tests/moveSymbol.misc.test.d.ts +0 -1
- package/dist/tests/moveSymbol.misc.test.js +0 -169
- package/dist/tests/moveSymbol.misc.test.js.map +0 -1
- package/dist/tests/moveSymbol.updateReference.test.d.ts +0 -1
- package/dist/tests/moveSymbol.updateReference.test.js +0 -1057
- package/dist/tests/moveSymbol.updateReference.test.js.map +0 -1
- package/dist/tests/renameModule.folder.test.d.ts +0 -1
- package/dist/tests/renameModule.folder.test.js +0 -229
- package/dist/tests/renameModule.folder.test.js.map +0 -1
- package/dist/tests/renameModule.fromImports.test.d.ts +0 -1
- package/dist/tests/renameModule.fromImports.test.js +0 -790
- package/dist/tests/renameModule.fromImports.test.js.map +0 -1
- package/dist/tests/renameModule.imports.test.d.ts +0 -1
- package/dist/tests/renameModule.imports.test.js +0 -380
- package/dist/tests/renameModule.imports.test.js.map +0 -1
- package/dist/tests/renameModule.misc.test.d.ts +0 -1
- package/dist/tests/renameModule.misc.test.js +0 -615
- package/dist/tests/renameModule.misc.test.js.map +0 -1
- package/dist/tests/renameModule.relativePath.test.d.ts +0 -1
- package/dist/tests/renameModule.relativePath.test.js +0 -231
- package/dist/tests/renameModule.relativePath.test.js.map +0 -1
- package/dist/tests/renameModuleTestUtils.d.ts +0 -4
- package/dist/tests/renameModuleTestUtils.js +0 -76
- package/dist/tests/renameModuleTestUtils.js.map +0 -1
@@ -14,6 +14,7 @@ exports.LanguageServerBase = void 0;
|
|
14
14
|
require("./common/extensions");
|
15
15
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
16
16
|
const progress_1 = require("vscode-languageserver/lib/common/progress");
|
17
|
+
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
17
18
|
const backgroundAnalysisProgram_1 = require("./analyzer/backgroundAnalysisProgram");
|
18
19
|
const cacheManager_1 = require("./analyzer/cacheManager");
|
19
20
|
const service_1 = require("./analyzer/service");
|
@@ -31,14 +32,19 @@ const pathUtils_1 = require("./common/pathUtils");
|
|
31
32
|
const progressReporter_1 = require("./common/progressReporter");
|
32
33
|
const stringUtils_1 = require("./common/stringUtils");
|
33
34
|
const uriParser_1 = require("./common/uriParser");
|
34
|
-
const workspaceEditUtils_1 = require("./common/workspaceEditUtils");
|
35
35
|
const analyzerServiceExecutor_1 = require("./languageService/analyzerServiceExecutor");
|
36
|
+
const callHierarchyProvider_1 = require("./languageService/callHierarchyProvider");
|
36
37
|
const definitionProvider_1 = require("./languageService/definitionProvider");
|
38
|
+
const documentHighlightProvider_1 = require("./languageService/documentHighlightProvider");
|
37
39
|
const documentSymbolProvider_1 = require("./languageService/documentSymbolProvider");
|
38
40
|
const hoverProvider_1 = require("./languageService/hoverProvider");
|
41
|
+
const navigationUtils_1 = require("./languageService/navigationUtils");
|
42
|
+
const referencesProvider_1 = require("./languageService/referencesProvider");
|
43
|
+
const signatureHelpProvider_1 = require("./languageService/signatureHelpProvider");
|
39
44
|
const localize_1 = require("./localization/localize");
|
40
45
|
const pyrightFileSystem_1 = require("./pyrightFileSystem");
|
41
46
|
const workspaceFactory_1 = require("./workspaceFactory");
|
47
|
+
const renameProvider_1 = require("./languageService/renameProvider");
|
42
48
|
const nullProgressReporter = (0, progress_1.attachWorkDone)(undefined, /* params */ undefined);
|
43
49
|
/*
|
44
50
|
* Additional DiagnosticTag values that are specific to Visual Studio.
|
@@ -99,10 +105,10 @@ var VSDiagnosticRank;
|
|
99
105
|
VSDiagnosticRank.Lowest = 500;
|
100
106
|
})(VSDiagnosticRank || (VSDiagnosticRank = {}));
|
101
107
|
class LanguageServerBase {
|
102
|
-
constructor(
|
108
|
+
constructor(serverOptions, connection, console, uriParserFactory = (fs) => new uriParser_1.UriParser(fs)) {
|
103
109
|
var _a, _b;
|
104
|
-
this.
|
105
|
-
this.
|
110
|
+
this.serverOptions = serverOptions;
|
111
|
+
this.connection = connection;
|
106
112
|
this.console = console;
|
107
113
|
this._lastTriggerKind = vscode_languageserver_1.CompletionTriggerKind.Invoked;
|
108
114
|
this._initialized = false;
|
@@ -131,33 +137,121 @@ class LanguageServerBase {
|
|
131
137
|
supportsTaskItemDiagnosticTag: false,
|
132
138
|
completionItemResolveSupportsAdditionalTextEdits: false,
|
133
139
|
};
|
140
|
+
this.openFileMap = new Map();
|
134
141
|
// Stash the base directory into a global variable.
|
135
142
|
// This must happen before fs.getModulePath().
|
136
|
-
global.__rootDirectory =
|
137
|
-
this.console.info(`${
|
138
|
-
this.console.info(`Server root directory: ${
|
139
|
-
this.
|
140
|
-
this.
|
141
|
-
this.
|
142
|
-
this.
|
143
|
+
global.__rootDirectory = serverOptions.rootDirectory;
|
144
|
+
this.console.info(`${serverOptions.productName} language server ${serverOptions.version && serverOptions.version + ' '}starting`);
|
145
|
+
this.console.info(`Server root directory: ${serverOptions.rootDirectory}`);
|
146
|
+
this.cacheManager = new cacheManager_1.CacheManager();
|
147
|
+
this.fs = new pyrightFileSystem_1.PyrightFileSystem(this.serverOptions.fileSystem);
|
148
|
+
this.uriParser = uriParserFactory(this.fs);
|
149
|
+
this.workspaceFactory = new workspaceFactory_1.WorkspaceFactory(this.console, this.uriParser, this.createAnalyzerServiceForWorkspace.bind(this), this.isPythonPathImmutable.bind(this), this.onWorkspaceCreated.bind(this));
|
143
150
|
// Set the working directory to a known location within
|
144
151
|
// the extension directory. Otherwise the execution of
|
145
152
|
// python can have unintended and surprising results.
|
146
|
-
const moduleDirectory = this.
|
153
|
+
const moduleDirectory = this.fs.getModulePath();
|
147
154
|
if (moduleDirectory) {
|
148
|
-
this.
|
155
|
+
this.fs.chdir(moduleDirectory);
|
149
156
|
}
|
150
157
|
// Set up callbacks.
|
151
|
-
this.setupConnection((_a =
|
158
|
+
this.setupConnection((_a = serverOptions.supportedCommands) !== null && _a !== void 0 ? _a : [], (_b = serverOptions.supportedCodeActions) !== null && _b !== void 0 ? _b : []);
|
152
159
|
this._progressReporter = new progressReporter_1.ProgressReportTracker(this.createProgressReporter());
|
153
160
|
// Listen on the connection.
|
154
|
-
this.
|
161
|
+
this.connection.listen();
|
155
162
|
// Setup extensions
|
156
163
|
extensibility_1.Extensions.createLanguageServiceExtensions(this);
|
157
164
|
}
|
165
|
+
// Provides access to the client's window.
|
166
|
+
get window() {
|
167
|
+
return this.connection.window;
|
168
|
+
}
|
169
|
+
get supportAdvancedEdits() {
|
170
|
+
return this.client.hasDocumentChangeCapability && this.client.hasDocumentAnnotationCapability;
|
171
|
+
}
|
158
172
|
// Convert uri to path
|
159
173
|
decodeTextDocumentUri(uriString) {
|
160
|
-
return this.
|
174
|
+
return this.uriParser.decodeTextDocumentUri(uriString);
|
175
|
+
}
|
176
|
+
// Creates a service instance that's used for analyzing a
|
177
|
+
// program within a workspace.
|
178
|
+
createAnalyzerService(name, services, libraryReanalysisTimeProvider) {
|
179
|
+
var _a;
|
180
|
+
this.console.info(`Starting service instance "${name}"`);
|
181
|
+
const serviceId = (0, service_1.getNextServiceId)(name);
|
182
|
+
const service = new service_1.AnalyzerService(name, (_a = services === null || services === void 0 ? void 0 : services.fs) !== null && _a !== void 0 ? _a : this.fs, {
|
183
|
+
console: this.console,
|
184
|
+
hostFactory: this.createHost.bind(this),
|
185
|
+
importResolverFactory: this.createImportResolver.bind(this),
|
186
|
+
backgroundAnalysis: services ? services.backgroundAnalysis : this.createBackgroundAnalysis(serviceId),
|
187
|
+
maxAnalysisTime: this.serverOptions.maxAnalysisTimeInForeground,
|
188
|
+
backgroundAnalysisProgramFactory: this.createBackgroundAnalysisProgram.bind(this),
|
189
|
+
cancellationProvider: this.serverOptions.cancellationProvider,
|
190
|
+
libraryReanalysisTimeProvider,
|
191
|
+
cacheManager: this.cacheManager,
|
192
|
+
serviceId,
|
193
|
+
});
|
194
|
+
service.setCompletionCallback((results) => this.onAnalysisCompletedHandler(service.fs, results));
|
195
|
+
return service;
|
196
|
+
}
|
197
|
+
async test_getWorkspaces() {
|
198
|
+
const workspaces = [...this.workspaceFactory.items()];
|
199
|
+
for (const workspace of workspaces) {
|
200
|
+
await workspace.isInitialized.promise;
|
201
|
+
}
|
202
|
+
return workspaces;
|
203
|
+
}
|
204
|
+
async getWorkspaceForFile(filePath, pythonPath) {
|
205
|
+
return this.workspaceFactory.getWorkspaceForFile(filePath, pythonPath);
|
206
|
+
}
|
207
|
+
async getContainingWorkspacesForFile(filePath) {
|
208
|
+
return this.workspaceFactory.getContainingWorkspacesForFile(filePath);
|
209
|
+
}
|
210
|
+
reanalyze() {
|
211
|
+
this.workspaceFactory.items().forEach((workspace) => {
|
212
|
+
workspace.service.invalidateAndForceReanalysis();
|
213
|
+
});
|
214
|
+
}
|
215
|
+
restart() {
|
216
|
+
this.workspaceFactory.items().forEach((workspace) => {
|
217
|
+
workspace.service.restart();
|
218
|
+
});
|
219
|
+
}
|
220
|
+
updateSettingsForAllWorkspaces() {
|
221
|
+
const tasks = [];
|
222
|
+
this.workspaceFactory.items().forEach((workspace) => {
|
223
|
+
// Updating settings can change workspace's file ownership. Make workspace uninitialized so that
|
224
|
+
// features can wait until workspace gets new settings.
|
225
|
+
// the file's ownership can also changed by `pyrightconfig.json` changes, but those are synchronous
|
226
|
+
// operation, so it won't affect this.
|
227
|
+
workspace.isInitialized = workspace.isInitialized.reset();
|
228
|
+
tasks.push(this.updateSettingsForWorkspace(workspace, workspace.isInitialized));
|
229
|
+
});
|
230
|
+
Promise.all(tasks).then(() => {
|
231
|
+
this._setupFileWatcher();
|
232
|
+
});
|
233
|
+
}
|
234
|
+
async updateSettingsForWorkspace(workspace, status, serverSettings) {
|
235
|
+
var _a;
|
236
|
+
status === null || status === void 0 ? void 0 : status.markCalled();
|
237
|
+
serverSettings = serverSettings !== null && serverSettings !== void 0 ? serverSettings : (await this.getSettings(workspace));
|
238
|
+
// Set logging level first.
|
239
|
+
this.console.level = (_a = serverSettings.logLevel) !== null && _a !== void 0 ? _a : console_1.LogLevel.Info;
|
240
|
+
// Apply the new path to the workspace (before restarting the service).
|
241
|
+
serverSettings.pythonPath = this.workspaceFactory.applyPythonPath(workspace, serverSettings.pythonPath);
|
242
|
+
// Then use the updated settings to restart the service.
|
243
|
+
this.updateOptionsAndRestartService(workspace, serverSettings);
|
244
|
+
workspace.disableLanguageServices = !!serverSettings.disableLanguageServices;
|
245
|
+
workspace.disableOrganizeImports = !!serverSettings.disableOrganizeImports;
|
246
|
+
// Don't use workspace.isInitialized directly since it might have been
|
247
|
+
// reset due to pending config change event.
|
248
|
+
// The workspace is now open for business.
|
249
|
+
status === null || status === void 0 ? void 0 : status.resolve();
|
250
|
+
}
|
251
|
+
updateOptionsAndRestartService(workspace, serverSettings, typeStubTargetImportName) {
|
252
|
+
var _a;
|
253
|
+
analyzerServiceExecutor_1.AnalyzerServiceExecutor.runWithOptions(this.rootPath, workspace, serverSettings, typeStubTargetImportName);
|
254
|
+
workspace.searchPathsToWatch = (_a = workspace.service.librarySearchPathsToWatch) !== null && _a !== void 0 ? _a : [];
|
161
255
|
}
|
162
256
|
isPythonPathImmutable(filePath) {
|
163
257
|
// This function is called to determine if the file is using
|
@@ -174,19 +268,16 @@ class LanguageServerBase {
|
|
174
268
|
if (section !== undefined) {
|
175
269
|
item.section = section;
|
176
270
|
}
|
177
|
-
return this.
|
271
|
+
return this.connection.workspace.getConfiguration(item);
|
178
272
|
}
|
179
|
-
if (this.
|
180
|
-
return (0, collectionUtils_1.getNestedProperty)(this.
|
273
|
+
if (this.defaultClientConfig) {
|
274
|
+
return (0, collectionUtils_1.getNestedProperty)(this.defaultClientConfig, section);
|
181
275
|
}
|
182
276
|
return undefined;
|
183
277
|
}
|
184
278
|
isOpenFilesOnly(diagnosticMode) {
|
185
279
|
return diagnosticMode !== 'workspace';
|
186
280
|
}
|
187
|
-
get allowModuleRename() {
|
188
|
-
return false;
|
189
|
-
}
|
190
281
|
getSeverityOverrides(value) {
|
191
282
|
const enumValue = value;
|
192
283
|
if ((0, commandLineOptions_1.getDiagnosticSeverityOverrides)().includes(enumValue)) {
|
@@ -205,87 +296,36 @@ class LanguageServerBase {
|
|
205
296
|
return new backgroundAnalysisProgram_1.BackgroundAnalysisProgram(console, configOptions, importResolver, backgroundAnalysis, maxAnalysisTime,
|
206
297
|
/* disableChecker */ undefined, cacheManager);
|
207
298
|
}
|
208
|
-
// Provides access to the client's window.
|
209
|
-
get window() {
|
210
|
-
return this._connection.window;
|
211
|
-
}
|
212
|
-
get supportAdvancedEdits() {
|
213
|
-
return this.client.hasDocumentChangeCapability && this.client.hasDocumentAnnotationCapability;
|
214
|
-
}
|
215
|
-
// Creates a service instance that's used for analyzing a
|
216
|
-
// program within a workspace.
|
217
|
-
createAnalyzerService(name, services, libraryReanalysisTimeProvider) {
|
218
|
-
var _a;
|
219
|
-
this.console.info(`Starting service instance "${name}"`);
|
220
|
-
const serviceId = (0, service_1.getNextServiceId)(name);
|
221
|
-
const service = new service_1.AnalyzerService(name, (_a = services === null || services === void 0 ? void 0 : services.fs) !== null && _a !== void 0 ? _a : this._serviceFS, {
|
222
|
-
console: this.console,
|
223
|
-
hostFactory: this.createHost.bind(this),
|
224
|
-
importResolverFactory: this.createImportResolver.bind(this),
|
225
|
-
backgroundAnalysis: services ? services.backgroundAnalysis : this.createBackgroundAnalysis(serviceId),
|
226
|
-
maxAnalysisTime: this._serverOptions.maxAnalysisTimeInForeground,
|
227
|
-
backgroundAnalysisProgramFactory: this.createBackgroundAnalysisProgram.bind(this),
|
228
|
-
cancellationProvider: this._serverOptions.cancellationProvider,
|
229
|
-
libraryReanalysisTimeProvider,
|
230
|
-
cacheManager: this._cacheManager,
|
231
|
-
serviceId,
|
232
|
-
});
|
233
|
-
service.setCompletionCallback((results) => this.onAnalysisCompletedHandler(service.fs, results));
|
234
|
-
return service;
|
235
|
-
}
|
236
|
-
async test_getWorkspaces() {
|
237
|
-
const workspaces = [...this._workspaceFactory.items()];
|
238
|
-
for (const workspace of workspaces) {
|
239
|
-
await workspace.isInitialized.promise;
|
240
|
-
}
|
241
|
-
return workspaces;
|
242
|
-
}
|
243
|
-
async getWorkspaceForFile(filePath, pythonPath) {
|
244
|
-
return this._workspaceFactory.getWorkspaceForFile(filePath, pythonPath);
|
245
|
-
}
|
246
|
-
async getContainingWorkspacesForFile(filePath) {
|
247
|
-
return this._workspaceFactory.getContainingWorkspacesForFile(filePath);
|
248
|
-
}
|
249
|
-
reanalyze() {
|
250
|
-
this._workspaceFactory.items().forEach((workspace) => {
|
251
|
-
workspace.service.invalidateAndForceReanalysis();
|
252
|
-
});
|
253
|
-
}
|
254
|
-
restart() {
|
255
|
-
this._workspaceFactory.items().forEach((workspace) => {
|
256
|
-
workspace.service.restart();
|
257
|
-
});
|
258
|
-
}
|
259
299
|
setupConnection(supportedCommands, supportedCodeActions) {
|
260
300
|
// After the server has started the client sends an initialize request. The server receives
|
261
301
|
// in the passed params the rootPath of the workspace plus the client capabilities.
|
262
|
-
this.
|
263
|
-
this.
|
264
|
-
this.
|
265
|
-
this.
|
266
|
-
this.
|
267
|
-
this.
|
268
|
-
this.
|
269
|
-
this.
|
270
|
-
this.
|
271
|
-
this.
|
272
|
-
this.
|
273
|
-
this.
|
274
|
-
this.
|
275
|
-
this.
|
276
|
-
this.
|
277
|
-
this.
|
278
|
-
this.
|
279
|
-
const callHierarchy = this.
|
302
|
+
this.connection.onInitialize((params) => this.initialize(params, supportedCommands, supportedCodeActions));
|
303
|
+
this.connection.onInitialized(() => this.onInitialized());
|
304
|
+
this.connection.onDidChangeConfiguration((params) => this.onDidChangeConfiguration(params));
|
305
|
+
this.connection.onCodeAction((params, token) => this.executeCodeAction(params, token));
|
306
|
+
this.connection.onDefinition(async (params, token) => this.onDefinition(params, token));
|
307
|
+
this.connection.onDeclaration(async (params, token) => this.onDeclaration(params, token));
|
308
|
+
this.connection.onTypeDefinition(async (params, token) => this.onTypeDefinition(params, token));
|
309
|
+
this.connection.onReferences(async (params, token, workDoneReporter, resultReporter) => this.onReferences(params, token, workDoneReporter, resultReporter));
|
310
|
+
this.connection.onDocumentSymbol(async (params, token) => this.onDocumentSymbol(params, token));
|
311
|
+
this.connection.onWorkspaceSymbol(async (params, token, _, resultReporter) => this.onWorkspaceSymbol(params, token, resultReporter));
|
312
|
+
this.connection.onHover(async (params, token) => this.onHover(params, token));
|
313
|
+
this.connection.onDocumentHighlight(async (params, token) => this.onDocumentHighlight(params, token));
|
314
|
+
this.connection.onSignatureHelp(async (params, token) => this.onSignatureHelp(params, token));
|
315
|
+
this.connection.onCompletion((params, token) => this.onCompletion(params, token));
|
316
|
+
this.connection.onCompletionResolve(async (params, token) => this.onCompletionResolve(params, token));
|
317
|
+
this.connection.onPrepareRename(async (params, token) => this.onPrepareRenameRequest(params, token));
|
318
|
+
this.connection.onRenameRequest(async (params, token) => this.onRenameRequest(params, token));
|
319
|
+
const callHierarchy = this.connection.languages.callHierarchy;
|
280
320
|
callHierarchy.onPrepare(async (params, token) => this.onPrepare(params, token));
|
281
321
|
callHierarchy.onIncomingCalls(async (params, token) => this.onIncomingCalls(params, token));
|
282
322
|
callHierarchy.onOutgoingCalls(async (params, token) => this.onOutgoingCalls(params, token));
|
283
|
-
this.
|
284
|
-
this.
|
285
|
-
this.
|
286
|
-
this.
|
287
|
-
this.
|
288
|
-
this.
|
323
|
+
this.connection.onDidOpenTextDocument(async (params) => this.onDidOpenTextDocument(params));
|
324
|
+
this.connection.onDidChangeTextDocument(async (params) => this.onDidChangeTextDocument(params));
|
325
|
+
this.connection.onDidCloseTextDocument(async (params) => this.onDidCloseTextDocument(params));
|
326
|
+
this.connection.onDidChangeWatchedFiles((params) => this.onDidChangeWatchedFiles(params));
|
327
|
+
this.connection.onExecuteCommand(async (params, token, reporter) => this.onExecuteCommand(params, token, reporter));
|
328
|
+
this.connection.onShutdown(async (token) => this.onShutdown(token));
|
289
329
|
}
|
290
330
|
initialize(params, supportedCommands, supportedCodeActions) {
|
291
331
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19;
|
@@ -327,7 +367,7 @@ class LanguageServerBase {
|
|
327
367
|
this.client.completionItemResolveSupportsAdditionalTextEdits =
|
328
368
|
!!((_19 = (_18 = (_17 = (_16 = capabilities.textDocument) === null || _16 === void 0 ? void 0 : _16.completion) === null || _17 === void 0 ? void 0 : _17.completionItem) === null || _18 === void 0 ? void 0 : _18.resolveSupport) === null || _19 === void 0 ? void 0 : _19.properties.some((p) => p === 'additionalTextEdits'));
|
329
369
|
// Create a service instance for each of the workspace folders.
|
330
|
-
this.
|
370
|
+
this.workspaceFactory.handleInitialize(params);
|
331
371
|
const result = {
|
332
372
|
capabilities: {
|
333
373
|
textDocumentSync: vscode_languageserver_1.TextDocumentSyncKind.Incremental,
|
@@ -382,64 +422,37 @@ class LanguageServerBase {
|
|
382
422
|
this.updateSettingsForAllWorkspaces();
|
383
423
|
return;
|
384
424
|
}
|
385
|
-
this.
|
386
|
-
this.
|
425
|
+
this.connection.workspace.onDidChangeWorkspaceFolders((event) => {
|
426
|
+
this.workspaceFactory.handleWorkspaceFoldersChanged(event);
|
387
427
|
this._setupFileWatcher();
|
388
428
|
});
|
389
429
|
this._setupFileWatcher();
|
390
430
|
}
|
391
|
-
_setupFileWatcher() {
|
392
|
-
if (!this.client.hasWatchFileCapability) {
|
393
|
-
return;
|
394
|
-
}
|
395
|
-
const watchKind = vscode_languageserver_1.WatchKind.Create | vscode_languageserver_1.WatchKind.Change | vscode_languageserver_1.WatchKind.Delete;
|
396
|
-
// Set default (config files and all workspace files) first.
|
397
|
-
const watchers = [
|
398
|
-
...service_1.configFileNames.map((fileName) => ({ globPattern: `**/${fileName}`, kind: watchKind })),
|
399
|
-
{ globPattern: '**', kind: watchKind },
|
400
|
-
];
|
401
|
-
// Add all python search paths to watch list
|
402
|
-
if (this.client.hasWatchFileRelativePathCapability) {
|
403
|
-
// Dedup search paths from all workspaces.
|
404
|
-
// Get rid of any search path under workspace root since it is already watched by
|
405
|
-
// "**" above.
|
406
|
-
const foldersToWatch = (0, pathUtils_1.deduplicateFolders)(this._workspaceFactory
|
407
|
-
.getNonDefaultWorkspaces()
|
408
|
-
.map((w) => w.searchPathsToWatch.filter((p) => !p.startsWith(w.rootPath))));
|
409
|
-
foldersToWatch.forEach((p) => {
|
410
|
-
const globPattern = (0, pathUtils_1.isFile)(this._serviceFS, p, /* treatZipDirectoryAsFile */ true)
|
411
|
-
? { baseUri: (0, pathUtils_1.convertPathToUri)(this._serviceFS, (0, pathUtils_1.getDirectoryPath)(p)), pattern: (0, pathUtils_1.getFileName)(p) }
|
412
|
-
: { baseUri: (0, pathUtils_1.convertPathToUri)(this._serviceFS, p), pattern: '**' };
|
413
|
-
watchers.push({ globPattern, kind: watchKind });
|
414
|
-
});
|
415
|
-
}
|
416
|
-
// File watcher is pylance wide service. Dispose all existing file watchers and create new ones.
|
417
|
-
this._connection.client.register(vscode_languageserver_1.DidChangeWatchedFilesNotification.type, { watchers }).then((d) => {
|
418
|
-
if (this._lastFileWatcherRegistration) {
|
419
|
-
this._lastFileWatcherRegistration.dispose();
|
420
|
-
}
|
421
|
-
this._lastFileWatcherRegistration = d;
|
422
|
-
});
|
423
|
-
}
|
424
431
|
onDidChangeConfiguration(params) {
|
425
432
|
this.console.log(`Received updated settings`);
|
426
433
|
if (params === null || params === void 0 ? void 0 : params.settings) {
|
427
|
-
this.
|
434
|
+
this.defaultClientConfig = params === null || params === void 0 ? void 0 : params.settings;
|
428
435
|
}
|
429
436
|
this.updateSettingsForAllWorkspaces();
|
430
437
|
}
|
431
438
|
async onDefinition(params, token) {
|
432
|
-
return this.getDefinitions(params, token, this.client.hasGoToDeclarationCapability ? definitionProvider_1.DefinitionFilter.PreferSource : definitionProvider_1.DefinitionFilter.All, (workspace, filePath, position, filter, token) => workspace.service.
|
439
|
+
return this.getDefinitions(params, token, this.client.hasGoToDeclarationCapability ? definitionProvider_1.DefinitionFilter.PreferSource : definitionProvider_1.DefinitionFilter.All, (workspace, filePath, position, filter, token) => workspace.service.run((program) => {
|
440
|
+
return new definitionProvider_1.DefinitionProvider(program, filePath, position, filter, token).getDefinitions();
|
441
|
+
}, token));
|
433
442
|
}
|
434
443
|
async onDeclaration(params, token) {
|
435
|
-
return this.getDefinitions(params, token, this.client.hasGoToDeclarationCapability ? definitionProvider_1.DefinitionFilter.PreferStubs : definitionProvider_1.DefinitionFilter.All, (workspace, filePath, position, filter, token) => workspace.service.
|
444
|
+
return this.getDefinitions(params, token, this.client.hasGoToDeclarationCapability ? definitionProvider_1.DefinitionFilter.PreferStubs : definitionProvider_1.DefinitionFilter.All, (workspace, filePath, position, filter, token) => workspace.service.run((program) => {
|
445
|
+
return new definitionProvider_1.DefinitionProvider(program, filePath, position, filter, token).getDefinitions();
|
446
|
+
}, token));
|
436
447
|
}
|
437
448
|
async onTypeDefinition(params, token) {
|
438
|
-
return this.getDefinitions(params, token, definitionProvider_1.DefinitionFilter.All, (workspace, filePath, position, _, token) => workspace.service.
|
449
|
+
return this.getDefinitions(params, token, definitionProvider_1.DefinitionFilter.All, (workspace, filePath, position, _, token) => workspace.service.run((program) => {
|
450
|
+
return new definitionProvider_1.TypeDefinitionProvider(program, filePath, position, token).getDefinitions();
|
451
|
+
}, token));
|
439
452
|
}
|
440
453
|
async getDefinitions(params, token, filter, getDefinitionsFunc) {
|
441
454
|
this.recordUserInteractionTime();
|
442
|
-
const { filePath, position } = this.
|
455
|
+
const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position);
|
443
456
|
const workspace = await this.getWorkspaceForFile(filePath);
|
444
457
|
if (workspace.disableLanguageServices) {
|
445
458
|
return undefined;
|
@@ -464,22 +477,14 @@ class LanguageServerBase {
|
|
464
477
|
const source = progress.source;
|
465
478
|
this._pendingFindAllRefsCancellationSource = source;
|
466
479
|
try {
|
467
|
-
const { filePath, position } = this.
|
480
|
+
const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position);
|
468
481
|
const workspace = await this.getWorkspaceForFile(filePath);
|
469
482
|
if (workspace.disableLanguageServices) {
|
470
483
|
return;
|
471
484
|
}
|
472
|
-
|
473
|
-
return
|
474
|
-
|
475
|
-
.map((loc) => vscode_languageserver_1.Location.create((0, pathUtils_1.convertPathToUri)(workspace.service.fs, loc.path), loc.range));
|
476
|
-
};
|
477
|
-
const locations = [];
|
478
|
-
const reporter = resultReporter
|
479
|
-
? (locs) => resultReporter.report(convert(locs))
|
480
|
-
: (locs) => (0, collectionUtils_1.appendArray)(locations, convert(locs));
|
481
|
-
workspace.service.reportReferencesForPosition(filePath, position, params.context.includeDeclaration, reporter, source.token);
|
482
|
-
return locations;
|
485
|
+
return workspace.service.run((program) => {
|
486
|
+
return new referencesProvider_1.ReferencesProvider(program, source.token).reportReferences(filePath, position, params.context.includeDeclaration, resultReporter);
|
487
|
+
}, token);
|
483
488
|
}
|
484
489
|
finally {
|
485
490
|
progress.reporter.done();
|
@@ -488,7 +493,7 @@ class LanguageServerBase {
|
|
488
493
|
}
|
489
494
|
async onDocumentSymbol(params, token) {
|
490
495
|
this.recordUserInteractionTime();
|
491
|
-
const filePath = this.
|
496
|
+
const filePath = this.uriParser.decodeTextDocumentUri(params.textDocument.uri);
|
492
497
|
const workspace = await this.getWorkspaceForFile(filePath);
|
493
498
|
if (workspace.disableLanguageServices) {
|
494
499
|
return undefined;
|
@@ -505,7 +510,7 @@ class LanguageServerBase {
|
|
505
510
|
const reporter = resultReporter
|
506
511
|
? (symbols) => resultReporter.report(symbols)
|
507
512
|
: (symbols) => (0, collectionUtils_1.appendArray)(symbolList, symbols);
|
508
|
-
for (const workspace of this.
|
513
|
+
for (const workspace of this.workspaceFactory.items()) {
|
509
514
|
await workspace.isInitialized.promise;
|
510
515
|
if (!workspace.disableLanguageServices && !workspace.disableWorkspaceSymbol) {
|
511
516
|
workspace.service.reportSymbolsForWorkspace(params.query, reporter, token);
|
@@ -514,96 +519,28 @@ class LanguageServerBase {
|
|
514
519
|
return symbolList;
|
515
520
|
}
|
516
521
|
async onHover(params, token) {
|
517
|
-
const { filePath, position } = this.
|
522
|
+
const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position);
|
518
523
|
const workspace = await this.getWorkspaceForFile(filePath);
|
519
524
|
return workspace.service.run((program) => {
|
520
|
-
return new hoverProvider_1.HoverProvider(program, filePath, position, this.client.hoverContentFormat,
|
525
|
+
return new hoverProvider_1.HoverProvider(program, filePath, position, this.client.hoverContentFormat, token).getHover();
|
521
526
|
}, token);
|
522
527
|
}
|
523
528
|
async onDocumentHighlight(params, token) {
|
524
|
-
const { filePath, position } = this.
|
529
|
+
const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position);
|
525
530
|
const workspace = await this.getWorkspaceForFile(filePath);
|
526
|
-
return workspace.service.
|
531
|
+
return workspace.service.run((program) => {
|
532
|
+
return new documentHighlightProvider_1.DocumentHighlightProvider(program, filePath, position, token).getDocumentHighlight();
|
533
|
+
}, token);
|
527
534
|
}
|
528
535
|
async onSignatureHelp(params, token) {
|
529
|
-
|
530
|
-
const { filePath, position } = this._uriParser.decodeTextDocumentPosition(params.textDocument, params.position);
|
536
|
+
const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position);
|
531
537
|
const workspace = await this.getWorkspaceForFile(filePath);
|
532
538
|
if (workspace.disableLanguageServices) {
|
533
539
|
return;
|
534
540
|
}
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
}
|
539
|
-
const signatures = signatureHelpResults.signatures.map((sig) => {
|
540
|
-
let paramInfo = [];
|
541
|
-
if (sig.parameters) {
|
542
|
-
paramInfo = sig.parameters.map((param) => vscode_languageserver_1.ParameterInformation.create(this.client.hasSignatureLabelOffsetCapability
|
543
|
-
? [param.startOffset, param.endOffset]
|
544
|
-
: param.text, param.documentation));
|
545
|
-
}
|
546
|
-
const sigInfo = vscode_languageserver_1.SignatureInformation.create(sig.label, /* documentation */ undefined, ...paramInfo);
|
547
|
-
if (sig.documentation !== undefined) {
|
548
|
-
sigInfo.documentation = sig.documentation;
|
549
|
-
}
|
550
|
-
if (sig.activeParameter !== undefined) {
|
551
|
-
sigInfo.activeParameter = sig.activeParameter;
|
552
|
-
}
|
553
|
-
return sigInfo;
|
554
|
-
});
|
555
|
-
// A signature is active if it contains an active parameter,
|
556
|
-
// or if both the signature and its invocation have no parameters.
|
557
|
-
const isActive = (sig) => { var _a; return sig.activeParameter !== undefined || (!signatureHelpResults.callHasParameters && !((_a = sig.parameters) === null || _a === void 0 ? void 0 : _a.length)); };
|
558
|
-
let activeSignature = signatures.findIndex(isActive);
|
559
|
-
if (activeSignature === -1) {
|
560
|
-
activeSignature = undefined;
|
561
|
-
}
|
562
|
-
let activeParameter = activeSignature !== undefined ? signatures[activeSignature].activeParameter : undefined;
|
563
|
-
// Check if we should reuse the user's signature selection. If the retrigger was not "invoked"
|
564
|
-
// (i.e., the signature help call was automatically generated by the client due to some navigation
|
565
|
-
// or text change), check to see if the previous signature is still "active". If so, we mark it as
|
566
|
-
// active in our response.
|
567
|
-
//
|
568
|
-
// This isn't a perfect method. For nested calls, we can't tell when we are moving between them.
|
569
|
-
// Ideally, we would include a token in the signature help responses to compare later, allowing us
|
570
|
-
// to know when the user's navigated to a nested call (and therefore the old signature's info does
|
571
|
-
// not apply), but for now manually retriggering the signature help will work around the issue.
|
572
|
-
if (((_a = params.context) === null || _a === void 0 ? void 0 : _a.isRetrigger) && params.context.triggerKind !== vscode_languageserver_1.SignatureHelpTriggerKind.Invoked) {
|
573
|
-
const prevActiveSignature = (_b = params.context.activeSignatureHelp) === null || _b === void 0 ? void 0 : _b.activeSignature;
|
574
|
-
if (prevActiveSignature !== undefined && prevActiveSignature < signatures.length) {
|
575
|
-
const sig = signatures[prevActiveSignature];
|
576
|
-
if (isActive(sig)) {
|
577
|
-
activeSignature = prevActiveSignature;
|
578
|
-
activeParameter = sig.activeParameter;
|
579
|
-
}
|
580
|
-
}
|
581
|
-
}
|
582
|
-
if (this.client.hasActiveParameterCapability || activeSignature === undefined) {
|
583
|
-
// If there is no active parameter, then we want the client to not highlight anything.
|
584
|
-
// Unfortunately, the LSP spec says that "undefined" or "out of bounds" values should be
|
585
|
-
// treated as 0, which is the first parameter. That's not what we want, but thankfully
|
586
|
-
// VS Code (and potentially other clients) choose to handle out of bounds values by
|
587
|
-
// not highlighting them, which is what we want.
|
588
|
-
//
|
589
|
-
// The spec defines activeParameter as uinteger, so use the maximum length of any
|
590
|
-
// signature's parameter list to ensure that the value is always out of range.
|
591
|
-
//
|
592
|
-
// We always set this even if some signature has an active parameter, as this
|
593
|
-
// value is used as the fallback for signatures that don't explicitly specify an
|
594
|
-
// active parameter (and we use "undefined" to mean "no active parameter").
|
595
|
-
//
|
596
|
-
// We could apply this hack to each individual signature such that they all specify
|
597
|
-
// activeParameter, but that would make it more difficult to determine which actually
|
598
|
-
// are active when comparing, and we already have to set this for clients which don't
|
599
|
-
// support per-signature activeParameter.
|
600
|
-
//
|
601
|
-
// See:
|
602
|
-
// - https://github.com/microsoft/language-server-protocol/issues/1271
|
603
|
-
// - https://github.com/microsoft/pyright/pull/1783
|
604
|
-
activeParameter = Math.max(...signatures.map((s) => { var _a, _b; return (_b = (_a = s.parameters) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0; }));
|
605
|
-
}
|
606
|
-
return { signatures, activeSignature, activeParameter };
|
541
|
+
return workspace.service.run((program) => {
|
542
|
+
return new signatureHelpProvider_1.SignatureHelpProvider(program, filePath, position, this.client.signatureDocFormat, this.client.hasSignatureLabelOffsetCapability, this.client.hasActiveParameterCapability, params.context, token).getSignatureHelp();
|
543
|
+
}, token);
|
607
544
|
}
|
608
545
|
async onCompletion(params, token) {
|
609
546
|
var _a, _b;
|
@@ -618,7 +555,7 @@ class LanguageServerBase {
|
|
618
555
|
const completionIncomplete = this._lastTriggerKind !== vscode_languageserver_1.CompletionTriggerKind.TriggerForIncompleteCompletions ||
|
619
556
|
((_a = params.context) === null || _a === void 0 ? void 0 : _a.triggerKind) !== vscode_languageserver_1.CompletionTriggerKind.TriggerForIncompleteCompletions;
|
620
557
|
this._lastTriggerKind = (_b = params.context) === null || _b === void 0 ? void 0 : _b.triggerKind;
|
621
|
-
const { filePath, position } = this.
|
558
|
+
const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position);
|
622
559
|
const workspace = await this.getWorkspaceForFile(filePath);
|
623
560
|
if (workspace.disableLanguageServices) {
|
624
561
|
return;
|
@@ -633,7 +570,7 @@ class LanguageServerBase {
|
|
633
570
|
completions.completionList &&
|
634
571
|
completions.completionList.items.length > 0 &&
|
635
572
|
completions.memberAccessInfo.lastKnownModule &&
|
636
|
-
this.
|
573
|
+
this.serverOptions.supportsTelemetry) {
|
637
574
|
// Just stick it on the first item. It only checks the first one
|
638
575
|
completions.completionList.items[0].data = {
|
639
576
|
...completions.completionList.items[0].data,
|
@@ -657,84 +594,71 @@ class LanguageServerBase {
|
|
657
594
|
return params;
|
658
595
|
}
|
659
596
|
async onPrepareRenameRequest(params, token) {
|
660
|
-
|
661
|
-
const { filePath, position } = this._uriParser.decodeTextDocumentPosition(params.textDocument, params.position);
|
597
|
+
const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position);
|
662
598
|
const workspace = await this.getWorkspaceForFile(filePath);
|
663
599
|
if (workspace.disableLanguageServices) {
|
664
600
|
return null;
|
665
601
|
}
|
666
|
-
|
667
|
-
|
602
|
+
return workspace.service.run((program) => {
|
603
|
+
return new renameProvider_1.RenameProvider(program, filePath, position, token).canRenameSymbol(workspace.kinds.includes(workspaceFactory_1.WellKnownWorkspaceKinds.Default));
|
604
|
+
}, token);
|
668
605
|
}
|
669
606
|
async onRenameRequest(params, token) {
|
670
|
-
const { filePath, position } = this.
|
607
|
+
const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position);
|
671
608
|
const workspace = await this.getWorkspaceForFile(filePath);
|
672
609
|
if (workspace.disableLanguageServices) {
|
673
610
|
return;
|
674
611
|
}
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
}
|
679
|
-
return (0, workspaceEditUtils_1.convertToWorkspaceEdit)(workspace.service.fs, editActions);
|
612
|
+
return workspace.service.run((program) => {
|
613
|
+
return new renameProvider_1.RenameProvider(program, filePath, position, token).renameSymbol(params.newName, workspace.kinds.includes(workspaceFactory_1.WellKnownWorkspaceKinds.Default));
|
614
|
+
}, token);
|
680
615
|
}
|
681
616
|
async onPrepare(params, token) {
|
682
|
-
const { filePath, position } = this.
|
617
|
+
const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position);
|
683
618
|
const workspace = await this.getWorkspaceForFile(filePath);
|
684
619
|
if (workspace.disableLanguageServices) {
|
685
620
|
return null;
|
686
621
|
}
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
}
|
691
|
-
if (!this.canNavigateToFile(callItem.uri, workspace.service.fs)) {
|
692
|
-
return null;
|
693
|
-
}
|
694
|
-
// Convert the file path in the item to proper URI.
|
695
|
-
callItem.uri = (0, pathUtils_1.convertPathToUri)(workspace.service.fs, callItem.uri);
|
696
|
-
return [callItem];
|
622
|
+
return workspace.service.run((program) => {
|
623
|
+
return new callHierarchyProvider_1.CallHierarchyProvider(program, filePath, position, token).onPrepare();
|
624
|
+
}, token);
|
697
625
|
}
|
698
626
|
async onIncomingCalls(params, token) {
|
699
|
-
const { filePath, position } = this.
|
627
|
+
const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.item, params.item.range.start);
|
700
628
|
const workspace = await this.getWorkspaceForFile(filePath);
|
701
629
|
if (workspace.disableLanguageServices) {
|
702
630
|
return null;
|
703
631
|
}
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
}
|
708
|
-
callItems = callItems.filter((item) => this.canNavigateToFile(item.from.uri, workspace.service.fs));
|
709
|
-
// Convert the file paths in the items to proper URIs.
|
710
|
-
callItems.forEach((item) => {
|
711
|
-
item.from.uri = (0, pathUtils_1.convertPathToUri)(workspace.service.fs, item.from.uri);
|
712
|
-
});
|
713
|
-
return callItems;
|
632
|
+
return workspace.service.run((program) => {
|
633
|
+
return new callHierarchyProvider_1.CallHierarchyProvider(program, filePath, position, token).getIncomingCalls();
|
634
|
+
}, token);
|
714
635
|
}
|
715
636
|
async onOutgoingCalls(params, token) {
|
716
|
-
const { filePath, position } = this.
|
637
|
+
const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.item, params.item.range.start);
|
717
638
|
const workspace = await this.getWorkspaceForFile(filePath);
|
718
639
|
if (workspace.disableLanguageServices) {
|
719
640
|
return null;
|
720
641
|
}
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
}
|
725
|
-
callItems = callItems.filter((item) => this.canNavigateToFile(item.to.uri, workspace.service.fs));
|
726
|
-
// Convert the file paths in the items to proper URIs.
|
727
|
-
callItems.forEach((item) => {
|
728
|
-
item.to.uri = (0, pathUtils_1.convertPathToUri)(workspace.service.fs, item.to.uri);
|
729
|
-
});
|
730
|
-
return callItems;
|
642
|
+
return workspace.service.run((program) => {
|
643
|
+
return new callHierarchyProvider_1.CallHierarchyProvider(program, filePath, position, token).getOutgoingCalls();
|
644
|
+
}, token);
|
731
645
|
}
|
732
646
|
async onDidOpenTextDocument(params, ipythonMode = sourceFile_1.IPythonMode.None) {
|
733
|
-
const filePath = this.
|
734
|
-
if (!this.
|
647
|
+
const filePath = this.uriParser.decodeTextDocumentUri(params.textDocument.uri);
|
648
|
+
if (!this.fs.addUriMap(params.textDocument.uri, filePath)) {
|
735
649
|
// We do not support opening 1 file with 2 different uri.
|
736
650
|
return;
|
737
651
|
}
|
652
|
+
let doc = this.openFileMap.get(filePath);
|
653
|
+
if (doc) {
|
654
|
+
// We shouldn't get an open text document request for an already-opened doc.
|
655
|
+
this.console.error(`Received redundant open text document command for ${filePath}`);
|
656
|
+
doc = vscode_languageserver_textdocument_1.TextDocument.update(doc, [{ text: params.textDocument.text }], params.textDocument.version);
|
657
|
+
}
|
658
|
+
else {
|
659
|
+
doc = vscode_languageserver_textdocument_1.TextDocument.create(filePath, 'python', params.textDocument.version, params.textDocument.text);
|
660
|
+
}
|
661
|
+
this.openFileMap.set(filePath, doc);
|
738
662
|
// Send this open to all the workspaces that might contain this file.
|
739
663
|
const workspaces = await this.getContainingWorkspacesForFile(filePath);
|
740
664
|
workspaces.forEach((w) => {
|
@@ -743,20 +667,29 @@ class LanguageServerBase {
|
|
743
667
|
}
|
744
668
|
async onDidChangeTextDocument(params, ipythonMode = sourceFile_1.IPythonMode.None) {
|
745
669
|
this.recordUserInteractionTime();
|
746
|
-
const filePath = this.
|
747
|
-
if (!this.
|
670
|
+
const filePath = this.uriParser.decodeTextDocumentUri(params.textDocument.uri);
|
671
|
+
if (!this.fs.hasUriMapEntry(params.textDocument.uri, filePath)) {
|
748
672
|
// We do not support opening 1 file with 2 different uri.
|
749
673
|
return;
|
750
674
|
}
|
675
|
+
let doc = this.openFileMap.get(filePath);
|
676
|
+
if (!doc) {
|
677
|
+
// We shouldn't get a change text request for a closed doc.
|
678
|
+
this.console.error(`Received change text document command for closed file ${filePath}`);
|
679
|
+
return;
|
680
|
+
}
|
681
|
+
doc = vscode_languageserver_textdocument_1.TextDocument.update(doc, params.contentChanges, params.textDocument.version);
|
682
|
+
this.openFileMap.set(filePath, doc);
|
683
|
+
const newContents = doc.getText();
|
751
684
|
// Send this change to all the workspaces that might contain this file.
|
752
685
|
const workspaces = await this.getContainingWorkspacesForFile(filePath);
|
753
686
|
workspaces.forEach((w) => {
|
754
|
-
w.service.updateOpenFileContents(filePath, params.textDocument.version,
|
687
|
+
w.service.updateOpenFileContents(filePath, params.textDocument.version, newContents, ipythonMode);
|
755
688
|
});
|
756
689
|
}
|
757
690
|
async onDidCloseTextDocument(params) {
|
758
|
-
const filePath = this.
|
759
|
-
if (!this.
|
691
|
+
const filePath = this.uriParser.decodeTextDocumentUri(params.textDocument.uri);
|
692
|
+
if (!this.fs.removeUriMap(params.textDocument.uri, filePath)) {
|
760
693
|
// We do not support opening 1 file with 2 different uri.
|
761
694
|
return;
|
762
695
|
}
|
@@ -765,12 +698,13 @@ class LanguageServerBase {
|
|
765
698
|
workspaces.forEach((w) => {
|
766
699
|
w.service.setFileClosed(filePath);
|
767
700
|
});
|
701
|
+
this.openFileMap.delete(filePath);
|
768
702
|
}
|
769
703
|
onDidChangeWatchedFiles(params) {
|
770
704
|
params.changes.forEach((change) => {
|
771
|
-
const filePath = this.
|
705
|
+
const filePath = this.fs.realCasePath(this.uriParser.decodeTextDocumentUri(change.uri));
|
772
706
|
const eventType = change.type === 1 ? 'add' : 'change';
|
773
|
-
this.
|
707
|
+
this.serverOptions.fileWatcherHandler.onFileChange(eventType, filePath);
|
774
708
|
});
|
775
709
|
}
|
776
710
|
async onExecuteCommand(params, token, reporter) {
|
@@ -784,12 +718,12 @@ class LanguageServerBase {
|
|
784
718
|
if (vscode_languageserver_1.WorkspaceEdit.is(result)) {
|
785
719
|
// Tell client to apply edits.
|
786
720
|
// Do not await; the client isn't expecting a result.
|
787
|
-
this.
|
721
|
+
this.connection.workspace.applyEdit({ label: `Command '${params.command}'`, edit: result });
|
788
722
|
}
|
789
723
|
if (commandResult_1.CommandResult.is(result)) {
|
790
724
|
// Tell client to apply edits.
|
791
725
|
// Await so that we return after the edit is complete.
|
792
|
-
await this.
|
726
|
+
await this.connection.workspace.applyEdit({ label: result.label, edit: result.edits });
|
793
727
|
}
|
794
728
|
return result;
|
795
729
|
};
|
@@ -814,7 +748,9 @@ class LanguageServerBase {
|
|
814
748
|
}
|
815
749
|
onShutdown(token) {
|
816
750
|
// Shutdown remaining workspaces.
|
817
|
-
this.
|
751
|
+
this.workspaceFactory.clear();
|
752
|
+
// Stop tracking all open files.
|
753
|
+
this.openFileMap.clear();
|
818
754
|
return Promise.resolve();
|
819
755
|
}
|
820
756
|
resolveWorkspaceCompletionItem(workspace, filePath, item, token) {
|
@@ -824,20 +760,6 @@ class LanguageServerBase {
|
|
824
760
|
getWorkspaceCompletionsForPosition(workspace, filePath, position, options, token) {
|
825
761
|
return workspace.service.getCompletionsForPosition(filePath, position, workspace.rootPath, options, undefined, token);
|
826
762
|
}
|
827
|
-
updateSettingsForAllWorkspaces() {
|
828
|
-
const tasks = [];
|
829
|
-
this._workspaceFactory.items().forEach((workspace) => {
|
830
|
-
// Updating settings can change workspace's file ownership. Make workspace uninitialized so that
|
831
|
-
// features can wait until workspace gets new settings.
|
832
|
-
// the file's ownership can also changed by `pyrightconfig.json` changes, but those are synchronous
|
833
|
-
// operation, so it won't affect this.
|
834
|
-
workspace.isInitialized = workspace.isInitialized.reset();
|
835
|
-
tasks.push(this.updateSettingsForWorkspace(workspace, workspace.isInitialized));
|
836
|
-
});
|
837
|
-
Promise.all(tasks).then(() => {
|
838
|
-
this._setupFileWatcher();
|
839
|
-
});
|
840
|
-
}
|
841
763
|
getCompletionOptions(workspace, params) {
|
842
764
|
var _a;
|
843
765
|
return {
|
@@ -867,7 +789,7 @@ class LanguageServerBase {
|
|
867
789
|
return;
|
868
790
|
}
|
869
791
|
this._sendDiagnostics(this.convertDiagnostics(fs, fileDiag));
|
870
|
-
this.
|
792
|
+
this.fs.pendingRequest(fileDiag.filePath, fileDiag.diagnostics.length > 0);
|
871
793
|
});
|
872
794
|
if (!this._progressReporter.isEnabled(results)) {
|
873
795
|
// Make sure to disable progress bar if it is currently active.
|
@@ -891,28 +813,6 @@ class LanguageServerBase {
|
|
891
813
|
this._progressReporter.end();
|
892
814
|
}
|
893
815
|
}
|
894
|
-
async updateSettingsForWorkspace(workspace, status, serverSettings) {
|
895
|
-
var _a;
|
896
|
-
status === null || status === void 0 ? void 0 : status.markCalled();
|
897
|
-
serverSettings = serverSettings !== null && serverSettings !== void 0 ? serverSettings : (await this.getSettings(workspace));
|
898
|
-
// Set logging level first.
|
899
|
-
this.console.level = (_a = serverSettings.logLevel) !== null && _a !== void 0 ? _a : console_1.LogLevel.Info;
|
900
|
-
// Apply the new path to the workspace (before restarting the service).
|
901
|
-
serverSettings.pythonPath = this._workspaceFactory.applyPythonPath(workspace, serverSettings.pythonPath);
|
902
|
-
// Then use the updated settings to restart the service.
|
903
|
-
this.updateOptionsAndRestartService(workspace, serverSettings);
|
904
|
-
workspace.disableLanguageServices = !!serverSettings.disableLanguageServices;
|
905
|
-
workspace.disableOrganizeImports = !!serverSettings.disableOrganizeImports;
|
906
|
-
// Don't use workspace.isInitialized directly since it might have been
|
907
|
-
// reset due to pending config change event.
|
908
|
-
// The workspace is now open for business.
|
909
|
-
status === null || status === void 0 ? void 0 : status.resolve();
|
910
|
-
}
|
911
|
-
updateOptionsAndRestartService(workspace, serverSettings, typeStubTargetImportName) {
|
912
|
-
var _a;
|
913
|
-
analyzerServiceExecutor_1.AnalyzerServiceExecutor.runWithOptions(this.rootPath, workspace, serverSettings, typeStubTargetImportName);
|
914
|
-
workspace.searchPathsToWatch = (_a = workspace.service.librarySearchPathsToWatch) !== null && _a !== void 0 ? _a : [];
|
915
|
-
}
|
916
816
|
onWorkspaceCreated(workspace) {
|
917
817
|
// Update settings on this workspace (but only if initialize has happened)
|
918
818
|
if (this._initialized) {
|
@@ -926,15 +826,63 @@ class LanguageServerBase {
|
|
926
826
|
// 10 seconds back off for multi workspace.
|
927
827
|
const multiWorkspaceBackOffTime = 10 * 1000;
|
928
828
|
const libraryReanalysisTimeProvider = kinds.length === 1 && kinds[0] === workspaceFactory_1.WellKnownWorkspaceKinds.Regular
|
929
|
-
? () => this.
|
829
|
+
? () => this.workspaceFactory.hasMultipleWorkspaces(kinds[0])
|
930
830
|
? multiWorkspaceBackOffTime
|
931
831
|
: defaultBackOffTime
|
932
832
|
: () => defaultBackOffTime;
|
933
833
|
return this.createAnalyzerService(name, services, libraryReanalysisTimeProvider);
|
934
834
|
}
|
835
|
+
recordUserInteractionTime() {
|
836
|
+
// Tell all of the services that the user is actively
|
837
|
+
// interacting with one or more editors, so they should
|
838
|
+
// back off from performing any work.
|
839
|
+
this.workspaceFactory.items().forEach((workspace) => {
|
840
|
+
workspace.service.recordUserInteractionTime();
|
841
|
+
});
|
842
|
+
}
|
843
|
+
getDocumentationUrlForDiagnosticRule(rule) {
|
844
|
+
// Configuration.md is configured to have a link for every rule name.
|
845
|
+
return `https://github.com/microsoft/pyright/blob/main/docs/configuration.md#${rule}`;
|
846
|
+
}
|
847
|
+
canNavigateToFile(path, fs) {
|
848
|
+
return (0, navigationUtils_1.canNavigateToFile)(fs, path);
|
849
|
+
}
|
850
|
+
_setupFileWatcher() {
|
851
|
+
if (!this.client.hasWatchFileCapability) {
|
852
|
+
return;
|
853
|
+
}
|
854
|
+
const watchKind = vscode_languageserver_1.WatchKind.Create | vscode_languageserver_1.WatchKind.Change | vscode_languageserver_1.WatchKind.Delete;
|
855
|
+
// Set default (config files and all workspace files) first.
|
856
|
+
const watchers = [
|
857
|
+
...service_1.configFileNames.map((fileName) => ({ globPattern: `**/${fileName}`, kind: watchKind })),
|
858
|
+
{ globPattern: '**', kind: watchKind },
|
859
|
+
];
|
860
|
+
// Add all python search paths to watch list
|
861
|
+
if (this.client.hasWatchFileRelativePathCapability) {
|
862
|
+
// Dedup search paths from all workspaces.
|
863
|
+
// Get rid of any search path under workspace root since it is already watched by
|
864
|
+
// "**" above.
|
865
|
+
const foldersToWatch = (0, pathUtils_1.deduplicateFolders)(this.workspaceFactory
|
866
|
+
.getNonDefaultWorkspaces()
|
867
|
+
.map((w) => w.searchPathsToWatch.filter((p) => !p.startsWith(w.rootPath))));
|
868
|
+
foldersToWatch.forEach((p) => {
|
869
|
+
const globPattern = (0, pathUtils_1.isFile)(this.fs, p, /* treatZipDirectoryAsFile */ true)
|
870
|
+
? { baseUri: (0, pathUtils_1.convertPathToUri)(this.fs, (0, pathUtils_1.getDirectoryPath)(p)), pattern: (0, pathUtils_1.getFileName)(p) }
|
871
|
+
: { baseUri: (0, pathUtils_1.convertPathToUri)(this.fs, p), pattern: '**' };
|
872
|
+
watchers.push({ globPattern, kind: watchKind });
|
873
|
+
});
|
874
|
+
}
|
875
|
+
// File watcher is pylance wide service. Dispose all existing file watchers and create new ones.
|
876
|
+
this.connection.client.register(vscode_languageserver_1.DidChangeWatchedFilesNotification.type, { watchers }).then((d) => {
|
877
|
+
if (this._lastFileWatcherRegistration) {
|
878
|
+
this._lastFileWatcherRegistration.dispose();
|
879
|
+
}
|
880
|
+
this._lastFileWatcherRegistration = d;
|
881
|
+
});
|
882
|
+
}
|
935
883
|
_sendDiagnostics(params) {
|
936
884
|
for (const param of params) {
|
937
|
-
this.
|
885
|
+
this.connection.sendDiagnostics(param);
|
938
886
|
}
|
939
887
|
}
|
940
888
|
_getCompatibleMarkupKind(clientSupportedFormats) {
|
@@ -952,16 +900,16 @@ class LanguageServerBase {
|
|
952
900
|
// created by the LSP library. If it's the latter, we'll create a server-initiated
|
953
901
|
// progress reporter.
|
954
902
|
if (reporter.constructor !== nullProgressReporter.constructor) {
|
955
|
-
return { reporter: reporter, source: (0, cancellationUtils_1.CancelAfter)(this.
|
903
|
+
return { reporter: reporter, source: (0, cancellationUtils_1.CancelAfter)(this.serverOptions.cancellationProvider, token) };
|
956
904
|
}
|
957
|
-
const serverInitiatedReporter = await this.
|
905
|
+
const serverInitiatedReporter = await this.connection.window.createWorkDoneProgress();
|
958
906
|
serverInitiatedReporter.begin(title,
|
959
907
|
/* percentage */ undefined,
|
960
908
|
/* message */ undefined,
|
961
909
|
/* cancellable */ true);
|
962
910
|
return {
|
963
911
|
reporter: serverInitiatedReporter,
|
964
|
-
source: (0, cancellationUtils_1.CancelAfter)(this.
|
912
|
+
source: (0, cancellationUtils_1.CancelAfter)(this.serverOptions.cancellationProvider, token, serverInitiatedReporter.token),
|
965
913
|
};
|
966
914
|
}
|
967
915
|
_convertDiagnostics(fs, diags) {
|
@@ -969,7 +917,7 @@ class LanguageServerBase {
|
|
969
917
|
diags.forEach((diag) => {
|
970
918
|
const severity = convertCategoryToSeverity(diag.category);
|
971
919
|
const rule = diag.getRule();
|
972
|
-
const vsDiag = vscode_languageserver_1.Diagnostic.create(diag.range, diag.message, severity, rule, this.
|
920
|
+
const vsDiag = vscode_languageserver_1.Diagnostic.create(diag.range, diag.message, severity, rule, this.serverOptions.productName);
|
973
921
|
if (diag.category === 3 /* UnusedCode */ ||
|
974
922
|
diag.category === 4 /* UnreachableCode */) {
|
975
923
|
vsDiag.tags = [vscode_languageserver_1.DiagnosticTag.Unnecessary];
|
@@ -1043,21 +991,6 @@ class LanguageServerBase {
|
|
1043
991
|
}
|
1044
992
|
return convertedDiags;
|
1045
993
|
}
|
1046
|
-
recordUserInteractionTime() {
|
1047
|
-
// Tell all of the services that the user is actively
|
1048
|
-
// interacting with one or more editors, so they should
|
1049
|
-
// back off from performing any work.
|
1050
|
-
this._workspaceFactory.items().forEach((workspace) => {
|
1051
|
-
workspace.service.recordUserInteractionTime();
|
1052
|
-
});
|
1053
|
-
}
|
1054
|
-
getDocumentationUrlForDiagnosticRule(rule) {
|
1055
|
-
// Configuration.md is configured to have a link for every rule name.
|
1056
|
-
return `https://github.com/microsoft/pyright/blob/main/docs/configuration.md#${rule}`;
|
1057
|
-
}
|
1058
|
-
canNavigateToFile(path, fs) {
|
1059
|
-
return !fs.isInZipOrEgg(path);
|
1060
|
-
}
|
1061
994
|
}
|
1062
995
|
exports.LanguageServerBase = LanguageServerBase;
|
1063
996
|
//# sourceMappingURL=languageServerBase.js.map
|