@zzzen/pyright-internal 1.2.0-dev.20260809 → 1.2.0-dev.20260823
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/analyzerNodeInfo.d.ts +119 -24
- package/dist/analyzer/analyzerNodeInfo.js +408 -89
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.d.ts +6 -3
- package/dist/analyzer/binder.js +157 -70
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +5 -2
- package/dist/analyzer/checker.js +92 -34
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +2 -1
- package/dist/analyzer/codeFlowEngine.js +12 -10
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowUtils.d.ts +2 -1
- package/dist/analyzer/codeFlowUtils.js +2 -3
- package/dist/analyzer/codeFlowUtils.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +47 -7
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +18 -8
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.d.ts +6 -4
- package/dist/analyzer/dataClasses.js +119 -75
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.d.ts +2 -1
- package/dist/analyzer/declarationUtils.js +2 -2
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.d.ts +5 -4
- package/dist/analyzer/decorators.js +38 -21
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.d.ts +5 -4
- package/dist/analyzer/enums.js +11 -10
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +1 -1
- package/dist/analyzer/importResolver.js +5 -3
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.d.ts +3 -1
- package/dist/analyzer/importStatementUtils.js +14 -7
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.d.ts +2 -1
- package/dist/analyzer/namedTuples.js +3 -4
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.d.ts +3 -2
- package/dist/analyzer/operations.js +8 -8
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +2 -2
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +13 -11
- package/dist/analyzer/parseTreeUtils.js +62 -36
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.d.ts +7 -2
- package/dist/analyzer/parseTreeWalker.js +29 -175
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.d.ts +4 -3
- package/dist/analyzer/patternMatching.js +47 -43
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +12 -0
- package/dist/analyzer/program.js +235 -29
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.d.ts +4 -3
- package/dist/analyzer/properties.js +7 -8
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +14 -2
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/scope.d.ts +3 -0
- package/dist/analyzer/scope.js +10 -0
- package/dist/analyzer/scope.js.map +1 -1
- package/dist/analyzer/scopeUtils.d.ts +4 -3
- package/dist/analyzer/scopeUtils.js +8 -8
- package/dist/analyzer/scopeUtils.js.map +1 -1
- package/dist/analyzer/sentinel.d.ts +2 -1
- package/dist/analyzer/sentinel.js +2 -3
- package/dist/analyzer/sentinel.js.map +1 -1
- package/dist/analyzer/service.js +28 -10
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceEnumerator.d.ts +5 -0
- package/dist/analyzer/sourceEnumerator.js +57 -3
- package/dist/analyzer/sourceEnumerator.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +12 -6
- package/dist/analyzer/sourceFile.js +73 -50
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.d.ts +1 -0
- package/dist/analyzer/sourceFileInfoUtils.js +8 -0
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/sourceMapper.d.ts +4 -1
- package/dist/analyzer/sourceMapper.js +14 -8
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +4 -1
- package/dist/analyzer/symbol.js +8 -0
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/testWalker.js +2 -1
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/tracePrinter.d.ts +2 -1
- package/dist/analyzer/tracePrinter.js +2 -2
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +3 -2
- package/dist/analyzer/tuples.js +5 -5
- package/dist/analyzer/tuples.js.map +1 -1
- package/dist/analyzer/typeCacheUtils.d.ts +6 -2
- package/dist/analyzer/typeCacheUtils.js +16 -37
- package/dist/analyzer/typeCacheUtils.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.d.ts +5 -7
- package/dist/analyzer/typeDocStringUtils.js +229 -132
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +2 -0
- package/dist/analyzer/typeEvaluator.js +1280 -302
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +3 -2
- package/dist/analyzer/typeGuards.js +37 -33
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +12 -9
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.js +3 -1
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +4 -3
- package/dist/analyzer/typedDicts.js +15 -14
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +11 -1
- package/dist/analyzer/types.js +48 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/collectionUtils.js +15 -6
- package/dist/common/collectionUtils.js.map +1 -1
- package/dist/common/commandLineOptions.d.ts +1 -0
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/configOptions.d.ts +4 -1
- package/dist/common/configOptions.js +68 -12
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/envVarUtils.d.ts +1 -0
- package/dist/common/envVarUtils.js +41 -10
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/extensibility.d.ts +3 -1
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/extraPathGlob.d.ts +12 -0
- package/dist/common/extraPathGlob.js +315 -0
- package/dist/common/extraPathGlob.js.map +1 -0
- package/dist/common/host.d.ts +2 -0
- package/dist/common/host.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +2 -1
- package/dist/common/languageServerInterface.js.map +1 -1
- package/dist/common/pathConsts.d.ts +1 -0
- package/dist/common/pathConsts.js +11 -1
- package/dist/common/pathConsts.js.map +1 -1
- package/dist/common/processUtils.d.ts +4 -2
- package/dist/common/processUtils.js +3 -0
- package/dist/common/processUtils.js.map +1 -1
- package/dist/common/stringUtils.d.ts +6 -0
- package/dist/common/stringUtils.js +87 -5
- package/dist/common/stringUtils.js.map +1 -1
- package/dist/common/textEditTracker.d.ts +3 -1
- package/dist/common/textEditTracker.js +8 -6
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/common/textRangeCollection.d.ts +1 -0
- package/dist/common/textRangeCollection.js +32 -1
- package/dist/common/textRangeCollection.js.map +1 -1
- package/dist/common/uri/uriUtils.d.ts +3 -0
- package/dist/common/uri/uriUtils.js +65 -15
- package/dist/common/uri/uriUtils.js.map +1 -1
- package/dist/fileSystemMapping.d.ts +10 -0
- package/dist/fileSystemMapping.js +176 -0
- package/dist/fileSystemMapping.js.map +1 -0
- package/dist/languageService/analyzerServiceExecutor.js +2 -1
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +1 -0
- package/dist/languageService/autoImporter.js +32 -5
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.d.ts +7 -0
- package/dist/languageService/callHierarchyProvider.js +97 -11
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +30 -8
- package/dist/languageService/completionProvider.js +298 -93
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +7 -6
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentHighlightProvider.js +2 -1
- package/dist/languageService/documentHighlightProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +3 -1
- package/dist/languageService/documentSymbolCollector.js +78 -14
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/documentSymbolProvider.js +3 -2
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/fileWatcherDynamicFeature.js +28 -1
- package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +2 -1
- package/dist/languageService/hoverProvider.js +48 -16
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importSorter.d.ts +3 -1
- package/dist/languageService/importSorter.js +4 -2
- package/dist/languageService/importSorter.js.map +1 -1
- package/dist/languageService/importStatementCandidates.js +4 -2
- package/dist/languageService/importStatementCandidates.js.map +1 -1
- package/dist/languageService/quickActions.js +2 -1
- package/dist/languageService/quickActions.js.map +1 -1
- package/dist/languageService/referencesProvider.js +12 -5
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.d.ts +3 -0
- package/dist/languageService/signatureHelpProvider.js +56 -18
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.d.ts +2 -1
- package/dist/languageService/symbolIndexer.js +7 -7
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.d.ts +1 -1
- package/dist/languageService/tooltipUtils.js +103 -35
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.js +3 -2
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +12 -0
- package/dist/localization/localize.js +14 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +11 -0
- package/dist/localization/package.nls.de.json +11 -0
- package/dist/localization/package.nls.en-us.json +18 -0
- package/dist/localization/package.nls.es.json +11 -0
- package/dist/localization/package.nls.fr.json +11 -0
- package/dist/localization/package.nls.it.json +11 -0
- package/dist/localization/package.nls.ja.json +11 -0
- package/dist/localization/package.nls.ko.json +11 -0
- package/dist/localization/package.nls.pl.json +11 -0
- package/dist/localization/package.nls.pt-br.json +11 -0
- package/dist/localization/package.nls.qps-ploc.json +11 -0
- package/dist/localization/package.nls.ru.json +11 -0
- package/dist/localization/package.nls.tr.json +11 -0
- package/dist/localization/package.nls.zh-cn.json +12 -1
- package/dist/localization/package.nls.zh-tw.json +13 -2
- package/dist/parser/parseNodes.d.ts +85 -80
- package/dist/parser/parseNodes.js +182 -159
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parseTreeUtils.d.ts +3 -0
- package/dist/parser/parseTreeUtils.js +209 -0
- package/dist/parser/parseTreeUtils.js.map +1 -0
- package/dist/parser/parser.d.ts +16 -6
- package/dist/parser/parser.js +210 -144
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/stringAnnotationInfo.d.ts +16 -0
- package/dist/parser/stringAnnotationInfo.js +26 -0
- package/dist/parser/stringAnnotationInfo.js.map +1 -0
- package/dist/readonlyAugmentedFileSystem.d.ts +2 -9
- package/dist/readonlyAugmentedFileSystem.js +17 -144
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +2 -2
- package/dist/server.js.map +1 -1
- package/dist/tests/analyzerNodeInfo.test.d.ts +1 -0
- package/dist/tests/analyzerNodeInfo.test.js +113 -0
- package/dist/tests/analyzerNodeInfo.test.js.map +1 -0
- package/dist/tests/collectionUtils.test.js +46 -0
- package/dist/tests/collectionUtils.test.js.map +1 -1
- package/dist/tests/completions.test.js +34 -0
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/config.test.js +131 -6
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/extraPathGlob.test.d.ts +1 -0
- package/dist/tests/extraPathGlob.test.js +434 -0
- package/dist/tests/extraPathGlob.test.js.map +1 -0
- package/dist/tests/fileSystemMapping.test.d.ts +1 -0
- package/dist/tests/fileSystemMapping.test.js +458 -0
- package/dist/tests/fileSystemMapping.test.js.map +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.fourslash.js +23 -0
- package/dist/tests/fourslash/completions.call.typedDict.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.call.typedDict.list.fourslash.js +14 -0
- package/dist/tests/fourslash/completions.call.typedDict.list.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.call.typedDict.states.fourslash.js +7 -0
- package/dist/tests/fourslash/completions.call.typedDict.states.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.callSite.isinstanceNarrowing.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.callSite.isinstanceNarrowing.fourslash.js +41 -0
- package/dist/tests/fourslash/completions.callSite.isinstanceNarrowing.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js +2 -0
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js +5 -0
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.stringLiteral.fourslash.js +4 -0
- package/dist/tests/fourslash/completions.stringLiteral.fourslash.js.map +1 -1
- package/dist/tests/fourslash/findallreferences.protocolMemberVariable.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.protocolMemberVariable.fourslash.js +48 -0
- package/dist/tests/fourslash/findallreferences.protocolMemberVariable.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js +8 -2
- package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js +5 -2
- package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js.map +1 -1
- package/dist/tests/fourslash/signature.docstrings.overloaded.fourslash.js +2 -2
- package/dist/tests/fourslash/signature.docstrings.overloaded.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +1 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/hoverProvider.test.js +38 -0
- package/dist/tests/hoverProvider.test.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +6 -3
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/ipythonMode.test.js +38 -0
- package/dist/tests/ipythonMode.test.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +88 -0
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/parser.test.js +60 -3
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/positionUtils.test.js +23 -0
- package/dist/tests/positionUtils.test.js.map +1 -1
- package/dist/tests/pyrightFileSystem.test.js +41 -0
- package/dist/tests/pyrightFileSystem.test.js.map +1 -1
- package/dist/tests/service.test.js +77 -0
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/sourceEnumeratorSymlink.test.d.ts +1 -0
- package/dist/tests/sourceEnumeratorSymlink.test.js +203 -0
- package/dist/tests/sourceEnumeratorSymlink.test.js.map +1 -0
- package/dist/tests/stringUtils.test.js +84 -0
- package/dist/tests/stringUtils.test.js.map +1 -1
- package/dist/tests/symlinkAliasInvalidation.test.d.ts +1 -0
- package/dist/tests/symlinkAliasInvalidation.test.js +471 -0
- package/dist/tests/symlinkAliasInvalidation.test.js.map +1 -0
- package/dist/tests/testUtils.d.ts +2 -0
- package/dist/tests/testUtils.js +7 -1
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/textEditUtil.test.js +2 -2
- package/dist/tests/textEditUtil.test.js.map +1 -1
- package/dist/tests/textRangeCollection.test.d.ts +1 -0
- package/dist/tests/textRangeCollection.test.js +137 -0
- package/dist/tests/textRangeCollection.test.js.map +1 -0
- package/dist/tests/typeCacheUtils.test.d.ts +1 -0
- package/dist/tests/typeCacheUtils.test.js +69 -0
- package/dist/tests/typeCacheUtils.test.js.map +1 -0
- package/dist/tests/typeEvaluator1.test.js +24 -3
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +8 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +4 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +12 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +33 -1
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +29 -0
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +318 -4
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/dist/tests/typeServer/typeCache.test.d.ts +1 -0
- package/dist/tests/typeServer/typeCache.test.js +69 -0
- package/dist/tests/typeServer/typeCache.test.js.map +1 -0
- package/dist/tests/typeServer/typeServer.virtualFileRedirect.test.js +18 -0
- package/dist/tests/typeServer/typeServer.virtualFileRedirect.test.js.map +1 -1
- package/dist/tests/types.test.d.ts +1 -0
- package/dist/{analyzer/parseTreeCleaner.js → tests/types.test.js} +23 -25
- package/dist/tests/types.test.js.map +1 -0
- package/dist/tests/uri.test.js +51 -0
- package/dist/tests/uri.test.js.map +1 -1
- package/dist/typeServer/notebookDocumentHandler.d.ts +9 -2
- package/dist/typeServer/notebookDocumentHandler.js +16 -6
- package/dist/typeServer/notebookDocumentHandler.js.map +1 -1
- package/dist/typeServer/programWrapper.d.ts +1 -0
- package/dist/typeServer/programWrapper.js +28 -15
- package/dist/typeServer/programWrapper.js.map +1 -1
- package/dist/typeServer/protocol/tspSupplemental.d.ts +1 -1
- package/dist/typeServer/protocol/tspSupplemental.js +2 -2
- package/dist/typeServer/server.d.ts +13 -2
- package/dist/typeServer/server.js +36 -23
- package/dist/typeServer/server.js.map +1 -1
- package/dist/typeServer/typeCache.d.ts +8 -4
- package/dist/typeServer/typeCache.js +33 -5
- package/dist/typeServer/typeCache.js.map +1 -1
- package/dist/typeServer/typeEvalUtils.d.ts +2 -1
- package/dist/typeServer/typeEvalUtils.js +7 -3
- package/dist/typeServer/typeEvalUtils.js.map +1 -1
- package/dist/typeServer/typeServerFileSystem.d.ts +10 -9
- package/dist/typeServer/typeServerFileSystem.js +16 -12
- package/dist/typeServer/typeServerFileSystem.js.map +1 -1
- package/package.json +7 -5
- package/dist/analyzer/parseTreeCleaner.d.ts +0 -8
- package/dist/analyzer/parseTreeCleaner.js.map +0 -1
|
@@ -42,11 +42,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
42
42
|
};
|
|
43
43
|
})();
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.CompletionMap = exports.CompletionProvider = exports.indexValueDetail = exports.autoImportDetail = void 0;
|
|
45
|
+
exports.CompletionMap = exports.CompletionProvider = exports.indexValueDetail = exports.autoImportDetail = exports.SortCategory = void 0;
|
|
46
46
|
exports.hoistCompletionItemDataDefault = hoistCompletionItemDataDefault;
|
|
47
47
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
48
48
|
const vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
49
49
|
const AnalyzerNodeInfo = __importStar(require("../analyzer/analyzerNodeInfo"));
|
|
50
|
+
const analyzerNodeInfo_1 = require("../analyzer/analyzerNodeInfo");
|
|
50
51
|
const declaration_1 = require("../analyzer/declaration");
|
|
51
52
|
const declarationUtils_1 = require("../analyzer/declarationUtils");
|
|
52
53
|
const enums_1 = require("../analyzer/enums");
|
|
@@ -190,30 +191,32 @@ var SortCategory;
|
|
|
190
191
|
SortCategory[SortCategory["ImportModuleName"] = 2] = "ImportModuleName";
|
|
191
192
|
// A literal string.
|
|
192
193
|
SortCategory[SortCategory["LiteralValue"] = 3] = "LiteralValue";
|
|
194
|
+
// A class that is one of the subject's union members in a `match`/`case` pattern.
|
|
195
|
+
SortCategory[SortCategory["MatchClassPattern"] = 4] = "MatchClassPattern";
|
|
193
196
|
// A named parameter in a call expression.
|
|
194
|
-
SortCategory[SortCategory["NamedParameter"] =
|
|
197
|
+
SortCategory[SortCategory["NamedParameter"] = 5] = "NamedParameter";
|
|
195
198
|
// A keyword or symbol that was recently used for completion.
|
|
196
|
-
SortCategory[SortCategory["RecentKeywordOrSymbol"] =
|
|
199
|
+
SortCategory[SortCategory["RecentKeywordOrSymbol"] = 6] = "RecentKeywordOrSymbol";
|
|
197
200
|
// An auto-import symbol that was recently used for completion.
|
|
198
|
-
SortCategory[SortCategory["RecentAutoImport"] =
|
|
201
|
+
SortCategory[SortCategory["RecentAutoImport"] = 7] = "RecentAutoImport";
|
|
199
202
|
// A keyword in the python syntax.
|
|
200
|
-
SortCategory[SortCategory["Keyword"] =
|
|
203
|
+
SortCategory[SortCategory["Keyword"] = 8] = "Keyword";
|
|
201
204
|
// An enum member.
|
|
202
|
-
SortCategory[SortCategory["EnumMember"] =
|
|
205
|
+
SortCategory[SortCategory["EnumMember"] = 9] = "EnumMember";
|
|
203
206
|
// A symbol declared directly on the object or class being accessed.
|
|
204
|
-
SortCategory[SortCategory["DeclaredSymbol"] =
|
|
207
|
+
SortCategory[SortCategory["DeclaredSymbol"] = 10] = "DeclaredSymbol";
|
|
205
208
|
// A private symbol declared directly on the object or class being accessed.
|
|
206
|
-
SortCategory[SortCategory["DeclaredPrivateSymbol"] =
|
|
209
|
+
SortCategory[SortCategory["DeclaredPrivateSymbol"] = 11] = "DeclaredPrivateSymbol";
|
|
207
210
|
// A normal symbol.
|
|
208
|
-
SortCategory[SortCategory["NormalSymbol"] =
|
|
211
|
+
SortCategory[SortCategory["NormalSymbol"] = 12] = "NormalSymbol";
|
|
209
212
|
// A symbol that starts with _ or __ (used only when there is
|
|
210
213
|
// no matching filter).
|
|
211
|
-
SortCategory[SortCategory["PrivateSymbol"] =
|
|
214
|
+
SortCategory[SortCategory["PrivateSymbol"] = 13] = "PrivateSymbol";
|
|
212
215
|
// A symbol with a dunder name (e.g. __init__).
|
|
213
|
-
SortCategory[SortCategory["DunderSymbol"] =
|
|
216
|
+
SortCategory[SortCategory["DunderSymbol"] = 14] = "DunderSymbol";
|
|
214
217
|
// An auto-import symbol.
|
|
215
|
-
SortCategory[SortCategory["AutoImport"] =
|
|
216
|
-
})(SortCategory || (SortCategory = {}));
|
|
218
|
+
SortCategory[SortCategory["AutoImport"] = 15] = "AutoImport";
|
|
219
|
+
})(SortCategory || (exports.SortCategory = SortCategory = {}));
|
|
217
220
|
// Publishes the shared completion item `data` fields (uri/position) once via
|
|
218
221
|
// `CompletionList.itemDefaults.data` and requests a shallow merge via `CompletionList.applyKind`,
|
|
219
222
|
// so each item only needs to carry its per-item data. Items are built without the shared fields in
|
|
@@ -262,6 +265,7 @@ class CompletionProvider {
|
|
|
262
265
|
this.execEnv = this.configOptions.findExecEnvironment(this.fileUri);
|
|
263
266
|
this.parseResults = this.program.getParseResults(this.fileUri);
|
|
264
267
|
this.sourceMapper = this.program.getSourceMapper(this.fileUri, this.cancellationToken, /* mapCompiled */ true);
|
|
268
|
+
this.nodeInfo = (0, analyzerNodeInfo_1.getInfoReader)(this.program);
|
|
265
269
|
}
|
|
266
270
|
getCompletions() {
|
|
267
271
|
if (!this.program.getSourceFileInfo(this.fileUri)) {
|
|
@@ -592,7 +596,7 @@ class CompletionProvider {
|
|
|
592
596
|
// Handle enum members specially. Enum members normally look like
|
|
593
597
|
// variables, but the are declared using assignment expressions
|
|
594
598
|
// within an enum class.
|
|
595
|
-
if (this.
|
|
599
|
+
if (this.isEnumMember(detail.boundObjectOrClass, name)) {
|
|
596
600
|
itemKind = vscode_languageserver_1.CompletionItemKind.EnumMember;
|
|
597
601
|
}
|
|
598
602
|
this.addNameToCompletions(detail.autoImportAlias ?? name, itemKind, priorWord, completionMap, {
|
|
@@ -651,7 +655,7 @@ class CompletionProvider {
|
|
|
651
655
|
// instance=false, so this block is independently unreachable. The explicit
|
|
652
656
|
// !preserveEnumMembers guard is defense-in-depth for clarity.
|
|
653
657
|
for (const name of symbolTable.keys()) {
|
|
654
|
-
if (this.
|
|
658
|
+
if (this.isEnumMember(resolvedClassSubtype, name)) {
|
|
655
659
|
symbolTable.delete(name);
|
|
656
660
|
}
|
|
657
661
|
}
|
|
@@ -756,7 +760,7 @@ class CompletionProvider {
|
|
|
756
760
|
}
|
|
757
761
|
else if (detail?.autoImportText) {
|
|
758
762
|
// Force auto-import entries to the end.
|
|
759
|
-
completionItem.sortText = this.
|
|
763
|
+
completionItem.sortText = this.makeSortText(SortCategory.AutoImport, `${name}.${this._formatInteger(detail.autoImportText.source.length, 2)}.${detail.autoImportText.source}`, detail.autoImportText.importText);
|
|
760
764
|
completionItemData.autoImportText = detail.autoImportText.importText;
|
|
761
765
|
completionItem.detail = exports.autoImportDetail;
|
|
762
766
|
if (detail.autoImportText.source) {
|
|
@@ -765,23 +769,23 @@ class CompletionProvider {
|
|
|
765
769
|
}
|
|
766
770
|
else if (itemKind === vscode_languageserver_1.CompletionItemKind.EnumMember) {
|
|
767
771
|
// Handle enum members separately so they are sorted above other symbols.
|
|
768
|
-
completionItem.sortText = this.
|
|
772
|
+
completionItem.sortText = this.makeSortText(SortCategory.EnumMember, name);
|
|
769
773
|
}
|
|
770
774
|
else if (SymbolNameUtils.isDunderName(name)) {
|
|
771
775
|
// Force dunder-named symbols to appear after all other symbols.
|
|
772
|
-
completionItem.sortText = this.
|
|
776
|
+
completionItem.sortText = this.makeSortText(SortCategory.DunderSymbol, name);
|
|
773
777
|
}
|
|
774
778
|
else if (filter === '' && SymbolNameUtils.isPrivateOrProtectedName(name)) {
|
|
775
779
|
// Distinguish between normal and private symbols only if there is
|
|
776
780
|
// currently no filter text. Once we get a single character to filter
|
|
777
781
|
// upon, we'll no longer differentiate.
|
|
778
|
-
completionItem.sortText = this.
|
|
782
|
+
completionItem.sortText = this.makeSortText(detail?.declaredOnBoundObjectOrClass ? SortCategory.DeclaredPrivateSymbol : SortCategory.PrivateSymbol, name);
|
|
779
783
|
}
|
|
780
784
|
else if (filter === '' && detail?.declaredOnBoundObjectOrClass) {
|
|
781
|
-
completionItem.sortText = this.
|
|
785
|
+
completionItem.sortText = this.makeSortText(SortCategory.DeclaredSymbol, name);
|
|
782
786
|
}
|
|
783
787
|
else {
|
|
784
|
-
completionItem.sortText = this.
|
|
788
|
+
completionItem.sortText = this.makeSortText(SortCategory.NormalSymbol, name);
|
|
785
789
|
}
|
|
786
790
|
completionItemData.symbolLabel = name;
|
|
787
791
|
if (this.options.format === vscode_languageserver_1.MarkupKind.Markdown) {
|
|
@@ -874,6 +878,24 @@ class CompletionProvider {
|
|
|
874
878
|
importText,
|
|
875
879
|
};
|
|
876
880
|
}
|
|
881
|
+
// Extension hook for `match`/`case` pattern-slot completions. The base implementation does
|
|
882
|
+
// nothing (it returns undefined so the normal expression path continues); a subclass
|
|
883
|
+
// (Pylance) overrides this to provide slot-aware pattern completions. When it returns a
|
|
884
|
+
// completion map (possibly empty, to deliberately suppress suggestions) the caller short-
|
|
885
|
+
// circuits and uses it; when it returns undefined the cursor is not in a pattern slot.
|
|
886
|
+
tryGetMatchCasePatternCompletions(_node, _priorWord, _priorText, _postText) {
|
|
887
|
+
return undefined;
|
|
888
|
+
}
|
|
889
|
+
isEnumMember(containingType, name) {
|
|
890
|
+
if (!containingType || !types_1.ClassType.isEnumClass(containingType)) {
|
|
891
|
+
return false;
|
|
892
|
+
}
|
|
893
|
+
const symbolType = (0, enums_1.transformTypeForEnumMember)(this.evaluator, containingType, name, (0, analyzerNodeInfo_1.getInfoReader)(this.evaluator));
|
|
894
|
+
return (symbolType &&
|
|
895
|
+
(0, types_1.isClassInstance)(symbolType) &&
|
|
896
|
+
types_1.ClassType.isSameGenericClass(symbolType, types_1.TypeBase.isInstance(containingType) ? containingType : types_1.ClassType.cloneAsInstance(containingType)) &&
|
|
897
|
+
symbolType.priv.literalValue instanceof types_1.EnumLiteral);
|
|
898
|
+
}
|
|
877
899
|
get _fileContents() {
|
|
878
900
|
return this.parseResults?.text ?? '';
|
|
879
901
|
}
|
|
@@ -898,7 +920,7 @@ class CompletionProvider {
|
|
|
898
920
|
if (offset === undefined) {
|
|
899
921
|
return originalType;
|
|
900
922
|
}
|
|
901
|
-
const node = ParseTreeUtils.findNodeByOffset(this.parseResults.parserOutput.parseTree, offset);
|
|
923
|
+
const node = ParseTreeUtils.findNodeByOffset(this.parseResults.parserOutput.parseTree, offset, this.nodeInfo);
|
|
902
924
|
const memberAccessNode = node
|
|
903
925
|
? ParseTreeUtils.getParentNodeOfType(node, 35 /* ParseNodeType.MemberAccess */)
|
|
904
926
|
: undefined;
|
|
@@ -915,7 +937,7 @@ class CompletionProvider {
|
|
|
915
937
|
if (offset === undefined) {
|
|
916
938
|
return undefined;
|
|
917
939
|
}
|
|
918
|
-
let node = ParseTreeUtils.findNodeByOffset(this.parseResults.parserOutput.parseTree, offset);
|
|
940
|
+
let node = ParseTreeUtils.findNodeByOffset(this.parseResults.parserOutput.parseTree, offset, this.nodeInfo);
|
|
919
941
|
// See if we're inside a string literal or an f-string statement.
|
|
920
942
|
const token = ParseTreeUtils.getTokenOverlapping(this.parseResults.tokenizerOutput.tokens, offset);
|
|
921
943
|
if (token?.type === 5 /* TokenType.String */) {
|
|
@@ -950,7 +972,7 @@ class CompletionProvider {
|
|
|
950
972
|
if (curChar === ',') {
|
|
951
973
|
sawComma = true;
|
|
952
974
|
}
|
|
953
|
-
const curNode = ParseTreeUtils.findNodeByOffset(this.parseResults.parserOutput.parseTree, curOffset);
|
|
975
|
+
const curNode = ParseTreeUtils.findNodeByOffset(this.parseResults.parserOutput.parseTree, curOffset, this.nodeInfo);
|
|
954
976
|
if (curNode && curNode !== initialNode) {
|
|
955
977
|
if ((curNode.nodeType === 48 /* ParseNodeType.StringList */ ||
|
|
956
978
|
curNode.nodeType === 49 /* ParseNodeType.String */ ||
|
|
@@ -1287,7 +1309,7 @@ class CompletionProvider {
|
|
|
1287
1309
|
return this._getExpressionCompletions(node, priorWord, priorText, postText);
|
|
1288
1310
|
}
|
|
1289
1311
|
const previousOffset = textRange_1.TextRange.getEnd(prevToken);
|
|
1290
|
-
const previousNode = ParseTreeUtils.findNodeByOffset(this.parseResults.parserOutput.parseTree, previousOffset);
|
|
1312
|
+
const previousNode = ParseTreeUtils.findNodeByOffset(this.parseResults.parserOutput.parseTree, previousOffset, this.nodeInfo);
|
|
1291
1313
|
if (previousNode?.nodeType !== 0 /* ParseNodeType.Error */ ||
|
|
1292
1314
|
previousNode.d.category !== 7 /* ErrorExpressionCategory.MissingMemberAccessName */) {
|
|
1293
1315
|
return this._getExpressionCompletions(node, priorWord, priorText, postText);
|
|
@@ -1357,7 +1379,7 @@ class CompletionProvider {
|
|
|
1357
1379
|
_createSingleKeywordCompletion(keyword) {
|
|
1358
1380
|
const completionItem = vscode_languageserver_1.CompletionItem.create(keyword);
|
|
1359
1381
|
completionItem.kind = vscode_languageserver_1.CompletionItemKind.Keyword;
|
|
1360
|
-
completionItem.sortText = this.
|
|
1382
|
+
completionItem.sortText = this.makeSortText(SortCategory.LikelyKeyword, keyword);
|
|
1361
1383
|
const completionMap = new CompletionMap();
|
|
1362
1384
|
completionMap.set(completionItem);
|
|
1363
1385
|
return completionMap;
|
|
@@ -1392,7 +1414,7 @@ class CompletionProvider {
|
|
|
1392
1414
|
expandTypeAlias: false,
|
|
1393
1415
|
});
|
|
1394
1416
|
this.addNameToCompletions(text, vscode_languageserver_1.CompletionItemKind.Reference, priorWord, completionMap, {
|
|
1395
|
-
sortText: this.
|
|
1417
|
+
sortText: this.makeSortText(SortCategory.LikelyKeyword, text),
|
|
1396
1418
|
});
|
|
1397
1419
|
return;
|
|
1398
1420
|
}
|
|
@@ -1429,7 +1451,7 @@ class CompletionProvider {
|
|
|
1429
1451
|
: 2 /* ParseTreeUtils.PrintExpressionFlags.DoNotLimitStringLength */;
|
|
1430
1452
|
const text = `${ParseTreeUtils.printExpression(declWithTypeAnnotations[declWithTypeAnnotations.length - 1].typeAnnotationNode, printFlags)}`;
|
|
1431
1453
|
this.addNameToCompletions(text, vscode_languageserver_1.CompletionItemKind.Reference, priorWord, completionMap, {
|
|
1432
|
-
sortText: this.
|
|
1454
|
+
sortText: this.makeSortText(SortCategory.LikelyKeyword, text),
|
|
1433
1455
|
});
|
|
1434
1456
|
}
|
|
1435
1457
|
_getClassVariableCompletions(partialName) {
|
|
@@ -1468,7 +1490,7 @@ class CompletionProvider {
|
|
|
1468
1490
|
return completionMap.size > 0 ? completionMap : undefined;
|
|
1469
1491
|
}
|
|
1470
1492
|
_getMethodOverloadsCompletions(priorWord, partialName) {
|
|
1471
|
-
const symbolTable = getSymbolTable(this.evaluator, partialName);
|
|
1493
|
+
const symbolTable = getSymbolTable(this.evaluator, partialName, this.nodeInfo);
|
|
1472
1494
|
if (!symbolTable) {
|
|
1473
1495
|
return undefined;
|
|
1474
1496
|
}
|
|
@@ -1498,7 +1520,7 @@ class CompletionProvider {
|
|
|
1498
1520
|
}
|
|
1499
1521
|
});
|
|
1500
1522
|
return completionMap;
|
|
1501
|
-
function getSymbolTable(evaluator, partialName) {
|
|
1523
|
+
function getSymbolTable(evaluator, partialName, nodeInfo) {
|
|
1502
1524
|
const enclosingClass = ParseTreeUtils.getEnclosingClass(partialName, false);
|
|
1503
1525
|
if (enclosingClass) {
|
|
1504
1526
|
const classResults = evaluator.getTypeOfClass(enclosingClass);
|
|
@@ -1516,7 +1538,7 @@ class CompletionProvider {
|
|
|
1516
1538
|
// For function overload, we only care about top level functions
|
|
1517
1539
|
const moduleNode = ParseTreeUtils.getEnclosingModule(partialName);
|
|
1518
1540
|
if (moduleNode) {
|
|
1519
|
-
const moduleScope = AnalyzerNodeInfo.getScope(moduleNode);
|
|
1541
|
+
const moduleScope = AnalyzerNodeInfo.getScope(moduleNode, nodeInfo);
|
|
1520
1542
|
return moduleScope?.symbolTable;
|
|
1521
1543
|
}
|
|
1522
1544
|
return undefined;
|
|
@@ -1622,12 +1644,32 @@ class CompletionProvider {
|
|
|
1622
1644
|
// The condition of `if <expr>:` / `elif <expr>:` (elif is a
|
|
1623
1645
|
// nested `IfNode`).
|
|
1624
1646
|
return parent.d.testExpr === node;
|
|
1647
|
+
case 64 /* ParseNodeType.Case */:
|
|
1648
|
+
// The guard of `case <pattern> if <expr>:`. The guard is a real
|
|
1649
|
+
// expression (not a pattern), but a statement-only keyword is never
|
|
1650
|
+
// valid there. The pattern slot itself is handled separately via
|
|
1651
|
+
// `tryGetMatchCasePatternCompletions`.
|
|
1652
|
+
return parent.d.guardExpr === node;
|
|
1625
1653
|
default:
|
|
1626
1654
|
return false;
|
|
1627
1655
|
}
|
|
1628
1656
|
}
|
|
1629
1657
|
_getExpressionCompletions(parseNode, priorWord, priorText, postText) {
|
|
1630
1658
|
const isIndexArgument = this._isIndexArgument(parseNode);
|
|
1659
|
+
// A `match`/`case` pattern slot is not an arbitrary expression: only a restricted
|
|
1660
|
+
// grammar is valid there. When the cursor sits in such a slot, build a tailored
|
|
1661
|
+
// completion set (filtered/narrowed to what can form a pattern) and short-circuit
|
|
1662
|
+
// the generic symbol/keyword dump below. This runs before the numeric-literal and
|
|
1663
|
+
// `with ... as` guards so that pattern slots whose node-resolution lands on a numeric
|
|
1664
|
+
// element (e.g. `case (1, ‸)`, where the cursor resolves to the `1` literal) still get
|
|
1665
|
+
// slot-aware completions. The base implementation returns undefined; Pylance overrides
|
|
1666
|
+
// `tryGetMatchCasePatternCompletions` to provide the slot-aware set (and intentionally
|
|
1667
|
+
// returns undefined when the cursor is inside the numeric literal being typed, e.g.
|
|
1668
|
+
// `case 3.‸`, so the numeric guard below still suppresses completions there).
|
|
1669
|
+
const matchCaseCompletions = this.tryGetMatchCasePatternCompletions(parseNode, priorWord, priorText, postText);
|
|
1670
|
+
if (matchCaseCompletions) {
|
|
1671
|
+
return matchCaseCompletions;
|
|
1672
|
+
}
|
|
1631
1673
|
// If the user typed a "." as part of a number, don't present
|
|
1632
1674
|
// any completion options.
|
|
1633
1675
|
if (!isIndexArgument && parseNode.nodeType === 40 /* ParseNodeType.Number */) {
|
|
@@ -1650,9 +1692,9 @@ class CompletionProvider {
|
|
|
1650
1692
|
this._addClassVariableTypeAnnotationCompletions(priorWord, parseNode, completionMap);
|
|
1651
1693
|
// Add call argument completions.
|
|
1652
1694
|
this._addCallArgumentCompletions(parseNode, priorWord, priorText, postText,
|
|
1653
|
-
/* atArgument */
|
|
1695
|
+
/* atArgument */ this._isInsideContainerArgument(parseNode), completionMap);
|
|
1654
1696
|
// Add symbols that are in scope.
|
|
1655
|
-
this.
|
|
1697
|
+
this.addSymbols(parseNode, priorWord, completionMap);
|
|
1656
1698
|
this.addAdditionalExpressionCompletions(parseNode, priorWord, completionMap);
|
|
1657
1699
|
// Add keywords. In slots that can only contain an expression, suppress
|
|
1658
1700
|
// keywords that are only valid at the start of a statement (e.g. don't
|
|
@@ -1660,13 +1702,13 @@ class CompletionProvider {
|
|
|
1660
1702
|
const keywords = this._isExpressionOnlySlot(parseNode)
|
|
1661
1703
|
? Keywords.expressionKeywordsForVersion(this.execEnv.pythonVersion)
|
|
1662
1704
|
: Keywords.forVersion(this.execEnv.pythonVersion);
|
|
1663
|
-
this.
|
|
1705
|
+
this.findMatchingKeywords(keywords, priorWord).map((keyword) => {
|
|
1664
1706
|
if (completionMap.has(keyword)) {
|
|
1665
1707
|
return;
|
|
1666
1708
|
}
|
|
1667
1709
|
const completionItem = vscode_languageserver_1.CompletionItem.create(keyword);
|
|
1668
1710
|
completionItem.kind = vscode_languageserver_1.CompletionItemKind.Keyword;
|
|
1669
|
-
completionItem.sortText = this.
|
|
1711
|
+
completionItem.sortText = this.makeSortText(SortCategory.Keyword, keyword);
|
|
1670
1712
|
completionMap.set(completionItem);
|
|
1671
1713
|
});
|
|
1672
1714
|
// Add auto-import suggestions from other modules.
|
|
@@ -1689,6 +1731,34 @@ class CompletionProvider {
|
|
|
1689
1731
|
currentNode.parent.d.leftExpr &&
|
|
1690
1732
|
currentNode.parent.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */);
|
|
1691
1733
|
}
|
|
1734
|
+
_isInsideContainerArgument(node) {
|
|
1735
|
+
// Walk up from the cursor node. If we reach a collection literal
|
|
1736
|
+
// (list/dict/set/tuple) before reaching the enclosing call's argument,
|
|
1737
|
+
// the cursor is inside a collection value rather than at an argument slot,
|
|
1738
|
+
// so keyword-argument (named parameter) completions should be suppressed.
|
|
1739
|
+
//
|
|
1740
|
+
// A parenthesized single expression (e.g. `f(x=(value))`) is intentionally NOT a
|
|
1741
|
+
// container: it parses as the inner expression, not a Tuple node, so the walk stops
|
|
1742
|
+
// at the Argument/Call. Only an actual tuple literal (which has a comma) counts here.
|
|
1743
|
+
//
|
|
1744
|
+
// This is only consulted when the cursor is inside a call; the caller early-returns
|
|
1745
|
+
// when there is no enclosing call, so a `true` result outside call context is a no-op.
|
|
1746
|
+
let current = node;
|
|
1747
|
+
while (current) {
|
|
1748
|
+
switch (current.nodeType) {
|
|
1749
|
+
case 34 /* ParseNodeType.List */:
|
|
1750
|
+
case 18 /* ParseNodeType.Dictionary */:
|
|
1751
|
+
case 45 /* ParseNodeType.Set */:
|
|
1752
|
+
case 52 /* ParseNodeType.Tuple */:
|
|
1753
|
+
return true;
|
|
1754
|
+
case 1 /* ParseNodeType.Argument */:
|
|
1755
|
+
case 9 /* ParseNodeType.Call */:
|
|
1756
|
+
return false;
|
|
1757
|
+
}
|
|
1758
|
+
current = current.parent;
|
|
1759
|
+
}
|
|
1760
|
+
return false;
|
|
1761
|
+
}
|
|
1692
1762
|
_addCallArgumentCompletions(parseNode, priorWord, priorText, postText, atArgument, completionMap) {
|
|
1693
1763
|
// If we're within the argument list of a call, add parameter names.
|
|
1694
1764
|
const offset = (0, positionUtils_1.convertPositionToOffset)(this.position, this.parseResults.tokenizerOutput.lines);
|
|
@@ -1719,23 +1789,61 @@ class CompletionProvider {
|
|
|
1719
1789
|
return undefined;
|
|
1720
1790
|
}
|
|
1721
1791
|
const paramType = types_1.FunctionType.getParamType(type, paramIndex);
|
|
1722
|
-
this.
|
|
1792
|
+
this.addLiteralValuesForTargetType(paramType, priorWord, priorText, postText, completionMap);
|
|
1723
1793
|
return undefined;
|
|
1724
1794
|
});
|
|
1725
1795
|
}
|
|
1726
|
-
|
|
1796
|
+
// Kept in place (rather than relocated above the private accessors) to minimize the subrepo diff.
|
|
1797
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1798
|
+
addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap) {
|
|
1727
1799
|
const quoteValue = this._getQuoteInfo(priorWord, priorText);
|
|
1800
|
+
// When the cursor is inside a string/bytes token, only offer the
|
|
1801
|
+
// matching literal kind so a `b"..."` context doesn't surface str
|
|
1802
|
+
// literals (and vice versa) for a mixed `Literal[b"x", "y"]`.
|
|
1803
|
+
const insideStringToken = this._stringLiteralContainer !== undefined;
|
|
1804
|
+
const insideBytesToken = insideStringToken && (this._stringLiteralContainer.flags & 32 /* StringTokenFlags.Bytes */) !== 0;
|
|
1805
|
+
// The bytes re-wrap below hard-codes a single-char `b` prefix. A raw-bytes
|
|
1806
|
+
// token (`rb"..."`/`br"..."`, prefixLength > 1) is outside the documented
|
|
1807
|
+
// `b`-only scope; its multi-char prefix would make the replacement range
|
|
1808
|
+
// off by one and leave a dangling prefix char, so don't offer bytes
|
|
1809
|
+
// completions inside it.
|
|
1810
|
+
const insideMultiCharPrefixToken = insideStringToken && this._stringLiteralContainer.prefixLength > 1;
|
|
1728
1811
|
this._getSubTypesWithLiteralValues(type).forEach((v) => {
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1812
|
+
const isStr = types_1.ClassType.isBuiltIn(v, 'str');
|
|
1813
|
+
const isBytes = types_1.ClassType.isBuiltIn(v, 'bytes');
|
|
1814
|
+
if (!isStr && !isBytes) {
|
|
1815
|
+
return;
|
|
1816
|
+
}
|
|
1817
|
+
if (insideStringToken) {
|
|
1818
|
+
if (isBytes && !insideBytesToken) {
|
|
1819
|
+
return;
|
|
1735
1820
|
}
|
|
1736
|
-
|
|
1737
|
-
|
|
1821
|
+
if (isStr && insideBytesToken) {
|
|
1822
|
+
return;
|
|
1738
1823
|
}
|
|
1824
|
+
if (isBytes && insideMultiCharPrefixToken) {
|
|
1825
|
+
return;
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
// `printLiteralValue` truncates long literals to a `…`-suffixed form.
|
|
1829
|
+
// That is fine for a label, but the same text is used for the inserted
|
|
1830
|
+
// source here, and inserting `…` would produce invalid, wrong code.
|
|
1831
|
+
// Skip offering the completion rather than writing a broken value.
|
|
1832
|
+
if ((0, typePrinter_1.isLiteralValueTruncated)(v)) {
|
|
1833
|
+
return;
|
|
1834
|
+
}
|
|
1835
|
+
// Bytes literals are printed as `b"..."`; the `b` prefix must be
|
|
1836
|
+
// stripped before re-wrapping and accounted for in the range.
|
|
1837
|
+
const prefix = isBytes ? 'b' : '';
|
|
1838
|
+
const value = (0, typePrinter_1.printLiteralValue)(v, quoteValue.quoteCharacter);
|
|
1839
|
+
if (quoteValue.stringValue === undefined) {
|
|
1840
|
+
this.addNameToCompletions(value, vscode_languageserver_1.CompletionItemKind.Constant, priorWord, completionMap, {
|
|
1841
|
+
sortText: this.makeSortText(SortCategory.LiteralValue, v.priv.literalValue),
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
else {
|
|
1845
|
+
this._addStringLiteralToCompletions(value.substr(prefix.length + 1, value.length - prefix.length - 2), quoteValue, postText, completionMap,
|
|
1846
|
+
/* detail */ undefined, prefix, isBytes ? '"' : quoteValue.quoteCharacter);
|
|
1739
1847
|
}
|
|
1740
1848
|
});
|
|
1741
1849
|
}
|
|
@@ -1812,6 +1920,14 @@ class CompletionProvider {
|
|
|
1812
1920
|
!types_1.ClassType.isEnumClass(v)) {
|
|
1813
1921
|
return;
|
|
1814
1922
|
}
|
|
1923
|
+
// printLiteralValue truncates long str/bytes literals to a `…`-suffixed
|
|
1924
|
+
// form. Since bare-bracket keys are inserted verbatim (str/bytes keys now
|
|
1925
|
+
// route through _addStringLiteralToCompletions with a textEdit), offering
|
|
1926
|
+
// a truncated key would write invalid, wrong source. Skip it (mirrors the
|
|
1927
|
+
// annotation-path guard in addLiteralValuesForTargetType).
|
|
1928
|
+
if ((0, typePrinter_1.isLiteralValueTruncated)(v)) {
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1815
1931
|
keys.push((0, typePrinter_1.printLiteralValue)(v, this.parseResults.tokenizerOutput.predominantSingleQuoteCharacter));
|
|
1816
1932
|
});
|
|
1817
1933
|
if (keys.length > 0) {
|
|
@@ -1834,9 +1950,9 @@ class CompletionProvider {
|
|
|
1834
1950
|
}
|
|
1835
1951
|
let startingNode = indexNode.d.leftExpr;
|
|
1836
1952
|
if (declaration.node) {
|
|
1837
|
-
const scopeRoot = ParseTreeUtils.getEvaluationScopeNode(declaration.node).node;
|
|
1953
|
+
const scopeRoot = ParseTreeUtils.getEvaluationScopeNode(declaration.node, this.nodeInfo).node;
|
|
1838
1954
|
// Find the lowest tree to search the symbol.
|
|
1839
|
-
if (ParseTreeUtils.getFileInfoFromNode(startingNode)?.fileUri.equals(ParseTreeUtils.getFileInfoFromNode(scopeRoot)?.fileUri)) {
|
|
1955
|
+
if (ParseTreeUtils.getFileInfoFromNode(startingNode, this.nodeInfo)?.fileUri.equals(ParseTreeUtils.getFileInfoFromNode(scopeRoot, this.nodeInfo)?.fileUri)) {
|
|
1840
1956
|
startingNode = scopeRoot;
|
|
1841
1957
|
}
|
|
1842
1958
|
}
|
|
@@ -1921,7 +2037,11 @@ class CompletionProvider {
|
|
|
1921
2037
|
}
|
|
1922
2038
|
_getLiteralCompletions(parseNode, offset, priorWord, priorText, postText) {
|
|
1923
2039
|
if (this.options.triggerCharacter === '"' || this.options.triggerCharacter === "'") {
|
|
1924
|
-
|
|
2040
|
+
// A prefixed string (e.g. b"" or r"") starts at the prefix, so the opening quote is
|
|
2041
|
+
// offset by the prefix length. Account for that so typing the opening quote of a
|
|
2042
|
+
// b"..." still triggers literal completions (matching plain str behavior).
|
|
2043
|
+
const prefixLength = parseNode.nodeType === 49 /* ParseNodeType.String */ ? parseNode.d.token.prefixLength : 0;
|
|
2044
|
+
if (parseNode.start + prefixLength !== offset - 1) {
|
|
1925
2045
|
// If completion is triggered by typing " or ', it must be the one that starts a string
|
|
1926
2046
|
// literal. In another word, it can't be something inside of another string or comment
|
|
1927
2047
|
return undefined;
|
|
@@ -1949,6 +2069,19 @@ class CompletionProvider {
|
|
|
1949
2069
|
}
|
|
1950
2070
|
const quoteInfo = this._getQuoteInfo(priorWord, priorTextInString);
|
|
1951
2071
|
const keys = this._getIndexKeys(argument.parent, parseNode);
|
|
2072
|
+
// When the cursor is inside a string/bytes token, only offer the matching
|
|
2073
|
+
// literal kind so a `b"..."` context doesn't surface str keys (and vice versa).
|
|
2074
|
+
const insideBytesToken = parseNode.nodeType === 49 /* ParseNodeType.String */ &&
|
|
2075
|
+
this._stringLiteralContainer !== undefined &&
|
|
2076
|
+
(this._stringLiteralContainer.flags & 32 /* StringTokenFlags.Bytes */) !== 0;
|
|
2077
|
+
// The bytes re-wrap below hard-codes a single-char `b` prefix. A raw-bytes
|
|
2078
|
+
// token (`rb"..."`/`br"..."`, prefixLength > 1) is outside the documented
|
|
2079
|
+
// `b`-only scope; its multi-char prefix would make the replacement range
|
|
2080
|
+
// off by one and leave a dangling prefix char, so don't offer bytes keys
|
|
2081
|
+
// inside it. Mirrors the annotation-path guard.
|
|
2082
|
+
const insideMultiCharPrefixToken = parseNode.nodeType === 49 /* ParseNodeType.String */ &&
|
|
2083
|
+
this._stringLiteralContainer !== undefined &&
|
|
2084
|
+
this._stringLiteralContainer.prefixLength > 1;
|
|
1952
2085
|
let keyFound = false;
|
|
1953
2086
|
for (const key of keys) {
|
|
1954
2087
|
if (completionMap.has(key)) {
|
|
@@ -1958,18 +2091,37 @@ class CompletionProvider {
|
|
|
1958
2091
|
// print(dict[<key will come from symbol table provider>]))
|
|
1959
2092
|
continue;
|
|
1960
2093
|
}
|
|
1961
|
-
|
|
2094
|
+
// Index keys are printed via printLiteralValue (str as `"..."`, bytes as
|
|
2095
|
+
// `b"..."`) or collected as raw source text. Recognize an optional bytes
|
|
2096
|
+
// prefix; f/r/u prefixes never denote a distinct completable value here
|
|
2097
|
+
// (f-strings can't be keys/Literals, and raw/unicode normalize to str).
|
|
2098
|
+
const isBytesLiteral = /^[bB]["'].*["']$/.test(key);
|
|
2099
|
+
const stringLiteral = isBytesLiteral || /^["'].*["']$/.test(key);
|
|
1962
2100
|
if (parseNode.nodeType === 49 /* ParseNodeType.String */ && !stringLiteral) {
|
|
1963
2101
|
continue;
|
|
1964
2102
|
}
|
|
2103
|
+
if (parseNode.nodeType === 49 /* ParseNodeType.String */) {
|
|
2104
|
+
if (isBytesLiteral && !insideBytesToken) {
|
|
2105
|
+
continue;
|
|
2106
|
+
}
|
|
2107
|
+
if (!isBytesLiteral && insideBytesToken) {
|
|
2108
|
+
continue;
|
|
2109
|
+
}
|
|
2110
|
+
if (isBytesLiteral && insideMultiCharPrefixToken) {
|
|
2111
|
+
continue;
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
1965
2114
|
keyFound = true;
|
|
1966
2115
|
if (stringLiteral) {
|
|
1967
|
-
|
|
1968
|
-
|
|
2116
|
+
// Bytes keys carry a `b`/`B` prefix; strip it (and the quotes) and
|
|
2117
|
+
// re-wrap using the key's own quote so raw/embedded quotes stay valid.
|
|
2118
|
+
const prefix = isBytesLiteral ? key[0] : '';
|
|
2119
|
+
const keyWithoutQuote = key.substr(prefix.length + 1, key.length - prefix.length - 2);
|
|
2120
|
+
this._addStringLiteralToCompletions(keyWithoutQuote, quoteInfo, postText, completionMap, exports.indexValueDetail, prefix, isBytesLiteral ? key[prefix.length] : undefined);
|
|
1969
2121
|
}
|
|
1970
2122
|
else {
|
|
1971
2123
|
this.addNameToCompletions(key, vscode_languageserver_1.CompletionItemKind.Constant, priorWord, completionMap, {
|
|
1972
|
-
sortText: this.
|
|
2124
|
+
sortText: this.makeSortText(SortCategory.LiteralValue, key),
|
|
1973
2125
|
itemDetail: exports.indexValueDetail,
|
|
1974
2126
|
});
|
|
1975
2127
|
}
|
|
@@ -2026,12 +2178,12 @@ class CompletionProvider {
|
|
|
2026
2178
|
const type = this.evaluator.getType(comparison.d.leftExpr);
|
|
2027
2179
|
if (type) {
|
|
2028
2180
|
if ((0, typeUtils_1.containsLiteralType)(type)) {
|
|
2029
|
-
this.
|
|
2181
|
+
this.addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
|
2030
2182
|
return true;
|
|
2031
2183
|
}
|
|
2032
2184
|
const enumValueLiteralType = getStringLiteralValueTypeFromEnumType(this.evaluator, type);
|
|
2033
2185
|
if (enumValueLiteralType) {
|
|
2034
|
-
this.
|
|
2186
|
+
this.addLiteralValuesForTargetType(enumValueLiteralType, priorWord, priorText, postText, completionMap);
|
|
2035
2187
|
return true;
|
|
2036
2188
|
}
|
|
2037
2189
|
}
|
|
@@ -2042,7 +2194,7 @@ class CompletionProvider {
|
|
|
2042
2194
|
assignmentExpression.d.rightExpr === parentAndChild.child) {
|
|
2043
2195
|
const type = this.evaluator.getType(assignmentExpression.d.name);
|
|
2044
2196
|
if (type && (0, typeUtils_1.containsLiteralType)(type)) {
|
|
2045
|
-
this.
|
|
2197
|
+
this.addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
|
2046
2198
|
return true;
|
|
2047
2199
|
}
|
|
2048
2200
|
}
|
|
@@ -2066,7 +2218,7 @@ class CompletionProvider {
|
|
|
2066
2218
|
const enumMemberSymbols = new Map();
|
|
2067
2219
|
(0, typeUtils_1.getMembersForClass)(enumClassType, enumMemberSymbols, /* includeInstanceVars */ false);
|
|
2068
2220
|
enumMemberSymbols.forEach((_, name) => {
|
|
2069
|
-
const enumMemberType = (0, enums_1.transformTypeForEnumMember)(evaluator, enumClassType, name);
|
|
2221
|
+
const enumMemberType = (0, enums_1.transformTypeForEnumMember)(evaluator, enumClassType, name, (0, analyzerNodeInfo_1.getInfoReader)(evaluator));
|
|
2070
2222
|
if (!enumMemberType || !(0, types_1.isClassInstance)(enumMemberType)) {
|
|
2071
2223
|
return;
|
|
2072
2224
|
}
|
|
@@ -2100,11 +2252,12 @@ class CompletionProvider {
|
|
|
2100
2252
|
}
|
|
2101
2253
|
}
|
|
2102
2254
|
_tryAddMatchCaseLiteralCompletions(parentAndChild, priorWord, priorText, postText, completionMap) {
|
|
2103
|
-
//
|
|
2255
|
+
// Basic literal-completion support for an empty case slot (`case /* here */`) or a `case`
|
|
2256
|
+
// pattern that is already a literal or a capture name (`case "..."` / `case Sym`). Richer
|
|
2257
|
+
// slot-aware pattern completions are provided by the subclass override of
|
|
2258
|
+
// `tryGetMatchCasePatternCompletions`.
|
|
2104
2259
|
// match c:
|
|
2105
2260
|
// case /* here */
|
|
2106
|
-
// and
|
|
2107
|
-
// match c:
|
|
2108
2261
|
// case "/* here */"
|
|
2109
2262
|
// case Sym/*here*/
|
|
2110
2263
|
const parent = parentAndChild.parent;
|
|
@@ -2115,6 +2268,7 @@ class CompletionProvider {
|
|
|
2115
2268
|
parent.d.pattern.d.category === 11 /* ErrorExpressionCategory.MissingPattern */ &&
|
|
2116
2269
|
parent.d.suite === parentAndChild.child &&
|
|
2117
2270
|
parent.parent?.nodeType === 63 /* ParseNodeType.Match */) {
|
|
2271
|
+
// Empty case slot: `case /* here */`. Offer the subject type's literal values.
|
|
2118
2272
|
matchNode = parent.parent;
|
|
2119
2273
|
caseNode = parent;
|
|
2120
2274
|
}
|
|
@@ -2128,9 +2282,12 @@ class CompletionProvider {
|
|
|
2128
2282
|
else {
|
|
2129
2283
|
return false;
|
|
2130
2284
|
}
|
|
2131
|
-
const type = this.
|
|
2132
|
-
if (type
|
|
2133
|
-
|
|
2285
|
+
const type = this.getFilteredMatchSubjectTypeForCaseCompletions(matchNode, caseNode);
|
|
2286
|
+
if (!type) {
|
|
2287
|
+
return false;
|
|
2288
|
+
}
|
|
2289
|
+
if ((0, typeUtils_1.containsLiteralType)(type)) {
|
|
2290
|
+
this.addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
|
2134
2291
|
return true;
|
|
2135
2292
|
}
|
|
2136
2293
|
return false;
|
|
@@ -2144,7 +2301,7 @@ class CompletionProvider {
|
|
|
2144
2301
|
if (!(0, typeUtils_1.containsLiteralType)(candidateType)) {
|
|
2145
2302
|
continue;
|
|
2146
2303
|
}
|
|
2147
|
-
this.
|
|
2304
|
+
this.addLiteralValuesForTargetType(candidateType, priorWord, priorText, postText, completionMap);
|
|
2148
2305
|
addedLiteralValues = true;
|
|
2149
2306
|
}
|
|
2150
2307
|
return addedLiteralValues;
|
|
@@ -2152,7 +2309,9 @@ class CompletionProvider {
|
|
|
2152
2309
|
_canUseExpectedTypeForLiteralCompletion(expressionNode, expectedTypeNode) {
|
|
2153
2310
|
return expressionNode === expectedTypeNode;
|
|
2154
2311
|
}
|
|
2155
|
-
|
|
2312
|
+
// Kept in place (rather than relocated above the private accessors) to minimize the subrepo diff.
|
|
2313
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
2314
|
+
getFilteredMatchSubjectTypeForCaseCompletions(matchNode, currentCaseNode) {
|
|
2156
2315
|
const getPriorCaseStringLiteralValues = () => {
|
|
2157
2316
|
const values = new Set();
|
|
2158
2317
|
const currentIndex = matchNode.d.cases.findIndex((c) => c === currentCaseNode);
|
|
@@ -2228,15 +2387,46 @@ class CompletionProvider {
|
|
|
2228
2387
|
typedDicts = this._tryNarrowTypedDicts(typedDicts, existingKeys);
|
|
2229
2388
|
const quoteInfo = this._getQuoteInfo(priorWord, priorText);
|
|
2230
2389
|
const excludes = new Set(existingKeys);
|
|
2390
|
+
// Collect the value type(s) for each key across all TypedDict subtypes. A key
|
|
2391
|
+
// shared by a union of TypedDicts must advertise the union of its value types
|
|
2392
|
+
// (that is the type produced by actually subscripting the union), not just the
|
|
2393
|
+
// first subtype's value type.
|
|
2394
|
+
const keyValueTypes = new Map();
|
|
2231
2395
|
typedDicts.forEach((typedDict) => {
|
|
2232
|
-
(0, typedDicts_1.getTypedDictMembersForClass)(this.evaluator, typedDict, /* allowNarrowed */ true).knownItems.forEach((
|
|
2396
|
+
(0, typedDicts_1.getTypedDictMembersForClass)(this.evaluator, typedDict, /* allowNarrowed */ true).knownItems.forEach((entry, key) => {
|
|
2233
2397
|
// Unions of TypedDicts may define the same key.
|
|
2234
2398
|
if (excludes.has(key) || completionMap.has(key)) {
|
|
2235
2399
|
return;
|
|
2236
2400
|
}
|
|
2237
|
-
|
|
2238
|
-
|
|
2401
|
+
let valueTypes = keyValueTypes.get(key);
|
|
2402
|
+
if (!valueTypes) {
|
|
2403
|
+
valueTypes = [];
|
|
2404
|
+
keyValueTypes.set(key, valueTypes);
|
|
2405
|
+
}
|
|
2406
|
+
valueTypes.push(entry.valueType);
|
|
2407
|
+
});
|
|
2408
|
+
});
|
|
2409
|
+
keyValueTypes.forEach((valueTypes, key) => {
|
|
2410
|
+
// Short-circuit before the (relatively expensive) printType call on this hot
|
|
2411
|
+
// path: skip keys that _addStringLiteralToCompletions would immediately drop,
|
|
2412
|
+
// either because the typed prefix filters them out or because the quoted label
|
|
2413
|
+
// already exists. These guards mirror the early returns in that helper.
|
|
2414
|
+
if (!StringUtils.isPatternInSymbol(quoteInfo.filterText || '', key)) {
|
|
2415
|
+
return;
|
|
2416
|
+
}
|
|
2417
|
+
const quotedLabel = `${quoteInfo.quoteCharacter}${key}${quoteInfo.quoteCharacter}`;
|
|
2418
|
+
if (completionMap.has(quotedLabel)) {
|
|
2419
|
+
return;
|
|
2420
|
+
}
|
|
2421
|
+
const valueType = valueTypes.length === 1 ? valueTypes[0] : (0, types_1.combineTypes)(valueTypes);
|
|
2422
|
+
// The value type is surfaced as the completion item's detail. It must be set
|
|
2423
|
+
// eagerly here: TypedDict key items carry no symbol, so resolveCompletionItem
|
|
2424
|
+
// bails early and never lazily fills detail.
|
|
2425
|
+
const valueTypeText = this.evaluator.printType(valueType, {
|
|
2426
|
+
enforcePythonSyntax: true,
|
|
2427
|
+
expandTypeAlias: false,
|
|
2239
2428
|
});
|
|
2429
|
+
this._addStringLiteralToCompletions(key, quoteInfo, postText, completionMap, valueTypeText);
|
|
2240
2430
|
});
|
|
2241
2431
|
return true;
|
|
2242
2432
|
}
|
|
@@ -2323,20 +2513,35 @@ class CompletionProvider {
|
|
|
2323
2513
|
}
|
|
2324
2514
|
return this._tryAddTypedDictKeys(baseType, [], priorWord, priorText, postText, completionMap);
|
|
2325
2515
|
}
|
|
2326
|
-
_addStringLiteralToCompletions(value, quoteInfo, postText, completionMap, detail) {
|
|
2516
|
+
_addStringLiteralToCompletions(value, quoteInfo, postText, completionMap, detail, prefix = '', valueQuoteCharacter) {
|
|
2327
2517
|
if (!StringUtils.isPatternInSymbol(quoteInfo.filterText || '', value)) {
|
|
2328
2518
|
return;
|
|
2329
2519
|
}
|
|
2330
|
-
|
|
2520
|
+
// The quote used to wrap the inserted literal must match how `value` was
|
|
2521
|
+
// escaped. Bytes literals are always printed double-quoted (escaping only
|
|
2522
|
+
// `"`), so they must be re-wrapped in double quotes even inside a single-
|
|
2523
|
+
// quoted token; otherwise an embedded `'` would produce invalid source.
|
|
2524
|
+
const wrapQuoteCharacter = valueQuoteCharacter ?? quoteInfo.quoteCharacter;
|
|
2525
|
+
const valueWithQuotes = `${prefix}${wrapQuoteCharacter}${value}${wrapQuoteCharacter}`;
|
|
2331
2526
|
if (completionMap.has(valueWithQuotes)) {
|
|
2332
2527
|
return;
|
|
2333
2528
|
}
|
|
2334
2529
|
const completionItem = vscode_languageserver_1.CompletionItem.create(valueWithQuotes);
|
|
2335
2530
|
completionItem.kind = vscode_languageserver_1.CompletionItemKind.Constant;
|
|
2336
|
-
completionItem.sortText = this.
|
|
2531
|
+
completionItem.sortText = this.makeSortText(SortCategory.LiteralValue, valueWithQuotes);
|
|
2532
|
+
// When the inserted literal is wrapped in a different quote than the
|
|
2533
|
+
// surrounding token (bytes are always double-quoted, even inside a
|
|
2534
|
+
// single-quoted `b'...'` token), the label/insert text uses `"` while the
|
|
2535
|
+
// text under the cursor uses `'`. The client fuzzy-filters the typed
|
|
2536
|
+
// single-quoted text against the double-quoted label and would drop the
|
|
2537
|
+
// item. Provide a filterText that matches the surrounding token's quote so
|
|
2538
|
+
// the completion survives client-side filtering.
|
|
2539
|
+
if (wrapQuoteCharacter !== quoteInfo.quoteCharacter) {
|
|
2540
|
+
completionItem.filterText = `${prefix}${quoteInfo.quoteCharacter}${value}${quoteInfo.quoteCharacter}`;
|
|
2541
|
+
}
|
|
2337
2542
|
let rangeStartCol = this.position.character;
|
|
2338
2543
|
if (quoteInfo.stringValue !== undefined) {
|
|
2339
|
-
rangeStartCol -= quoteInfo.stringValue.length + 1;
|
|
2544
|
+
rangeStartCol -= quoteInfo.stringValue.length + 1 + prefix.length;
|
|
2340
2545
|
}
|
|
2341
2546
|
else if (quoteInfo.priorWord) {
|
|
2342
2547
|
rangeStartCol -= quoteInfo.priorWord.length;
|
|
@@ -2405,7 +2610,9 @@ class CompletionProvider {
|
|
|
2405
2610
|
}
|
|
2406
2611
|
});
|
|
2407
2612
|
}
|
|
2408
|
-
|
|
2613
|
+
// Kept in place (rather than relocated above the private accessors) to minimize the subrepo diff.
|
|
2614
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
2615
|
+
findMatchingKeywords(keywordList, partialMatch) {
|
|
2409
2616
|
return keywordList.filter((keyword) => {
|
|
2410
2617
|
if (partialMatch) {
|
|
2411
2618
|
return StringUtils.isPatternInSymbol(partialMatch, keyword);
|
|
@@ -2443,7 +2650,7 @@ class CompletionProvider {
|
|
|
2443
2650
|
const completionItem = vscode_languageserver_1.CompletionItem.create(label);
|
|
2444
2651
|
completionItem.kind = vscode_languageserver_1.CompletionItemKind.Variable;
|
|
2445
2652
|
completionItem.data = this.createCompletionItemData({});
|
|
2446
|
-
completionItem.sortText = this.
|
|
2653
|
+
completionItem.sortText = this.makeSortText(SortCategory.NamedParameter, argName);
|
|
2447
2654
|
completionItem.filterText = argName;
|
|
2448
2655
|
// If the text immediately after the cursor already starts with
|
|
2449
2656
|
// `=`, extend the replacement range so we don't end up with
|
|
@@ -2469,14 +2676,16 @@ class CompletionProvider {
|
|
|
2469
2676
|
}
|
|
2470
2677
|
});
|
|
2471
2678
|
}
|
|
2472
|
-
|
|
2679
|
+
// Kept in place (rather than relocated above the private accessors) to minimize the subrepo diff.
|
|
2680
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
2681
|
+
addSymbols(node, priorWord, completionMap, includeSymbolCallback) {
|
|
2473
2682
|
let curNode = node;
|
|
2474
2683
|
while (curNode) {
|
|
2475
2684
|
// Does this node have a scope associated with it?
|
|
2476
|
-
let scope = (0, scopeUtils_1.getScopeForNode)(curNode);
|
|
2685
|
+
let scope = (0, scopeUtils_1.getScopeForNode)(curNode, this.nodeInfo);
|
|
2477
2686
|
if (scope) {
|
|
2478
2687
|
while (scope) {
|
|
2479
|
-
this._addSymbolsForSymbolTable(scope.symbolTable, () => true, priorWord, node,
|
|
2688
|
+
this._addSymbolsForSymbolTable(scope.symbolTable, includeSymbolCallback ?? (() => true), priorWord, node,
|
|
2480
2689
|
/* isInImport */ false,
|
|
2481
2690
|
/* boundObject */ undefined, completionMap);
|
|
2482
2691
|
scope = scope.parent;
|
|
@@ -2487,14 +2696,17 @@ class CompletionProvider {
|
|
|
2487
2696
|
if (classType && (0, types_1.isInstantiableClass)(classType.classType)) {
|
|
2488
2697
|
classType.classType.shared.mro.forEach((baseClass, index) => {
|
|
2489
2698
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
|
2490
|
-
this._addSymbolsForSymbolTable(types_1.ClassType.getSymbolTable(baseClass), (symbol) => {
|
|
2699
|
+
this._addSymbolsForSymbolTable(types_1.ClassType.getSymbolTable(baseClass), (symbol, name) => {
|
|
2491
2700
|
if (!symbol.isClassMember()) {
|
|
2492
2701
|
return false;
|
|
2493
2702
|
}
|
|
2494
2703
|
// Return only variables, not methods or classes.
|
|
2495
|
-
|
|
2704
|
+
if (!symbol
|
|
2496
2705
|
.getDeclarations()
|
|
2497
|
-
.some((decl) => decl.type === 1 /* DeclarationType.Variable */)
|
|
2706
|
+
.some((decl) => decl.type === 1 /* DeclarationType.Variable */)) {
|
|
2707
|
+
return false;
|
|
2708
|
+
}
|
|
2709
|
+
return includeSymbolCallback ? includeSymbolCallback(symbol, name) : true;
|
|
2498
2710
|
}, priorWord, node,
|
|
2499
2711
|
/* isInImport */ false,
|
|
2500
2712
|
/* boundObject */ undefined, completionMap);
|
|
@@ -2520,7 +2732,8 @@ class CompletionProvider {
|
|
|
2520
2732
|
// If there are no declarations or the symbol is not
|
|
2521
2733
|
// exported from this scope, don't include it in the
|
|
2522
2734
|
// suggestion list unless we are in the same file.
|
|
2523
|
-
const hidden = !(0, symbolUtils_1.isVisibleExternally)(symbol) &&
|
|
2735
|
+
const hidden = !(0, symbolUtils_1.isVisibleExternally)(symbol) &&
|
|
2736
|
+
!symbol.getDeclarations().some((d) => (0, declarationUtils_1.isDefinedInFile)(d, this.fileUri, this.nodeInfo));
|
|
2524
2737
|
if (!hidden && includeSymbolCallback(symbol, name)) {
|
|
2525
2738
|
// Don't add a symbol more than once. It may have already been
|
|
2526
2739
|
// added from an inner scope's symbol table.
|
|
@@ -2558,7 +2771,9 @@ class CompletionProvider {
|
|
|
2558
2771
|
_getRecentListIndex(name, autoImportText) {
|
|
2559
2772
|
return CompletionProvider._mostRecentCompletions.findIndex((item) => item.label === name && item.autoImportText === autoImportText);
|
|
2560
2773
|
}
|
|
2561
|
-
|
|
2774
|
+
// Kept in place (rather than relocated above the private accessors) to minimize the subrepo diff.
|
|
2775
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
2776
|
+
makeSortText(sortCategory, name, autoImportText = '') {
|
|
2562
2777
|
const recentListIndex = this._getRecentListIndex(name, autoImportText);
|
|
2563
2778
|
// If the label is in the recent list, modify the category
|
|
2564
2779
|
// so it appears higher in our list.
|
|
@@ -2665,7 +2880,7 @@ class CompletionProvider {
|
|
|
2665
2880
|
const keyword = 'import';
|
|
2666
2881
|
const completionItem = vscode_languageserver_1.CompletionItem.create(keyword);
|
|
2667
2882
|
completionItem.kind = vscode_languageserver_1.CompletionItemKind.Keyword;
|
|
2668
|
-
completionItem.sortText = this.
|
|
2883
|
+
completionItem.sortText = this.makeSortText(SortCategory.Keyword, keyword);
|
|
2669
2884
|
completionMap.set(completionItem);
|
|
2670
2885
|
}
|
|
2671
2886
|
completions.forEach((modulePath, completionName) => {
|
|
@@ -2673,7 +2888,7 @@ class CompletionProvider {
|
|
|
2673
2888
|
? SortCategory.PrivateSymbol
|
|
2674
2889
|
: SortCategory.ImportModuleName;
|
|
2675
2890
|
this.addNameToCompletions(completionName, vscode_languageserver_1.CompletionItemKind.Module, '', completionMap, {
|
|
2676
|
-
sortText: this.
|
|
2891
|
+
sortText: this.makeSortText(sortCategory, completionName),
|
|
2677
2892
|
moduleUri: modulePath,
|
|
2678
2893
|
});
|
|
2679
2894
|
});
|
|
@@ -2684,16 +2899,6 @@ class CompletionProvider {
|
|
|
2684
2899
|
// before doing more expensive type evaluation.
|
|
2685
2900
|
return decl.isMethod && decl.node.d.decorators.length > 0;
|
|
2686
2901
|
}
|
|
2687
|
-
_isEnumMember(containingType, name) {
|
|
2688
|
-
if (!containingType || !types_1.ClassType.isEnumClass(containingType)) {
|
|
2689
|
-
return false;
|
|
2690
|
-
}
|
|
2691
|
-
const symbolType = (0, enums_1.transformTypeForEnumMember)(this.evaluator, containingType, name);
|
|
2692
|
-
return (symbolType &&
|
|
2693
|
-
(0, types_1.isClassInstance)(symbolType) &&
|
|
2694
|
-
types_1.ClassType.isSameGenericClass(symbolType, types_1.TypeBase.isInstance(containingType) ? containingType : types_1.ClassType.cloneAsInstance(containingType)) &&
|
|
2695
|
-
symbolType.priv.literalValue instanceof types_1.EnumLiteral);
|
|
2696
|
-
}
|
|
2697
2902
|
}
|
|
2698
2903
|
exports.CompletionProvider = CompletionProvider;
|
|
2699
2904
|
CompletionProvider._mostRecentCompletions = [];
|