@zzzen/pyright-internal 1.2.0-dev.20260614 → 1.2.0-dev.20260628
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/analysis.js +17 -7
- package/dist/analyzer/analysis.js.map +1 -1
- package/dist/analyzer/analyzerNodeInfo.d.ts +11 -0
- package/dist/analyzer/binder.js +31 -8
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +23 -8
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +6 -0
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/dataClasses.js +19 -8
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +1 -0
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/docStringUtils.d.ts +1 -0
- package/dist/analyzer/docStringUtils.js +78 -0
- package/dist/analyzer/docStringUtils.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +1 -0
- package/dist/analyzer/importResolver.js +107 -12
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +36 -8
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +17 -7
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/parseTreeCleaner.js +17 -7
- package/dist/analyzer/parseTreeCleaner.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +27 -9
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +17 -7
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +44 -0
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +1 -0
- package/dist/analyzer/program.js +44 -8
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.js +34 -8
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/service.js +43 -11
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceEnumerator.js +6 -0
- package/dist/analyzer/sourceEnumerator.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +1 -0
- package/dist/analyzer/sourceFile.js +25 -7
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.d.ts +11 -1
- package/dist/analyzer/sourceMapper.js +220 -19
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +91 -19
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +17 -7
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeCacheUtils.js +17 -7
- package/dist/analyzer/typeCacheUtils.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.d.ts +8 -0
- package/dist/analyzer/typeDocStringUtils.js +101 -27
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +122 -89
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +71 -13
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +50 -8
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +17 -7
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -0
- package/dist/analyzer/typeUtils.js +9 -0
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeWalker.js +1 -1
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.js +19 -9
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/typeshedInfoProvider.js +17 -7
- package/dist/analyzer/typeshedInfoProvider.js.map +1 -1
- package/dist/backgroundAnalysisBase.js +17 -7
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.js +17 -7
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/common/chokidarFileWatcherProvider.js +17 -7
- package/dist/common/chokidarFileWatcherProvider.js.map +1 -1
- package/dist/common/configOptions.js +17 -7
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/console.js +17 -7
- package/dist/common/console.js.map +1 -1
- package/dist/common/docStringService.d.ts +2 -0
- package/dist/common/docStringService.js +5 -1
- package/dist/common/docStringService.js.map +1 -1
- package/dist/common/envVarUtils.js +17 -7
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/extensibility.d.ts +2 -0
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileBasedCancellationUtils.js +17 -7
- package/dist/common/fileBasedCancellationUtils.js.map +1 -1
- package/dist/common/fullAccessHost.d.ts +4 -2
- package/dist/common/fullAccessHost.js +69 -16
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/host.d.ts +33 -2
- package/dist/common/host.js +4 -1
- package/dist/common/host.js.map +1 -1
- package/dist/common/languageInfoUtils.js +12 -12
- package/dist/common/memUtils.js +18 -7
- package/dist/common/memUtils.js.map +1 -1
- package/dist/common/pathUtils.js +17 -7
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/positionUtils.js +19 -0
- package/dist/common/positionUtils.js.map +1 -1
- package/dist/common/processUtils.js +17 -7
- package/dist/common/processUtils.js.map +1 -1
- package/dist/common/realFileSystem.js +19 -19
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProvider.js +17 -7
- package/dist/common/serviceProvider.js.map +1 -1
- package/dist/common/streamUtils.d.ts +1 -1
- package/dist/common/textEditTracker.d.ts +1 -0
- package/dist/common/textEditTracker.js +31 -12
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/common/uri/fileUri.d.ts +1 -0
- package/dist/common/uri/fileUri.js +20 -0
- package/dist/common/uri/fileUri.js.map +1 -1
- package/dist/common/uri/memoization.js +5 -1
- package/dist/common/uri/memoization.js.map +1 -1
- package/dist/common/uri/uriMap.d.ts +4 -4
- package/dist/common/uri/uriMap.js +1 -0
- package/dist/common/uri/uriMap.js.map +1 -1
- package/dist/common/uri/uriUtils.d.ts +2 -0
- package/dist/common/uri/uriUtils.js +22 -0
- package/dist/common/uri/uriUtils.js.map +1 -1
- package/dist/common/workspaceEditUtils.d.ts +1 -0
- package/dist/common/workspaceEditUtils.js +10 -0
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.js +19 -4
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.js +17 -7
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +17 -7
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +11 -2
- package/dist/languageService/completionProvider.js +319 -65
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.d.ts +18 -0
- package/dist/languageService/completionProviderUtils.js +42 -0
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +1 -1
- package/dist/languageService/definitionProvider.js +69 -10
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentHighlightProvider.js +17 -7
- package/dist/languageService/documentHighlightProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +18 -0
- package/dist/languageService/documentSymbolCollector.js +102 -15
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +1 -1
- package/dist/languageService/hoverProvider.js +98 -23
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importStatementCandidates.d.ts +16 -0
- package/dist/languageService/importStatementCandidates.js +100 -0
- package/dist/languageService/importStatementCandidates.js.map +1 -0
- package/dist/languageService/referencesProvider.d.ts +16 -9
- package/dist/languageService/referencesProvider.js +205 -39
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.d.ts +7 -2
- package/dist/languageService/renameProvider.js +45 -17
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +54 -16
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +17 -7
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.d.ts +11 -0
- package/dist/languageService/tooltipUtils.js +67 -33
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.js +17 -7
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +8 -0
- package/dist/localization/localize.js +6 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +5 -0
- package/dist/parser/characters.js +17 -7
- package/dist/parser/characters.js.map +1 -1
- package/dist/parser/parseNodes.d.ts +4 -0
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -0
- package/dist/parser/parser.js +91 -38
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/stringTokenUtils.js +23 -7
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/parser/tokenizer.js +16 -15
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.d.ts +15 -14
- package/dist/parser/tokenizerTypes.js +22 -15
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/pyright.js +17 -7
- package/dist/pyright.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.js +13 -6
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/benchmarks/parserBenchmark.test.js +17 -7
- package/dist/tests/benchmarks/parserBenchmark.test.js.map +1 -1
- package/dist/tests/benchmarks/tokenizerBenchmark.test.js +17 -7
- package/dist/tests/benchmarks/tokenizerBenchmark.test.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +17 -7
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/checker.test.js +21 -7
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/collectionUtils.test.js +17 -7
- package/dist/tests/collectionUtils.test.js.map +1 -1
- package/dist/tests/common.test.js +17 -7
- package/dist/tests/common.test.js.map +1 -1
- package/dist/tests/completionProviderUtils.test.d.ts +1 -0
- package/dist/tests/completionProviderUtils.test.js +56 -0
- package/dist/tests/completionProviderUtils.test.js.map +1 -0
- package/dist/tests/completions.test.js +118 -9
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/config.test.js +69 -0
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/debug.test.js +17 -7
- package/dist/tests/debug.test.js.map +1 -1
- package/dist/tests/deferred.test.js +18 -8
- package/dist/tests/deferred.test.js.map +1 -1
- package/dist/tests/diagnosticOverrides.test.js +17 -7
- package/dist/tests/diagnosticOverrides.test.js.map +1 -1
- package/dist/tests/diagnostics.test.js +35 -0
- package/dist/tests/diagnostics.test.js.map +1 -1
- package/dist/tests/docStringReturnExtraction.test.d.ts +1 -0
- package/dist/tests/docStringReturnExtraction.test.js +125 -0
- package/dist/tests/docStringReturnExtraction.test.js.map +1 -0
- package/dist/tests/envVarUtils.test.js +17 -7
- package/dist/tests/envVarUtils.test.js.map +1 -1
- package/dist/tests/filesystem.test.js +17 -7
- package/dist/tests/filesystem.test.js.map +1 -1
- package/dist/tests/fourSlashParser.test.js +17 -7
- package/dist/tests/fourSlashParser.test.js.map +1 -1
- package/dist/tests/fourSlashRunner.test.js +17 -7
- package/dist/tests/fourSlashRunner.test.js.map +1 -1
- package/dist/tests/fourslash/completions.call.unpackedGenericTypedDict.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.call.unpackedGenericTypedDict.fourslash.js +35 -0
- package/dist/tests/fourslash/completions.call.unpackedGenericTypedDict.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.inherited.function.docFromStub.fourslash.js +1 -1
- package/dist/tests/fourslash/completions.inherited.function.docFromStub.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.keywords.expressionContext.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.keywords.expressionContext.fourslash.js +86 -0
- package/dist/tests/fourslash/completions.keywords.expressionContext.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.keywords.pythonVersion.fourslash.js +20 -0
- package/dist/tests/fourslash/completions.keywords.pythonVersion.fourslash.js.map +1 -1
- package/dist/tests/fourslash/diagnostics.missingModuleSource.compiledModule.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/diagnostics.missingModuleSource.compiledModule.fourslash.js +122 -0
- package/dist/tests/fourslash/diagnostics.missingModuleSource.compiledModule.fourslash.js.map +1 -0
- package/dist/tests/fourslash/diagnostics.missingModuleSource.nativeSubmodule.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/diagnostics.missingModuleSource.nativeSubmodule.fourslash.js +61 -0
- package/dist/tests/fourslash/diagnostics.missingModuleSource.nativeSubmodule.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.complicated.fourslash.js +1 -5
- package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -1
- package/dist/tests/fourslash/signature.posonly.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.posonly.fourslash.js +58 -0
- package/dist/tests/fourslash/signature.posonly.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/fourSlashTypes.js +17 -7
- package/dist/tests/harness/fourslash/fourSlashTypes.js.map +1 -1
- package/dist/tests/harness/fourslash/runner.js +17 -7
- package/dist/tests/harness/fourslash/runner.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +17 -7
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.Consts.js +17 -7
- package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +17 -7
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.js +17 -7
- package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js +17 -7
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js.map +1 -1
- package/dist/tests/harness/testAccessHost.d.ts +1 -1
- package/dist/tests/harness/testAccessHost.js +1 -1
- package/dist/tests/harness/testAccessHost.js.map +1 -1
- package/dist/tests/harness/testHost.js +17 -7
- package/dist/tests/harness/testHost.js.map +1 -1
- package/dist/tests/harness/utils.d.ts +4 -4
- package/dist/tests/harness/utils.js.map +1 -1
- package/dist/tests/harness/vfs/factory.js +17 -7
- package/dist/tests/harness/vfs/factory.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.js +19 -11
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/harness/vfs/pathValidation.js +17 -7
- package/dist/tests/harness/vfs/pathValidation.js.map +1 -1
- package/dist/tests/importResolver.test.js +137 -0
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +92 -0
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/languageServer.test.js +91 -0
- package/dist/tests/languageServer.test.js.map +1 -1
- package/dist/tests/localizer.test.js +17 -7
- package/dist/tests/localizer.test.js.map +1 -1
- package/dist/tests/logger.test.js +17 -7
- package/dist/tests/logger.test.js.map +1 -1
- package/dist/tests/lsp/languageServer.js +17 -7
- package/dist/tests/lsp/languageServer.js.map +1 -1
- package/dist/tests/lsp/languageServerTestUtils.d.ts +1 -5
- package/dist/tests/lsp/languageServerTestUtils.js +77 -22
- package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
- package/dist/tests/parser.test.js +264 -7
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/pathUtils.test.js +17 -7
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/positionUtils.test.js +26 -0
- package/dist/tests/positionUtils.test.js.map +1 -1
- package/dist/tests/pyrightFileSystem.test.js +25 -0
- package/dist/tests/pyrightFileSystem.test.js.map +1 -1
- package/dist/tests/realTempFile.test.js +17 -7
- package/dist/tests/realTempFile.test.js.map +1 -1
- package/dist/tests/signatureHelp.test.js +73 -0
- package/dist/tests/signatureHelp.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +17 -7
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +192 -0
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/stringUtils.test.js +17 -7
- package/dist/tests/stringUtils.test.js.map +1 -1
- package/dist/tests/symbolNameUtils.test.js +17 -7
- package/dist/tests/symbolNameUtils.test.js.map +1 -1
- package/dist/tests/testState.test.js +17 -7
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/testUtils.js +17 -7
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/textRange.test.js +17 -7
- package/dist/tests/textRange.test.js.map +1 -1
- package/dist/tests/tokenizer.test.js +17 -7
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +21 -7
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +23 -7
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +23 -7
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +45 -7
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +17 -7
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +17 -7
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +17 -7
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +40 -28
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +82 -7
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/tests/uri.test.js +17 -7
- package/dist/tests/uri.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +48 -7
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/tests/zipfs.test.js +17 -7
- package/dist/tests/zipfs.test.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +10 -10
- package/dist/tests/lsp/rspack.testserver.config.d.ts +0 -63
- package/dist/tests/lsp/rspack.testserver.config.js +0 -60
- package/dist/tests/lsp/rspack.testserver.config.js.map +0 -1
|
@@ -24,16 +24,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
24
24
|
}) : function(o, v) {
|
|
25
25
|
o["default"] = v;
|
|
26
26
|
});
|
|
27
|
-
var __importStar = (this && this.__importStar) || function (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
34
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
45
|
exports.CompletionMap = exports.CompletionProvider = exports.indexValueDetail = exports.autoImportDetail = void 0;
|
|
46
|
+
exports.hoistCompletionItemDataDefault = hoistCompletionItemDataDefault;
|
|
36
47
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
48
|
+
const vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
37
49
|
const AnalyzerNodeInfo = __importStar(require("../analyzer/analyzerNodeInfo"));
|
|
38
50
|
const declaration_1 = require("../analyzer/declaration");
|
|
39
51
|
const declarationUtils_1 = require("../analyzer/declarationUtils");
|
|
@@ -69,6 +81,7 @@ const tokenizer_1 = require("../parser/tokenizer");
|
|
|
69
81
|
const autoImporter_1 = require("./autoImporter");
|
|
70
82
|
const completionProviderUtils_1 = require("./completionProviderUtils");
|
|
71
83
|
const documentSymbolCollector_1 = require("./documentSymbolCollector");
|
|
84
|
+
const importStatementCandidates_1 = require("./importStatementCandidates");
|
|
72
85
|
const tooltipUtils_1 = require("./tooltipUtils");
|
|
73
86
|
var Keywords;
|
|
74
87
|
(function (Keywords) {
|
|
@@ -111,7 +124,11 @@ var Keywords;
|
|
|
111
124
|
];
|
|
112
125
|
const python3_5 = [...base, 'async', 'await'];
|
|
113
126
|
const python3_10 = [...python3_5, 'case', 'match'];
|
|
127
|
+
const python3_15 = [...python3_10, 'lazy'];
|
|
114
128
|
function forVersion(version) {
|
|
129
|
+
if (pythonVersion_1.PythonVersion.isGreaterOrEqualTo(version, pythonVersion_1.pythonVersion3_15)) {
|
|
130
|
+
return python3_15;
|
|
131
|
+
}
|
|
115
132
|
if (pythonVersion_1.PythonVersion.isGreaterOrEqualTo(version, pythonVersion_1.pythonVersion3_10)) {
|
|
116
133
|
return python3_10;
|
|
117
134
|
}
|
|
@@ -121,6 +138,45 @@ var Keywords;
|
|
|
121
138
|
return base;
|
|
122
139
|
}
|
|
123
140
|
Keywords.forVersion = forVersion;
|
|
141
|
+
// Keywords that can only begin a statement and can never begin an expression,
|
|
142
|
+
// so they are suppressed in the expression-only slots recognized here. (Some
|
|
143
|
+
// of these, like `from`, can still appear *within* an expression form such as
|
|
144
|
+
// `yield from <expr>`, but never as the start of one.) Keywords like `if`,
|
|
145
|
+
// `else`, `for`, `in`, `lambda`, `yield`, and `await` are intentionally
|
|
146
|
+
// excluded because they can appear inside expressions (ternaries,
|
|
147
|
+
// comprehensions, lambdas, etc.).
|
|
148
|
+
// Keep in sync with the counterpart in
|
|
149
|
+
// pylance-internal/src/languageService/asyncCompletionProvider.ts.
|
|
150
|
+
const statementOnlyKeywords = new Set([
|
|
151
|
+
'assert',
|
|
152
|
+
'break',
|
|
153
|
+
'case',
|
|
154
|
+
'class',
|
|
155
|
+
'continue',
|
|
156
|
+
'def',
|
|
157
|
+
'del',
|
|
158
|
+
'elif',
|
|
159
|
+
'except',
|
|
160
|
+
'finally',
|
|
161
|
+
'from',
|
|
162
|
+
'global',
|
|
163
|
+
'import',
|
|
164
|
+
'match',
|
|
165
|
+
'nonlocal',
|
|
166
|
+
'pass',
|
|
167
|
+
'raise',
|
|
168
|
+
'return',
|
|
169
|
+
'try',
|
|
170
|
+
'type',
|
|
171
|
+
'while',
|
|
172
|
+
'with',
|
|
173
|
+
]);
|
|
174
|
+
// Returns the version-appropriate keywords that are valid in an expression
|
|
175
|
+
// context (i.e. the full keyword set minus the statement-only keywords).
|
|
176
|
+
function expressionKeywordsForVersion(version) {
|
|
177
|
+
return forVersion(version).filter((keyword) => !statementOnlyKeywords.has(keyword));
|
|
178
|
+
}
|
|
179
|
+
Keywords.expressionKeywordsForVersion = expressionKeywordsForVersion;
|
|
124
180
|
})(Keywords || (Keywords = {}));
|
|
125
181
|
var SortCategory;
|
|
126
182
|
(function (SortCategory) {
|
|
@@ -144,16 +200,48 @@ var SortCategory;
|
|
|
144
200
|
SortCategory[SortCategory["Keyword"] = 7] = "Keyword";
|
|
145
201
|
// An enum member.
|
|
146
202
|
SortCategory[SortCategory["EnumMember"] = 8] = "EnumMember";
|
|
203
|
+
// A symbol declared directly on the object or class being accessed.
|
|
204
|
+
SortCategory[SortCategory["DeclaredSymbol"] = 9] = "DeclaredSymbol";
|
|
205
|
+
// A private symbol declared directly on the object or class being accessed.
|
|
206
|
+
SortCategory[SortCategory["DeclaredPrivateSymbol"] = 10] = "DeclaredPrivateSymbol";
|
|
147
207
|
// A normal symbol.
|
|
148
|
-
SortCategory[SortCategory["NormalSymbol"] =
|
|
208
|
+
SortCategory[SortCategory["NormalSymbol"] = 11] = "NormalSymbol";
|
|
149
209
|
// A symbol that starts with _ or __ (used only when there is
|
|
150
210
|
// no matching filter).
|
|
151
|
-
SortCategory[SortCategory["PrivateSymbol"] =
|
|
211
|
+
SortCategory[SortCategory["PrivateSymbol"] = 12] = "PrivateSymbol";
|
|
152
212
|
// A symbol with a dunder name (e.g. __init__).
|
|
153
|
-
SortCategory[SortCategory["DunderSymbol"] =
|
|
213
|
+
SortCategory[SortCategory["DunderSymbol"] = 13] = "DunderSymbol";
|
|
154
214
|
// An auto-import symbol.
|
|
155
|
-
SortCategory[SortCategory["AutoImport"] =
|
|
215
|
+
SortCategory[SortCategory["AutoImport"] = 14] = "AutoImport";
|
|
156
216
|
})(SortCategory || (SortCategory = {}));
|
|
217
|
+
// Publishes the shared completion item `data` fields (uri/position) once via
|
|
218
|
+
// `CompletionList.itemDefaults.data` and requests a shallow merge via `CompletionList.applyKind`,
|
|
219
|
+
// so each item only needs to carry its per-item data. Items are built without the shared fields in
|
|
220
|
+
// the first place (see `createCompletionItemData`), so there is nothing to strip here. The client
|
|
221
|
+
// reconstructs the full `data` (merging the defaults back in) before issuing a resolve request, so
|
|
222
|
+
// the resolve handler is unaffected.
|
|
223
|
+
//
|
|
224
|
+
// The caller must only invoke this when the client advertises both
|
|
225
|
+
// `completionList.itemDefaults` containing `data` and `completionList.applyKindSupport`.
|
|
226
|
+
//
|
|
227
|
+
// Note: `applyKind` only configures `data` (Merge); other itemDefaults (e.g. a future
|
|
228
|
+
// `commitCharacters` default) would fall back to the client default of `Replace` unless this
|
|
229
|
+
// object is extended. For data-less items (keywords, string literals) the shared `itemDefaults.data`
|
|
230
|
+
// still applies via the client merge, but they have nothing to resolve. The resolve dispatch
|
|
231
|
+
// short-circuits them by item kind so the merge doesn't drag them into a needless resolve
|
|
232
|
+
// round-trip: keywords are identified by `CompletionItemKind.Keyword`, and string literals by
|
|
233
|
+
// `CompletionItemKind.Constant` with no `symbolLabel` (data-bearing name completions always carry
|
|
234
|
+
// a `symbolLabel`). Named-parameter items (`Variable`, no `symbolLabel`) are not kind-short-circuited
|
|
235
|
+
// and may still reach resolve via the merge, but resolve is a no-op for them; the MRU is updated only
|
|
236
|
+
// when a completion is accepted.
|
|
237
|
+
function hoistCompletionItemDataDefault(list, fileUri, position) {
|
|
238
|
+
if (list.items.length === 0) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const sharedData = { uri: fileUri.toString(), position };
|
|
242
|
+
list.itemDefaults = { ...list.itemDefaults, data: (0, lspUtils_1.toLSPAny)(sharedData) };
|
|
243
|
+
list.applyKind = { ...list.applyKind, data: vscode_languageserver_types_1.ApplyKind.Merge };
|
|
244
|
+
}
|
|
157
245
|
exports.autoImportDetail = localize_1.Localizer.Completion.autoImportDetail();
|
|
158
246
|
exports.indexValueDetail = localize_1.Localizer.Completion.indexValueDetail();
|
|
159
247
|
// We'll use a somewhat-arbitrary cutoff value here to determine
|
|
@@ -180,24 +268,32 @@ class CompletionProvider {
|
|
|
180
268
|
return null;
|
|
181
269
|
}
|
|
182
270
|
const completionMap = this._getCompletions();
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
271
|
+
const completionList = vscode_languageserver_1.CompletionList.create(completionMap?.toArray());
|
|
272
|
+
if (this.options.completionItemDataDefault) {
|
|
273
|
+
hoistCompletionItemDataDefault(completionList, this.fileUri, this.position);
|
|
274
|
+
}
|
|
275
|
+
return completionList;
|
|
276
|
+
}
|
|
277
|
+
// Single source of truth for which completion item kinds participate in the MRU cache.
|
|
278
|
+
// Keyword items and data-less string-literal `Constant` items (no `symbolLabel`) carry no
|
|
279
|
+
// server-side identity: they are never resolved and were never recorded in the MRU. Every other
|
|
280
|
+
// kind can feed the MRU when accepted. Both the resolve short-circuit (languageService.ts) and the
|
|
281
|
+
// accept-command attach gate (asynchronousFeatures.ts) key off this predicate so MRU membership is
|
|
282
|
+
// defined in one place instead of as two hand-synced inverse checks.
|
|
283
|
+
static feedsMru(kind, hasSymbolLabel) {
|
|
284
|
+
return kind !== vscode_languageserver_1.CompletionItemKind.Keyword && !(kind === vscode_languageserver_1.CompletionItemKind.Constant && !hasSymbolLabel);
|
|
285
|
+
}
|
|
286
|
+
// Records an accepted completion in the MRU cache so we can better predict entries.
|
|
287
|
+
// This is called when a completion is actually committed (via the accept command), not when
|
|
288
|
+
// it is merely highlighted/previewed. Recording on highlight would let an inline preview that
|
|
289
|
+
// resolves on every keystroke reorder the list and make results oscillate.
|
|
290
|
+
static recordCompletionAccepted(label, autoImportText) {
|
|
196
291
|
const curIndex = CompletionProvider._mostRecentCompletions.findIndex((item) => item.label === label && item.autoImportText === autoImportText);
|
|
197
292
|
if (curIndex > 0) {
|
|
198
293
|
// If there's an existing entry with the same name that's not at the
|
|
199
|
-
// beginning of the array, remove it.
|
|
200
|
-
|
|
294
|
+
// beginning of the array, remove it in place. (Array.splice mutates the
|
|
295
|
+
// array and returns the removed elements, so it must not be reassigned.)
|
|
296
|
+
CompletionProvider._mostRecentCompletions.splice(curIndex, 1);
|
|
201
297
|
}
|
|
202
298
|
if (curIndex !== 0) {
|
|
203
299
|
// Add to the start of the array.
|
|
@@ -207,6 +303,13 @@ class CompletionProvider {
|
|
|
207
303
|
// Prevent the MRU list from growing indefinitely.
|
|
208
304
|
CompletionProvider._mostRecentCompletions.pop();
|
|
209
305
|
}
|
|
306
|
+
}
|
|
307
|
+
// When the user highlights/previews a completion, this callback is invoked so we can fill in
|
|
308
|
+
// additional details (documentation, auto-import edits). It must NOT mutate the MRU cache; MRU
|
|
309
|
+
// updates happen only when a completion is accepted (see recordCompletionAccepted).
|
|
310
|
+
resolveCompletionItem(completionItem) {
|
|
311
|
+
(0, cancellationUtils_1.throwIfCancellationRequested)(this.cancellationToken);
|
|
312
|
+
const completionItemData = this.getCompletionItemData(completionItem);
|
|
210
313
|
if (!completionItemData.symbolLabel) {
|
|
211
314
|
return;
|
|
212
315
|
}
|
|
@@ -264,6 +367,17 @@ class CompletionProvider {
|
|
|
264
367
|
getCompletionItemData(item) {
|
|
265
368
|
return (0, lspUtils_1.fromLSPAny)(item.data);
|
|
266
369
|
}
|
|
370
|
+
// Builds the `data` payload for a completion item. When the client supports `itemDefaults.data`
|
|
371
|
+
// (completionItemDataDefault), the shared `uri`/`position` live once in
|
|
372
|
+
// `CompletionList.itemDefaults.data` (see hoistCompletionItemDataDefault), so we never write them
|
|
373
|
+
// per item in the first place (rather than writing then stripping them); an item left with no
|
|
374
|
+
// per-item fields carries no `data` at all. Otherwise we inline `uri`/`position` on each item.
|
|
375
|
+
createCompletionItemData(data) {
|
|
376
|
+
if (!this.options.completionItemDataDefault) {
|
|
377
|
+
return (0, lspUtils_1.toLSPAny)({ uri: this.fileUri.toString(), position: this.position, ...data });
|
|
378
|
+
}
|
|
379
|
+
return Object.keys(data).length > 0 ? (0, lspUtils_1.toLSPAny)(data) : undefined;
|
|
380
|
+
}
|
|
267
381
|
addAdditionalExpressionCompletions(parseNode, priorWord, completionMap) {
|
|
268
382
|
// Default implementation is a no-op.
|
|
269
383
|
// Subclasses can override to inject additional completion items that are not produced by the
|
|
@@ -406,6 +520,13 @@ class CompletionProvider {
|
|
|
406
520
|
};
|
|
407
521
|
return vscode_languageserver_1.TextEdit.replace(range, text);
|
|
408
522
|
}
|
|
523
|
+
createReplaceEditWithOverlap(priorWord, overlap, text) {
|
|
524
|
+
const range = {
|
|
525
|
+
start: { line: this.position.line, character: this.position.character - priorWord.length },
|
|
526
|
+
end: { line: this.position.line, character: this.position.character + (overlap?.consumedChars ?? 0) },
|
|
527
|
+
};
|
|
528
|
+
return vscode_languageserver_1.TextEdit.replace(range, text);
|
|
529
|
+
}
|
|
409
530
|
shouldProcessDeclaration(declaration) {
|
|
410
531
|
// By default, we allow all symbol/decl to be included in the completion.
|
|
411
532
|
return true;
|
|
@@ -476,6 +597,7 @@ class CompletionProvider {
|
|
|
476
597
|
}
|
|
477
598
|
this.addNameToCompletions(detail.autoImportAlias ?? name, itemKind, priorWord, completionMap, {
|
|
478
599
|
autoImportText,
|
|
600
|
+
declaredOnBoundObjectOrClass: detail.declaredOnBoundObjectOrClass,
|
|
479
601
|
extraCommitChars: detail.extraCommitChars,
|
|
480
602
|
funcParensDisabled: detail.funcParensDisabled,
|
|
481
603
|
edits: detail.edits,
|
|
@@ -487,6 +609,7 @@ class CompletionProvider {
|
|
|
487
609
|
if (synthesizedType) {
|
|
488
610
|
const itemKind = this._convertTypeToItemKind(synthesizedType);
|
|
489
611
|
this.addNameToCompletions(name, itemKind, priorWord, completionMap, {
|
|
612
|
+
declaredOnBoundObjectOrClass: detail.declaredOnBoundObjectOrClass,
|
|
490
613
|
extraCommitChars: detail.extraCommitChars,
|
|
491
614
|
funcParensDisabled: detail.funcParensDisabled,
|
|
492
615
|
edits: detail.edits,
|
|
@@ -494,7 +617,7 @@ class CompletionProvider {
|
|
|
494
617
|
}
|
|
495
618
|
}
|
|
496
619
|
}
|
|
497
|
-
getMemberAccessCompletions(leftExprNode, priorWord) {
|
|
620
|
+
getMemberAccessCompletions(leftExprNode, priorWord, preserveEnumMembers = false) {
|
|
498
621
|
const symbolTable = new Map();
|
|
499
622
|
const completionMap = new CompletionMap();
|
|
500
623
|
let leftType = this.evaluator.getType(leftExprNode);
|
|
@@ -509,14 +632,26 @@ class CompletionProvider {
|
|
|
509
632
|
}
|
|
510
633
|
(0, typeUtils_1.doForEachSubtype)(leftType, (subtype) => {
|
|
511
634
|
subtype = this.evaluator.makeTopLevelTypeVarsConcrete(subtype);
|
|
635
|
+
let resolvedClassSubtype;
|
|
512
636
|
if ((0, types_1.isClass)(subtype)) {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
637
|
+
if (preserveEnumMembers && types_1.ClassType.isEnumClass(subtype) && types_1.TypeBase.isInstance(subtype)) {
|
|
638
|
+
// Preserve enum members by switching back to the class view before member enumeration.
|
|
639
|
+
resolvedClassSubtype = types_1.ClassType.cloneAsInstantiable(subtype);
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
resolvedClassSubtype = subtype;
|
|
643
|
+
}
|
|
644
|
+
const instance = types_1.TypeBase.isInstance(resolvedClassSubtype);
|
|
645
|
+
(0, typeUtils_1.getMembersForClass)(resolvedClassSubtype, symbolTable, instance);
|
|
646
|
+
if (types_1.ClassType.isEnumClass(resolvedClassSubtype) && instance && !preserveEnumMembers) {
|
|
516
647
|
// Don't show enum member out of another enum member
|
|
517
|
-
// ex) Enum.Member. <= shouldn't show `Member` again.
|
|
648
|
+
// ex) Enum.Member. <= shouldn't show `Member` again. This pruning stays separate
|
|
649
|
+
// from the clone above because the clone only changes which members are enumerated.
|
|
650
|
+
// Note: when preserveEnumMembers=true, the cloneAsInstantiable above already makes
|
|
651
|
+
// instance=false, so this block is independently unreachable. The explicit
|
|
652
|
+
// !preserveEnumMembers guard is defense-in-depth for clarity.
|
|
518
653
|
for (const name of symbolTable.keys()) {
|
|
519
|
-
if (this._isEnumMember(
|
|
654
|
+
if (this._isEnumMember(resolvedClassSubtype, name)) {
|
|
520
655
|
symbolTable.delete(name);
|
|
521
656
|
}
|
|
522
657
|
}
|
|
@@ -538,7 +673,7 @@ class CompletionProvider {
|
|
|
538
673
|
}
|
|
539
674
|
}
|
|
540
675
|
this._addSymbolsForSymbolTable(symbolTable, () => true, priorWord, leftExprNode,
|
|
541
|
-
/* isInImport */ false,
|
|
676
|
+
/* isInImport */ false, resolvedClassSubtype, completionMap);
|
|
542
677
|
});
|
|
543
678
|
return completionMap;
|
|
544
679
|
}
|
|
@@ -608,17 +743,13 @@ class CompletionProvider {
|
|
|
608
743
|
if (detail?.extraCommitChars) {
|
|
609
744
|
this.addExtraCommitChar(completionItem);
|
|
610
745
|
}
|
|
611
|
-
const completionItemData = {
|
|
612
|
-
uri: this.fileUri.toString(),
|
|
613
|
-
position: this.position,
|
|
614
|
-
};
|
|
746
|
+
const completionItemData = {};
|
|
615
747
|
if (detail?.funcParensDisabled || !this.options.snippet) {
|
|
616
748
|
completionItemData.funcParensDisabled = true;
|
|
617
749
|
}
|
|
618
750
|
if (detail?.moduleUri) {
|
|
619
751
|
completionItemData.moduleUri = detail.moduleUri.toString();
|
|
620
752
|
}
|
|
621
|
-
completionItem.data = (0, lspUtils_1.toLSPAny)(completionItemData);
|
|
622
753
|
if (detail?.sortText || detail?.itemDetail) {
|
|
623
754
|
completionItem.sortText = detail.sortText;
|
|
624
755
|
completionItem.detail = detail.itemDetail;
|
|
@@ -644,7 +775,10 @@ class CompletionProvider {
|
|
|
644
775
|
// Distinguish between normal and private symbols only if there is
|
|
645
776
|
// currently no filter text. Once we get a single character to filter
|
|
646
777
|
// upon, we'll no longer differentiate.
|
|
647
|
-
completionItem.sortText = this._makeSortText(SortCategory.PrivateSymbol, name);
|
|
778
|
+
completionItem.sortText = this._makeSortText(detail?.declaredOnBoundObjectOrClass ? SortCategory.DeclaredPrivateSymbol : SortCategory.PrivateSymbol, name);
|
|
779
|
+
}
|
|
780
|
+
else if (filter === '' && detail?.declaredOnBoundObjectOrClass) {
|
|
781
|
+
completionItem.sortText = this._makeSortText(SortCategory.DeclaredSymbol, name);
|
|
648
782
|
}
|
|
649
783
|
else {
|
|
650
784
|
completionItem.sortText = this._makeSortText(SortCategory.NormalSymbol, name);
|
|
@@ -720,6 +854,7 @@ class CompletionProvider {
|
|
|
720
854
|
}
|
|
721
855
|
}
|
|
722
856
|
}
|
|
857
|
+
completionItem.data = this.createCompletionItemData(completionItemData);
|
|
723
858
|
completionMap.set(completionItem);
|
|
724
859
|
}
|
|
725
860
|
getAutoImportText(importName, importFrom, importAlias) {
|
|
@@ -1004,6 +1139,12 @@ class CompletionProvider {
|
|
|
1004
1139
|
if (curNode.parent.nodeType === 35 /* ParseNodeType.MemberAccess */ && curNode === curNode.parent.d.member) {
|
|
1005
1140
|
return this.getMemberAccessCompletions(curNode.parent.d.leftExpr, priorWord);
|
|
1006
1141
|
}
|
|
1142
|
+
if (this._isRecoveredPatternMemberAccessName(curNode, priorWord, priorText)) {
|
|
1143
|
+
// Pass curNode (the Name node) rather than a MemberAccess leftExpr: the type evaluator
|
|
1144
|
+
// resolves the Name to the same class type, and no MemberAccess parent exists in this
|
|
1145
|
+
// recovered-pattern context.
|
|
1146
|
+
return this.getMemberAccessCompletions(curNode, priorWord, /* preserveEnumMembers */ true);
|
|
1147
|
+
}
|
|
1007
1148
|
if (curNode.parent.nodeType === 28 /* ParseNodeType.Except */ && curNode === curNode.parent.d.name) {
|
|
1008
1149
|
return undefined;
|
|
1009
1150
|
}
|
|
@@ -1059,6 +1200,17 @@ class CompletionProvider {
|
|
|
1059
1200
|
}
|
|
1060
1201
|
return false;
|
|
1061
1202
|
}
|
|
1203
|
+
_isRecoveredPatternMemberAccessName(curNode, priorWord, priorText) {
|
|
1204
|
+
if (priorWord.length > 0 || !priorText.endsWith('.')) {
|
|
1205
|
+
return false;
|
|
1206
|
+
}
|
|
1207
|
+
// Parser recovery keeps `case Direction.` as a `PatternCapture > Name`, so detect the
|
|
1208
|
+
// trailing-dot text shape directly instead of waiting for a `MemberAccess` node.
|
|
1209
|
+
if (curNode.parent?.nodeType !== 69 /* ParseNodeType.PatternCapture */) {
|
|
1210
|
+
return false;
|
|
1211
|
+
}
|
|
1212
|
+
return !!ParseTreeUtils.getFirstAncestorOrSelfOfKind(curNode.parent, 64 /* ParseNodeType.Case */);
|
|
1213
|
+
}
|
|
1062
1214
|
_isWithinComment(offset) {
|
|
1063
1215
|
const token = getTokenAfter(offset, this.parseResults.tokenizerOutput.tokens);
|
|
1064
1216
|
if (!token) {
|
|
@@ -1161,6 +1313,17 @@ class CompletionProvider {
|
|
|
1161
1313
|
case 3 /* ErrorExpressionCategory.MissingIndexOrSlice */: {
|
|
1162
1314
|
let completionResults = this._getLiteralCompletions(node, offset, priorWord, priorText, postText);
|
|
1163
1315
|
if (!completionResults) {
|
|
1316
|
+
if (node.d.category === 3 /* ErrorExpressionCategory.MissingIndexOrSlice */ &&
|
|
1317
|
+
this.options.triggerCharacter === '[' &&
|
|
1318
|
+
!this._isSubscriptInTypeContext(node)) {
|
|
1319
|
+
// When `[` auto-triggers a subscript and there are no literal key
|
|
1320
|
+
// suggestions, return undefined so the caller produces an empty
|
|
1321
|
+
// CompletionList instead of noisy generic expression completions.
|
|
1322
|
+
// Skip this suppression inside type-like contexts (annotations,
|
|
1323
|
+
// class bases, type aliases) where generic subscripts are the
|
|
1324
|
+
// expected workflow.
|
|
1325
|
+
return undefined;
|
|
1326
|
+
}
|
|
1164
1327
|
completionResults = this._getExpressionCompletions(node, priorWord, priorText, postText);
|
|
1165
1328
|
}
|
|
1166
1329
|
return completionResults;
|
|
@@ -1419,6 +1582,50 @@ class CompletionProvider {
|
|
|
1419
1582
|
// For now, use the same logic for expressions and statements.
|
|
1420
1583
|
return this._getExpressionCompletions(parseNode, priorWord, priorText, postText);
|
|
1421
1584
|
}
|
|
1585
|
+
// Returns true when `node` occupies a slot that can only contain an
|
|
1586
|
+
// expression (never the start of a statement), so statement-only keywords
|
|
1587
|
+
// must be suppressed. Biased toward a superset: only well-understood
|
|
1588
|
+
// expression slots return true; anything uncertain returns false so the
|
|
1589
|
+
// full keyword set is offered (it's better to leak a wrong keyword than to
|
|
1590
|
+
// drop a valid one). Keep in sync with the counterpart in
|
|
1591
|
+
// pylance-internal/src/languageService/asyncCompletionProvider.ts.
|
|
1592
|
+
_isExpressionOnlySlot(node) {
|
|
1593
|
+
const parent = node.parent;
|
|
1594
|
+
if (!parent) {
|
|
1595
|
+
return false;
|
|
1596
|
+
}
|
|
1597
|
+
switch (parent.nodeType) {
|
|
1598
|
+
case 29 /* ParseNodeType.For */:
|
|
1599
|
+
// The iterable of `for target in <iterable>` (but not the target).
|
|
1600
|
+
return parent.d.iterableExpr === node;
|
|
1601
|
+
case 12 /* ParseNodeType.ComprehensionFor */:
|
|
1602
|
+
// The iterable of a comprehension `... for target in <iterable>`.
|
|
1603
|
+
return parent.d.iterableExpr === node;
|
|
1604
|
+
case 3 /* ParseNodeType.Assignment */:
|
|
1605
|
+
// The right-hand side of `target = <value>` (but not the target).
|
|
1606
|
+
return parent.d.rightExpr === node;
|
|
1607
|
+
case 4 /* ParseNodeType.AssignmentExpression */:
|
|
1608
|
+
// The right-hand side of a walrus `name := <value>`.
|
|
1609
|
+
return parent.d.rightExpr === node;
|
|
1610
|
+
case 1 /* ParseNodeType.Argument */:
|
|
1611
|
+
// Any `ArgumentNode` slot: call arguments, subscript index items,
|
|
1612
|
+
// class bases, and decorator arguments. A statement-only keyword
|
|
1613
|
+
// is never valid in any of these, so suppressing it is always safe.
|
|
1614
|
+
return true;
|
|
1615
|
+
case 44 /* ParseNodeType.Return */:
|
|
1616
|
+
// The value of `return <expr>`.
|
|
1617
|
+
return parent.d.expr === node;
|
|
1618
|
+
case 57 /* ParseNodeType.While */:
|
|
1619
|
+
// The condition of `while <expr>:`.
|
|
1620
|
+
return parent.d.testExpr === node;
|
|
1621
|
+
case 22 /* ParseNodeType.If */:
|
|
1622
|
+
// The condition of `if <expr>:` / `elif <expr>:` (elif is a
|
|
1623
|
+
// nested `IfNode`).
|
|
1624
|
+
return parent.d.testExpr === node;
|
|
1625
|
+
default:
|
|
1626
|
+
return false;
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1422
1629
|
_getExpressionCompletions(parseNode, priorWord, priorText, postText) {
|
|
1423
1630
|
const isIndexArgument = this._isIndexArgument(parseNode);
|
|
1424
1631
|
// If the user typed a "." as part of a number, don't present
|
|
@@ -1447,8 +1654,13 @@ class CompletionProvider {
|
|
|
1447
1654
|
// Add symbols that are in scope.
|
|
1448
1655
|
this._addSymbols(parseNode, priorWord, completionMap);
|
|
1449
1656
|
this.addAdditionalExpressionCompletions(parseNode, priorWord, completionMap);
|
|
1450
|
-
// Add keywords.
|
|
1451
|
-
|
|
1657
|
+
// Add keywords. In slots that can only contain an expression, suppress
|
|
1658
|
+
// keywords that are only valid at the start of a statement (e.g. don't
|
|
1659
|
+
// offer `raise` in the iterable of a `for ... in`).
|
|
1660
|
+
const keywords = this._isExpressionOnlySlot(parseNode)
|
|
1661
|
+
? Keywords.expressionKeywordsForVersion(this.execEnv.pythonVersion)
|
|
1662
|
+
: Keywords.forVersion(this.execEnv.pythonVersion);
|
|
1663
|
+
this._findMatchingKeywords(keywords, priorWord).map((keyword) => {
|
|
1452
1664
|
if (completionMap.has(keyword)) {
|
|
1453
1665
|
return;
|
|
1454
1666
|
}
|
|
@@ -1490,7 +1702,7 @@ class CompletionProvider {
|
|
|
1490
1702
|
const callNameEnd = (0, positionUtils_1.convertOffsetToPosition)(signatureInfo.callNode.d.leftExpr.start + signatureInfo.callNode.d.leftExpr.length, this.parseResults.tokenizerOutput.lines);
|
|
1491
1703
|
if ((0, textRange_1.comparePositions)(this.position, callNameEnd) > 0) {
|
|
1492
1704
|
if (!atArgument) {
|
|
1493
|
-
this._addNamedParameters(signatureInfo, priorWord, completionMap);
|
|
1705
|
+
this._addNamedParameters(signatureInfo, priorWord, postText, completionMap);
|
|
1494
1706
|
}
|
|
1495
1707
|
this._addLiteralValuesForArgument(signatureInfo, priorWord, priorText, postText, completionMap);
|
|
1496
1708
|
}
|
|
@@ -1671,6 +1883,42 @@ class CompletionProvider {
|
|
|
1671
1883
|
}
|
|
1672
1884
|
return Array.from(keys);
|
|
1673
1885
|
}
|
|
1886
|
+
_isSubscriptInTypeContext(node) {
|
|
1887
|
+
// Standard type annotation contexts: TypeAnnotation, Parameter annotation, return annotation.
|
|
1888
|
+
if (ParseTreeUtils.isWithinTypeAnnotation(node, /* requireQuotedAnnotation */ false)) {
|
|
1889
|
+
return true;
|
|
1890
|
+
}
|
|
1891
|
+
// PEP 695 type alias: `type MyAlias = list[...]`
|
|
1892
|
+
if (ParseTreeUtils.getParentNodeOfType(node, 77 /* ParseNodeType.TypeAlias */)) {
|
|
1893
|
+
return true;
|
|
1894
|
+
}
|
|
1895
|
+
// Class bases: `class Foo(list[...])` or `class Foo(Generic[...])`
|
|
1896
|
+
let curNode = node.parent;
|
|
1897
|
+
while (curNode) {
|
|
1898
|
+
if (curNode.nodeType === 1 /* ParseNodeType.Argument */ && curNode.parent?.nodeType === 10 /* ParseNodeType.Class */) {
|
|
1899
|
+
return true;
|
|
1900
|
+
}
|
|
1901
|
+
if (curNode.nodeType === 50 /* ParseNodeType.Suite */ ||
|
|
1902
|
+
curNode.nodeType === 31 /* ParseNodeType.Function */ ||
|
|
1903
|
+
curNode.nodeType === 33 /* ParseNodeType.Lambda */) {
|
|
1904
|
+
break;
|
|
1905
|
+
}
|
|
1906
|
+
curNode = curNode.parent;
|
|
1907
|
+
}
|
|
1908
|
+
// Old-style TypeAlias assignment: `MyAlias: TypeAlias = list[...]`
|
|
1909
|
+
const assignmentNode = ParseTreeUtils.getParentNodeOfType(node, 3 /* ParseNodeType.Assignment */);
|
|
1910
|
+
if (assignmentNode && assignmentNode.nodeType === 3 /* ParseNodeType.Assignment */) {
|
|
1911
|
+
const leftExpr = assignmentNode.d.leftExpr;
|
|
1912
|
+
if (leftExpr.nodeType === 54 /* ParseNodeType.TypeAnnotation */) {
|
|
1913
|
+
const annotation = leftExpr.d.annotation;
|
|
1914
|
+
if ((annotation.nodeType === 38 /* ParseNodeType.Name */ && annotation.d.value === 'TypeAlias') ||
|
|
1915
|
+
(annotation.nodeType === 35 /* ParseNodeType.MemberAccess */ && annotation.d.member.d.value === 'TypeAlias')) {
|
|
1916
|
+
return true;
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
return false;
|
|
1921
|
+
}
|
|
1674
1922
|
_getLiteralCompletions(parseNode, offset, priorWord, priorText, postText) {
|
|
1675
1923
|
if (this.options.triggerCharacter === '"' || this.options.triggerCharacter === "'") {
|
|
1676
1924
|
if (parseNode.start !== offset - 1) {
|
|
@@ -2094,11 +2342,13 @@ class CompletionProvider {
|
|
|
2094
2342
|
rangeStartCol -= quoteInfo.priorWord.length;
|
|
2095
2343
|
}
|
|
2096
2344
|
// If the text after the insertion point is the closing quote,
|
|
2097
|
-
//
|
|
2345
|
+
// extend the replacement range so we don't end up with a duplicated
|
|
2346
|
+
// quote after the completion is applied.
|
|
2098
2347
|
let rangeEndCol = this.position.character;
|
|
2099
2348
|
if (postText !== undefined) {
|
|
2100
|
-
|
|
2101
|
-
|
|
2349
|
+
const overlap = (0, completionProviderUtils_1.detectTrailingOverlap)(quoteInfo.quoteCharacter, postText, 'adjacent');
|
|
2350
|
+
if (overlap) {
|
|
2351
|
+
rangeEndCol += overlap.consumedChars;
|
|
2102
2352
|
}
|
|
2103
2353
|
}
|
|
2104
2354
|
const range = {
|
|
@@ -2116,21 +2366,18 @@ class CompletionProvider {
|
|
|
2116
2366
|
}
|
|
2117
2367
|
// Access the imported module information, which is hanging
|
|
2118
2368
|
// off the ImportFromNode.
|
|
2119
|
-
const
|
|
2369
|
+
const importFromTarget = (0, importStatementCandidates_1.getImportFromTarget)(this.program, importFromNode);
|
|
2370
|
+
const importInfo = importFromTarget.importInfo;
|
|
2120
2371
|
if (!importInfo) {
|
|
2121
2372
|
return undefined;
|
|
2122
2373
|
}
|
|
2123
2374
|
const completionMap = new CompletionMap();
|
|
2124
|
-
|
|
2125
|
-
? importInfo.resolvedUris[importInfo.resolvedUris.length - 1]
|
|
2126
|
-
: uri_1.Uri.empty();
|
|
2127
|
-
const parseResults = this.program.getParseResults(resolvedPath);
|
|
2128
|
-
if (!parseResults) {
|
|
2375
|
+
if (!importFromTarget.hasParseResults) {
|
|
2129
2376
|
// Add the implicit imports.
|
|
2130
2377
|
this._addImplicitImportsToCompletion(importInfo, importFromNode, priorWord, completionMap);
|
|
2131
2378
|
return completionMap;
|
|
2132
2379
|
}
|
|
2133
|
-
const symbolTable =
|
|
2380
|
+
const symbolTable = importFromTarget.symbolTable;
|
|
2134
2381
|
if (!symbolTable) {
|
|
2135
2382
|
return completionMap;
|
|
2136
2383
|
}
|
|
@@ -2168,7 +2415,7 @@ class CompletionProvider {
|
|
|
2168
2415
|
}
|
|
2169
2416
|
});
|
|
2170
2417
|
}
|
|
2171
|
-
_addNamedParameters(signatureInfo, priorWord, completionMap) {
|
|
2418
|
+
_addNamedParameters(signatureInfo, priorWord, postText, completionMap) {
|
|
2172
2419
|
const argNameSet = new Set();
|
|
2173
2420
|
signatureInfo.signatures.forEach((signature) => {
|
|
2174
2421
|
this._addNamedParametersToMap(signature.type, argNameSet);
|
|
@@ -2195,13 +2442,16 @@ class CompletionProvider {
|
|
|
2195
2442
|
}
|
|
2196
2443
|
const completionItem = vscode_languageserver_1.CompletionItem.create(label);
|
|
2197
2444
|
completionItem.kind = vscode_languageserver_1.CompletionItemKind.Variable;
|
|
2198
|
-
|
|
2199
|
-
uri: this.fileUri.toString(),
|
|
2200
|
-
position: this.position,
|
|
2201
|
-
};
|
|
2202
|
-
completionItem.data = (0, lspUtils_1.toLSPAny)(completionItemData);
|
|
2445
|
+
completionItem.data = this.createCompletionItemData({});
|
|
2203
2446
|
completionItem.sortText = this._makeSortText(SortCategory.NamedParameter, argName);
|
|
2204
2447
|
completionItem.filterText = argName;
|
|
2448
|
+
// If the text immediately after the cursor already starts with
|
|
2449
|
+
// `=`, extend the replacement range so we don't end up with
|
|
2450
|
+
// `argName==` after the completion is applied (pylance-release#4808).
|
|
2451
|
+
const overlap = (0, completionProviderUtils_1.detectTrailingOverlap)('=', postText, 'adjacent');
|
|
2452
|
+
if (overlap) {
|
|
2453
|
+
completionItem.textEdit = this.createReplaceEditWithOverlap(priorWord, overlap, label);
|
|
2454
|
+
}
|
|
2205
2455
|
completionMap.set(completionItem);
|
|
2206
2456
|
}
|
|
2207
2457
|
});
|
|
@@ -2260,6 +2510,12 @@ class CompletionProvider {
|
|
|
2260
2510
|
_addSymbolsForSymbolTable(symbolTable, includeSymbolCallback, priorWord, node, isInImport, boundObjectOrClass, completionMap) {
|
|
2261
2511
|
const insideTypeAnnotation = ParseTreeUtils.isWithinAnnotationComment(node) ||
|
|
2262
2512
|
ParseTreeUtils.isWithinTypeAnnotation(node, /* requireQuotedAnnotation */ false);
|
|
2513
|
+
// `boundSymbolTable` holds only the fields declared directly on the leaf `boundObjectOrClass`,
|
|
2514
|
+
// whereas `symbolTable` is the merged-MRO table that also includes inherited members. The
|
|
2515
|
+
// declared-vs-inherited check below relies on this distinction, so callers must keep passing the
|
|
2516
|
+
// leaf type here even if they iterate per-MRO-class; otherwise inherited members would be
|
|
2517
|
+
// mis-bucketed as directly declared.
|
|
2518
|
+
const boundSymbolTable = boundObjectOrClass ? types_1.ClassType.getSymbolTable(boundObjectOrClass) : undefined;
|
|
2263
2519
|
symbolTable.forEach((symbol, name) => {
|
|
2264
2520
|
// If there are no declarations or the symbol is not
|
|
2265
2521
|
// exported from this scope, don't include it in the
|
|
@@ -2272,8 +2528,10 @@ class CompletionProvider {
|
|
|
2272
2528
|
// Skip func parens for classes when not a direct assignment or an argument (passed as a value)
|
|
2273
2529
|
const skipForClass = !this._shouldShowAutoParensForClass(symbol, node);
|
|
2274
2530
|
const skipForDecorator = node.parent?.nodeType === 16 /* ParseNodeType.Decorator */;
|
|
2531
|
+
const declaredOnBoundObjectOrClass = boundSymbolTable?.has(name);
|
|
2275
2532
|
this.addSymbol(name, symbol, priorWord, completionMap, {
|
|
2276
2533
|
boundObjectOrClass,
|
|
2534
|
+
declaredOnBoundObjectOrClass,
|
|
2277
2535
|
funcParensDisabled: isInImport || insideTypeAnnotation || skipForClass || skipForDecorator,
|
|
2278
2536
|
extraCommitChars: !isInImport && !!priorWord,
|
|
2279
2537
|
});
|
|
@@ -2312,6 +2570,8 @@ class CompletionProvider {
|
|
|
2312
2570
|
sortCategory = SortCategory.RecentImportModuleName;
|
|
2313
2571
|
}
|
|
2314
2572
|
else if (sortCategory === SortCategory.Keyword ||
|
|
2573
|
+
sortCategory === SortCategory.DeclaredSymbol ||
|
|
2574
|
+
sortCategory === SortCategory.DeclaredPrivateSymbol ||
|
|
2315
2575
|
sortCategory === SortCategory.NormalSymbol ||
|
|
2316
2576
|
sortCategory === SortCategory.PrivateSymbol ||
|
|
2317
2577
|
sortCategory === SortCategory.DunderSymbol) {
|
|
@@ -2394,13 +2654,7 @@ class CompletionProvider {
|
|
|
2394
2654
|
}
|
|
2395
2655
|
}
|
|
2396
2656
|
_getImportModuleCompletions(node) {
|
|
2397
|
-
const
|
|
2398
|
-
leadingDots: node.d.leadingDots,
|
|
2399
|
-
hasTrailingDot: node.d.hasTrailingDot || false,
|
|
2400
|
-
nameParts: node.d.nameParts.map((part) => part.d.value),
|
|
2401
|
-
importedSymbols: new Set(),
|
|
2402
|
-
};
|
|
2403
|
-
const completions = this.importResolver.getCompletionSuggestions(this.fileUri, this.execEnv, moduleDescriptor);
|
|
2657
|
+
const completions = (0, importStatementCandidates_1.getModuleNameCompletionSuggestions)(this.importResolver, this.fileUri, this.execEnv, node);
|
|
2404
2658
|
const completionMap = new CompletionMap();
|
|
2405
2659
|
// If we're in the middle of a "from X import Y" statement, offer
|
|
2406
2660
|
// the "import" keyword as a completion.
|