@zzzen/pyright-internal 1.2.0-dev.20230827 → 1.2.0-dev.20230910
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/binder.js +4 -1
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +40 -14
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +1 -2
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +5 -0
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +16 -7
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +2 -0
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +16 -1
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/deprecatedSymbols.js +13 -2
- package/dist/analyzer/deprecatedSymbols.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +6 -4
- package/dist/analyzer/importResolver.js +20 -18
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/namedTuples.js +1 -1
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.d.ts +3 -3
- package/dist/analyzer/packageTypeVerifier.js +8 -11
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parentDirectoryCache.js +1 -1
- package/dist/analyzer/parentDirectoryCache.js.map +1 -1
- package/dist/analyzer/program.d.ts +9 -22
- package/dist/analyzer/program.js +117 -105
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/protocols.js +3 -1
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.js +10 -8
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/service.d.ts +6 -3
- package/dist/analyzer/service.js +40 -20
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +6 -4
- package/dist/analyzer/sourceFile.js +9 -16
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfo.d.ts +62 -0
- package/dist/analyzer/sourceFileInfo.js +145 -0
- package/dist/analyzer/sourceFileInfo.js.map +1 -0
- package/dist/analyzer/sourceMapper.d.ts +1 -1
- package/dist/analyzer/typeDocStringUtils.js +1 -1
- package/dist/analyzer/typeEvaluator.js +361 -262
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +10 -8
- package/dist/analyzer/typeEvaluatorTypes.js +11 -8
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +116 -20
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +6 -4
- package/dist/analyzer/typeUtils.js +104 -63
- 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/types.d.ts +1 -0
- package/dist/analyzer/types.js +8 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysis.d.ts +1 -2
- package/dist/backgroundAnalysis.js +2 -2
- package/dist/backgroundAnalysis.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +1 -2
- package/dist/backgroundAnalysisBase.js +4 -4
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +1 -1
- package/dist/backgroundThreadBase.js +1 -0
- package/dist/backgroundThreadBase.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 +18 -5
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/console.d.ts +3 -0
- package/dist/common/console.js +8 -1
- package/dist/common/console.js.map +1 -1
- package/dist/common/extensibility.d.ts +10 -1
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileSystem.d.ts +3 -0
- package/dist/common/fileSystem.js +8 -1
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/pathUtils.d.ts +2 -15
- package/dist/common/pathUtils.js +9 -84
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.js +22 -13
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProvider.d.ts +1 -4
- package/dist/common/serviceProvider.js +4 -4
- package/dist/common/serviceProvider.js.map +1 -1
- package/dist/common/serviceProviderExtensions.d.ts +10 -4
- package/dist/common/serviceProviderExtensions.js +43 -1
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/languageServerBase.d.ts +9 -9
- package/dist/languageServerBase.js +5 -4
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.js +3 -2
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +7 -5
- package/dist/languageService/completionProvider.js +190 -176
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.d.ts +1 -1
- package/dist/languageService/completionProviderUtils.js +1 -1
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +14 -0
- package/dist/localization/localize.js +8 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +26 -17
- package/dist/localization/package.nls.de.json +26 -17
- package/dist/localization/package.nls.en-us.json +9 -2
- package/dist/localization/package.nls.es.json +26 -17
- package/dist/localization/package.nls.fr.json +26 -17
- package/dist/localization/package.nls.it.json +26 -17
- package/dist/localization/package.nls.ja.json +26 -17
- package/dist/localization/package.nls.ko.json +26 -17
- package/dist/localization/package.nls.pl.json +26 -17
- package/dist/localization/package.nls.pt-br.json +26 -17
- package/dist/localization/package.nls.qps-ploc.json +14 -5
- package/dist/localization/package.nls.ru.json +26 -17
- package/dist/localization/package.nls.tr.json +26 -17
- package/dist/localization/package.nls.zh-cn.json +26 -17
- package/dist/localization/package.nls.zh-tw.json +26 -17
- package/dist/pyright.js +6 -4
- package/dist/pyright.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +8 -10
- package/dist/server.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +4 -1
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/checker.test.js +11 -11
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/completions.test.js +57 -0
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/config.test.js +28 -22
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js +5 -5
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js +11 -9
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js +14 -14
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js +12 -12
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js +9 -9
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js +3 -3
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js +3 -3
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js +4 -4
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js.map +1 -1
- package/dist/tests/fourslash/fourslash.d.ts +1 -0
- package/dist/tests/fourslash/missingModuleSource.fourslash.js +4 -1
- package/dist/tests/fourslash/missingModuleSource.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +4 -1
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.Consts.d.ts +1 -0
- package/dist/tests/harness/fourslash/testState.Consts.js +2 -0
- package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +2 -0
- package/dist/tests/harness/fourslash/testState.js +9 -2
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.js +10 -6
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +14 -9
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/localizer.test.js +1 -1
- package/dist/tests/localizer.test.js.map +1 -1
- package/dist/tests/pathUtils.test.js +13 -21
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/service.test.js +55 -0
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +4 -2
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/testState.test.js +1 -1
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/testUtils.js +3 -5
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +2 -2
- package/dist/tests/typeEvaluator2.test.js +5 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +8 -4
- 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 +1 -1
- package/dist/tests/workspaceEditUtils.test.js +24 -20
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +1 -0
- package/dist/workspaceFactory.js +7 -4
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
@@ -28,7 +28,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
28
28
|
return result;
|
29
29
|
};
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
31
|
-
exports.CompletionMap = exports.CompletionProvider = exports.
|
31
|
+
exports.CompletionMap = exports.CompletionProvider = exports.indexValueDetail = exports.autoImportDetail = void 0;
|
32
32
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
33
33
|
const AnalyzerNodeInfo = __importStar(require("../analyzer/analyzerNodeInfo"));
|
34
34
|
const declaration_1 = require("../analyzer/declaration");
|
@@ -61,6 +61,7 @@ const autoImporter_1 = require("./autoImporter");
|
|
61
61
|
const completionProviderUtils_1 = require("./completionProviderUtils");
|
62
62
|
const documentSymbolCollector_1 = require("./documentSymbolCollector");
|
63
63
|
const tooltipUtils_1 = require("./tooltipUtils");
|
64
|
+
const localize_1 = require("../localization/localize");
|
64
65
|
var Keywords;
|
65
66
|
(function (Keywords) {
|
66
67
|
const base = [
|
@@ -145,8 +146,8 @@ var SortCategory;
|
|
145
146
|
// An auto-import symbol.
|
146
147
|
SortCategory[SortCategory["AutoImport"] = 12] = "AutoImport";
|
147
148
|
})(SortCategory || (SortCategory = {}));
|
148
|
-
exports.autoImportDetail =
|
149
|
-
exports.
|
149
|
+
exports.autoImportDetail = localize_1.Localizer.Completion.autoImportDetail();
|
150
|
+
exports.indexValueDetail = localize_1.Localizer.Completion.indexValueDetail();
|
150
151
|
// We'll use a somewhat-arbitrary cutoff value here to determine
|
151
152
|
// whether it's sufficiently similar.
|
152
153
|
const similarityLimit = 0.25;
|
@@ -405,6 +406,10 @@ class CompletionProvider {
|
|
405
406
|
};
|
406
407
|
return vscode_languageserver_1.TextEdit.replace(range, text);
|
407
408
|
}
|
409
|
+
shouldProcessDeclaration(declaration) {
|
410
|
+
// By default, we allow all symbol/decl to be included in the completion.
|
411
|
+
return true;
|
412
|
+
}
|
408
413
|
addSymbol(name, symbol, priorWord, completionMap, detail) {
|
409
414
|
var _a, _b, _c, _d;
|
410
415
|
// Make sure we don't crash due to OOM.
|
@@ -416,6 +421,9 @@ class CompletionProvider {
|
|
416
421
|
primaryDecl = declarations[declarations.length - 1];
|
417
422
|
}
|
418
423
|
}
|
424
|
+
if (!this.shouldProcessDeclaration(primaryDecl)) {
|
425
|
+
return;
|
426
|
+
}
|
419
427
|
primaryDecl = primaryDecl
|
420
428
|
? (_a = this.evaluator.resolveAliasDeclaration(primaryDecl, /* resolveLocalNames */ true)) !== null && _a !== void 0 ? _a : primaryDecl
|
421
429
|
: undefined;
|
@@ -444,7 +452,7 @@ class CompletionProvider {
|
|
444
452
|
// Can't resolve. so bail out.
|
445
453
|
return;
|
446
454
|
}
|
447
|
-
const typeDetail = (0, completionProviderUtils_1.getTypeDetail)(this.evaluator,
|
455
|
+
const typeDetail = (0, completionProviderUtils_1.getTypeDetail)(this.evaluator, type, primaryDecl, name, detail, this.configOptions.functionSignatureDisplay);
|
448
456
|
const documentation = (0, tooltipUtils_1.getDocumentationPartsForTypeAndDecl)(this.sourceMapper, type, primaryDecl, this.evaluator, {
|
449
457
|
name,
|
450
458
|
symbol,
|
@@ -471,7 +479,7 @@ class CompletionProvider {
|
|
471
479
|
((_c = primaryDecl.node.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* Assignment */) {
|
472
480
|
itemKind = vscode_languageserver_1.CompletionItemKind.EnumMember;
|
473
481
|
}
|
474
|
-
this.
|
482
|
+
this.addNameToCompletions((_d = detail.autoImportAlias) !== null && _d !== void 0 ? _d : name, itemKind, priorWord, completionMap, {
|
475
483
|
autoImportText,
|
476
484
|
extraCommitChars: detail.extraCommitChars,
|
477
485
|
funcParensDisabled: detail.funcParensDisabled,
|
@@ -483,7 +491,7 @@ class CompletionProvider {
|
|
483
491
|
const synthesizedType = symbol.getSynthesizedType();
|
484
492
|
if (synthesizedType) {
|
485
493
|
const itemKind = this._convertTypeToItemKind(synthesizedType);
|
486
|
-
this.
|
494
|
+
this.addNameToCompletions(name, itemKind, priorWord, completionMap, {
|
487
495
|
extraCommitChars: detail.extraCommitChars,
|
488
496
|
funcParensDisabled: detail.funcParensDisabled,
|
489
497
|
edits: detail.edits,
|
@@ -572,7 +580,7 @@ class CompletionProvider {
|
|
572
580
|
});
|
573
581
|
}
|
574
582
|
else {
|
575
|
-
this.
|
583
|
+
this.addNameToCompletions((_a = result.alias) !== null && _a !== void 0 ? _a : result.name, (_b = result.kind) !== null && _b !== void 0 ? _b : vscode_languageserver_1.CompletionItemKind.Module, priorWord, completionMap, {
|
576
584
|
extraCommitChars: true,
|
577
585
|
autoImportText: this._getAutoImportText(result.name, result.source, result.alias),
|
578
586
|
edits: {
|
@@ -589,6 +597,132 @@ class CompletionProvider {
|
|
589
597
|
addExtraCommitChar(item) {
|
590
598
|
// extra commit char is not supported.
|
591
599
|
}
|
600
|
+
addNameToCompletions(name, itemKind, filter, completionMap, detail) {
|
601
|
+
var _a, _b, _c, _d;
|
602
|
+
// Auto importer already filtered out unnecessary ones. No need to do it again.
|
603
|
+
const similarity = (detail === null || detail === void 0 ? void 0 : detail.autoImportText) ? true : StringUtils.isPatternInSymbol(filter, name);
|
604
|
+
if (!similarity) {
|
605
|
+
return;
|
606
|
+
}
|
607
|
+
if (completionMap.has(name, CompletionMap.matchKindAndImportText, itemKind, (_a = detail === null || detail === void 0 ? void 0 : detail.autoImportText) === null || _a === void 0 ? void 0 : _a.importText)) {
|
608
|
+
return;
|
609
|
+
}
|
610
|
+
const completionItem = vscode_languageserver_1.CompletionItem.create(name);
|
611
|
+
completionItem.kind = itemKind;
|
612
|
+
if (detail === null || detail === void 0 ? void 0 : detail.extraCommitChars) {
|
613
|
+
this.addExtraCommitChar(completionItem);
|
614
|
+
}
|
615
|
+
const completionItemData = {
|
616
|
+
workspacePath: this._workspacePath,
|
617
|
+
filePath: this.filePath,
|
618
|
+
position: this.position,
|
619
|
+
};
|
620
|
+
if ((detail === null || detail === void 0 ? void 0 : detail.funcParensDisabled) || !this.options.snippet) {
|
621
|
+
completionItemData.funcParensDisabled = true;
|
622
|
+
}
|
623
|
+
if (detail === null || detail === void 0 ? void 0 : detail.modulePath) {
|
624
|
+
completionItemData.modulePath = detail.modulePath;
|
625
|
+
}
|
626
|
+
completionItem.data = (0, lspUtils_1.toLSPAny)(completionItemData);
|
627
|
+
if ((detail === null || detail === void 0 ? void 0 : detail.sortText) || (detail === null || detail === void 0 ? void 0 : detail.itemDetail)) {
|
628
|
+
completionItem.sortText = detail.sortText;
|
629
|
+
completionItem.detail = detail.itemDetail;
|
630
|
+
}
|
631
|
+
else if (detail === null || detail === void 0 ? void 0 : detail.autoImportText) {
|
632
|
+
// Force auto-import entries to the end.
|
633
|
+
completionItem.sortText = this._makeSortText(SortCategory.AutoImport, `${name}.${this._formatInteger(detail.autoImportText.source.length, 2)}.${detail.autoImportText.source}`, detail.autoImportText.importText);
|
634
|
+
completionItemData.autoImportText = detail.autoImportText.importText;
|
635
|
+
completionItem.detail = exports.autoImportDetail;
|
636
|
+
if (detail.autoImportText.source) {
|
637
|
+
completionItem.labelDetails = { description: detail.autoImportText.source };
|
638
|
+
}
|
639
|
+
}
|
640
|
+
else if (itemKind === vscode_languageserver_1.CompletionItemKind.EnumMember) {
|
641
|
+
// Handle enum members separately so they are sorted above other symbols.
|
642
|
+
completionItem.sortText = this._makeSortText(SortCategory.EnumMember, name);
|
643
|
+
}
|
644
|
+
else if (SymbolNameUtils.isDunderName(name)) {
|
645
|
+
// Force dunder-named symbols to appear after all other symbols.
|
646
|
+
completionItem.sortText = this._makeSortText(SortCategory.DunderSymbol, name);
|
647
|
+
}
|
648
|
+
else if (filter === '' && SymbolNameUtils.isPrivateOrProtectedName(name)) {
|
649
|
+
// Distinguish between normal and private symbols only if there is
|
650
|
+
// currently no filter text. Once we get a single character to filter
|
651
|
+
// upon, we'll no longer differentiate.
|
652
|
+
completionItem.sortText = this._makeSortText(SortCategory.PrivateSymbol, name);
|
653
|
+
}
|
654
|
+
else {
|
655
|
+
completionItem.sortText = this._makeSortText(SortCategory.NormalSymbol, name);
|
656
|
+
}
|
657
|
+
completionItemData.symbolLabel = name;
|
658
|
+
if (this.options.format === vscode_languageserver_1.MarkupKind.Markdown) {
|
659
|
+
let markdownString = '';
|
660
|
+
if (detail === null || detail === void 0 ? void 0 : detail.autoImportText) {
|
661
|
+
markdownString += detail.autoImportText.importText;
|
662
|
+
if (detail.typeDetail || detail.documentation) {
|
663
|
+
// Micro perf optimization to not create new string from trimEnd.
|
664
|
+
markdownString += '\n\n';
|
665
|
+
}
|
666
|
+
}
|
667
|
+
if (detail === null || detail === void 0 ? void 0 : detail.typeDetail) {
|
668
|
+
markdownString += '```python\n' + detail.typeDetail + '\n```\n';
|
669
|
+
}
|
670
|
+
if (detail === null || detail === void 0 ? void 0 : detail.documentation) {
|
671
|
+
markdownString += '---\n';
|
672
|
+
markdownString += (0, docStringConversion_1.convertDocStringToMarkdown)(detail.documentation);
|
673
|
+
}
|
674
|
+
markdownString = markdownString.trimEnd();
|
675
|
+
if (markdownString) {
|
676
|
+
completionItem.documentation = {
|
677
|
+
kind: vscode_languageserver_1.MarkupKind.Markdown,
|
678
|
+
value: markdownString,
|
679
|
+
};
|
680
|
+
}
|
681
|
+
}
|
682
|
+
else if (this.options.format === vscode_languageserver_1.MarkupKind.PlainText) {
|
683
|
+
let plainTextString = '';
|
684
|
+
if (detail === null || detail === void 0 ? void 0 : detail.autoImportText) {
|
685
|
+
plainTextString += detail.autoImportText.importText;
|
686
|
+
if (detail.typeDetail || detail.documentation) {
|
687
|
+
// Micro perf optimization to not create new string from trimEnd.
|
688
|
+
plainTextString += '\n\n';
|
689
|
+
}
|
690
|
+
}
|
691
|
+
if (detail === null || detail === void 0 ? void 0 : detail.typeDetail) {
|
692
|
+
plainTextString += detail.typeDetail + '\n';
|
693
|
+
}
|
694
|
+
if (detail === null || detail === void 0 ? void 0 : detail.documentation) {
|
695
|
+
plainTextString += '\n' + (0, docStringConversion_1.convertDocStringToPlainText)(detail.documentation);
|
696
|
+
}
|
697
|
+
plainTextString = plainTextString.trimEnd();
|
698
|
+
if (plainTextString) {
|
699
|
+
completionItem.documentation = {
|
700
|
+
kind: vscode_languageserver_1.MarkupKind.PlainText,
|
701
|
+
value: plainTextString,
|
702
|
+
};
|
703
|
+
}
|
704
|
+
}
|
705
|
+
else {
|
706
|
+
(0, debug_1.fail)(`Unsupported markup type: ${this.options.format}`);
|
707
|
+
}
|
708
|
+
if ((_b = detail === null || detail === void 0 ? void 0 : detail.edits) === null || _b === void 0 ? void 0 : _b.format) {
|
709
|
+
completionItem.insertTextFormat = detail.edits.format;
|
710
|
+
}
|
711
|
+
if ((_c = detail === null || detail === void 0 ? void 0 : detail.edits) === null || _c === void 0 ? void 0 : _c.textEdit) {
|
712
|
+
completionItem.textEdit = detail.edits.textEdit;
|
713
|
+
}
|
714
|
+
if ((_d = detail === null || detail === void 0 ? void 0 : detail.edits) === null || _d === void 0 ? void 0 : _d.additionalTextEdits) {
|
715
|
+
completionItem.additionalTextEdits = (0, workspaceEditUtils_1.convertToTextEdits)(detail.edits.additionalTextEdits);
|
716
|
+
// This is for auto import entries from indices which skip symbols.
|
717
|
+
if (this._itemToResolve) {
|
718
|
+
const data = (0, lspUtils_1.fromLSPAny)(this._itemToResolve.data);
|
719
|
+
if (data.autoImportText === completionItemData.autoImportText) {
|
720
|
+
this._itemToResolve.additionalTextEdits = completionItem.additionalTextEdits;
|
721
|
+
}
|
722
|
+
}
|
723
|
+
}
|
724
|
+
completionMap.set(completionItem);
|
725
|
+
}
|
592
726
|
get _fileContents() {
|
593
727
|
var _a, _b;
|
594
728
|
return (_b = (_a = this.parseResults) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : '';
|
@@ -1037,7 +1171,7 @@ class CompletionProvider {
|
|
1037
1171
|
enforcePythonSyntax: true,
|
1038
1172
|
expandTypeAlias: false,
|
1039
1173
|
});
|
1040
|
-
this.
|
1174
|
+
this.addNameToCompletions(text, vscode_languageserver_1.CompletionItemKind.Reference, priorWord, completionMap, {
|
1041
1175
|
sortText: this._makeSortText(SortCategory.LikelyKeyword, text),
|
1042
1176
|
});
|
1043
1177
|
return;
|
@@ -1074,7 +1208,7 @@ class CompletionProvider {
|
|
1074
1208
|
2 /* DoNotLimitStringLength */
|
1075
1209
|
: 2 /* DoNotLimitStringLength */;
|
1076
1210
|
const text = `${ParseTreeUtils.printExpression(declWithTypeAnnotations[declWithTypeAnnotations.length - 1].typeAnnotationNode, printFlags)}`;
|
1077
|
-
this.
|
1211
|
+
this.addNameToCompletions(text, vscode_languageserver_1.CompletionItemKind.Reference, priorWord, completionMap, {
|
1078
1212
|
sortText: this._makeSortText(SortCategory.LikelyKeyword, text),
|
1079
1213
|
});
|
1080
1214
|
}
|
@@ -1326,7 +1460,7 @@ class CompletionProvider {
|
|
1326
1460
|
if (types_1.ClassType.isBuiltIn(v, 'str')) {
|
1327
1461
|
const value = (0, typePrinter_1.printLiteralValue)(v, quoteValue.quoteCharacter);
|
1328
1462
|
if (quoteValue.stringValue === undefined) {
|
1329
|
-
this.
|
1463
|
+
this.addNameToCompletions(value, vscode_languageserver_1.CompletionItemKind.Constant, priorWord, completionMap, {
|
1330
1464
|
sortText: this._makeSortText(SortCategory.LiteralValue, v.literalValue),
|
1331
1465
|
});
|
1332
1466
|
}
|
@@ -1518,7 +1652,7 @@ class CompletionProvider {
|
|
1518
1652
|
: undefined;
|
1519
1653
|
if (nodeForExpectedType) {
|
1520
1654
|
const expectedTypeResult = this.evaluator.getExpectedType(nodeForExpectedType);
|
1521
|
-
if (expectedTypeResult && (0, typeUtils_1.
|
1655
|
+
if (expectedTypeResult && (0, typeUtils_1.containsLiteralType)(expectedTypeResult.type)) {
|
1522
1656
|
this._addLiteralValuesForTargetType(expectedTypeResult.type, priorWord, priorText, postText, completionMap);
|
1523
1657
|
return true;
|
1524
1658
|
}
|
@@ -1569,12 +1703,12 @@ class CompletionProvider {
|
|
1569
1703
|
keyFound = true;
|
1570
1704
|
if (stringLiteral) {
|
1571
1705
|
const keyWithoutQuote = key.substr(1, key.length - 2);
|
1572
|
-
this._addStringLiteralToCompletions(keyWithoutQuote, quoteInfo, postText, completionMap, exports.
|
1706
|
+
this._addStringLiteralToCompletions(keyWithoutQuote, quoteInfo, postText, completionMap, exports.indexValueDetail);
|
1573
1707
|
}
|
1574
1708
|
else {
|
1575
|
-
this.
|
1709
|
+
this.addNameToCompletions(key, vscode_languageserver_1.CompletionItemKind.Constant, priorWord, completionMap, {
|
1576
1710
|
sortText: this._makeSortText(SortCategory.LiteralValue, key),
|
1577
|
-
itemDetail: exports.
|
1711
|
+
itemDetail: exports.indexValueDetail,
|
1578
1712
|
});
|
1579
1713
|
}
|
1580
1714
|
}
|
@@ -1587,7 +1721,7 @@ class CompletionProvider {
|
|
1587
1721
|
const supportedOperators = [2 /* Assign */, 12 /* Equals */, 28 /* NotEquals */];
|
1588
1722
|
if (comparison.nodeType === 7 /* BinaryOperation */ && supportedOperators.includes(comparison.operator)) {
|
1589
1723
|
const type = this.evaluator.getType(comparison.leftExpression);
|
1590
|
-
if (type && (0, typeUtils_1.
|
1724
|
+
if (type && (0, typeUtils_1.containsLiteralType)(type)) {
|
1591
1725
|
this._addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
1592
1726
|
return true;
|
1593
1727
|
}
|
@@ -1597,7 +1731,7 @@ class CompletionProvider {
|
|
1597
1731
|
if (assignmentExpression.nodeType === 4 /* AssignmentExpression */ &&
|
1598
1732
|
assignmentExpression.rightExpression === parentAndChild.child) {
|
1599
1733
|
const type = this.evaluator.getType(assignmentExpression.name);
|
1600
|
-
if (type && (0, typeUtils_1.
|
1734
|
+
if (type && (0, typeUtils_1.containsLiteralType)(type)) {
|
1601
1735
|
this._addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
1602
1736
|
return true;
|
1603
1737
|
}
|
@@ -1612,7 +1746,7 @@ class CompletionProvider {
|
|
1612
1746
|
caseNode.suite === parentAndChild.child &&
|
1613
1747
|
((_c = caseNode.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 63 /* Match */) {
|
1614
1748
|
const type = this.evaluator.getType(caseNode.parent.subjectExpression);
|
1615
|
-
if (type && (0, typeUtils_1.
|
1749
|
+
if (type && (0, typeUtils_1.containsLiteralType)(type)) {
|
1616
1750
|
this._addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
1617
1751
|
return true;
|
1618
1752
|
}
|
@@ -1627,7 +1761,7 @@ class CompletionProvider {
|
|
1627
1761
|
((_e = patternLiteral.parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 64 /* Case */ &&
|
1628
1762
|
((_f = patternLiteral.parent.parent.parent) === null || _f === void 0 ? void 0 : _f.nodeType) === 63 /* Match */) {
|
1629
1763
|
const type = this.evaluator.getType(patternLiteral.parent.parent.parent.subjectExpression);
|
1630
|
-
if (type && (0, typeUtils_1.
|
1764
|
+
if (type && (0, typeUtils_1.containsLiteralType)(type)) {
|
1631
1765
|
this._addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
1632
1766
|
return true;
|
1633
1767
|
}
|
@@ -1766,37 +1900,38 @@ class CompletionProvider {
|
|
1766
1900
|
return this._tryAddTypedDictKeys(baseType, [], priorWord, priorText, postText, completionMap);
|
1767
1901
|
}
|
1768
1902
|
_addStringLiteralToCompletions(value, quoteInfo, postText, completionMap, detail) {
|
1769
|
-
if (StringUtils.isPatternInSymbol(quoteInfo.filterText || '', value)) {
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1903
|
+
if (!StringUtils.isPatternInSymbol(quoteInfo.filterText || '', value)) {
|
1904
|
+
return;
|
1905
|
+
}
|
1906
|
+
const valueWithQuotes = `${quoteInfo.quoteCharacter}${value}${quoteInfo.quoteCharacter}`;
|
1907
|
+
if (completionMap.has(valueWithQuotes)) {
|
1908
|
+
return;
|
1909
|
+
}
|
1910
|
+
const completionItem = vscode_languageserver_1.CompletionItem.create(valueWithQuotes);
|
1911
|
+
completionItem.kind = vscode_languageserver_1.CompletionItemKind.Constant;
|
1912
|
+
completionItem.sortText = this._makeSortText(SortCategory.LiteralValue, valueWithQuotes);
|
1913
|
+
let rangeStartCol = this.position.character;
|
1914
|
+
if (quoteInfo.stringValue !== undefined) {
|
1915
|
+
rangeStartCol -= quoteInfo.stringValue.length + 1;
|
1916
|
+
}
|
1917
|
+
else if (quoteInfo.priorWord) {
|
1918
|
+
rangeStartCol -= quoteInfo.priorWord.length;
|
1919
|
+
}
|
1920
|
+
// If the text after the insertion point is the closing quote,
|
1921
|
+
// replace it.
|
1922
|
+
let rangeEndCol = this.position.character;
|
1923
|
+
if (postText !== undefined) {
|
1924
|
+
if (postText.startsWith(quoteInfo.quoteCharacter)) {
|
1925
|
+
rangeEndCol++;
|
1791
1926
|
}
|
1792
|
-
const range = {
|
1793
|
-
start: { line: this.position.line, character: rangeStartCol },
|
1794
|
-
end: { line: this.position.line, character: rangeEndCol },
|
1795
|
-
};
|
1796
|
-
completionItem.textEdit = vscode_languageserver_1.TextEdit.replace(range, valueWithQuotes);
|
1797
|
-
completionItem.detail = detail;
|
1798
|
-
completionMap.set(completionItem);
|
1799
1927
|
}
|
1928
|
+
const range = {
|
1929
|
+
start: { line: this.position.line, character: rangeStartCol },
|
1930
|
+
end: { line: this.position.line, character: rangeEndCol },
|
1931
|
+
};
|
1932
|
+
completionItem.textEdit = vscode_languageserver_1.TextEdit.replace(range, valueWithQuotes);
|
1933
|
+
completionItem.detail = detail;
|
1934
|
+
completionMap.set(completionItem);
|
1800
1935
|
}
|
1801
1936
|
_getImportFromCompletions(importFromNode, priorWord) {
|
1802
1937
|
var _a;
|
@@ -1814,6 +1949,8 @@ class CompletionProvider {
|
|
1814
1949
|
const resolvedPath = importInfo.resolvedPaths.length > 0 ? importInfo.resolvedPaths[importInfo.resolvedPaths.length - 1] : '';
|
1815
1950
|
const parseResults = this.program.getParseResults(resolvedPath);
|
1816
1951
|
if (!parseResults) {
|
1952
|
+
// Add the implicit imports.
|
1953
|
+
this._addImplicitImportsToCompletion(importInfo, importFromNode, priorWord, completionMap);
|
1817
1954
|
return completionMap;
|
1818
1955
|
}
|
1819
1956
|
const symbolTable = (_a = AnalyzerNodeInfo.getScope(parseResults.parseTree)) === null || _a === void 0 ? void 0 : _a.symbolTable;
|
@@ -1828,14 +1965,17 @@ class CompletionProvider {
|
|
1828
1965
|
/* isInImport */ true,
|
1829
1966
|
/* boundObject */ undefined, completionMap);
|
1830
1967
|
// Add the implicit imports.
|
1968
|
+
this._addImplicitImportsToCompletion(importInfo, importFromNode, priorWord, completionMap);
|
1969
|
+
return completionMap;
|
1970
|
+
}
|
1971
|
+
_addImplicitImportsToCompletion(importInfo, importFromNode, priorWord, completionMap) {
|
1831
1972
|
importInfo.implicitImports.forEach((implImport) => {
|
1832
1973
|
if (!importFromNode.imports.find((imp) => imp.name.value === implImport.name)) {
|
1833
|
-
this.
|
1974
|
+
this.addNameToCompletions(implImport.name, vscode_languageserver_1.CompletionItemKind.Module, priorWord, completionMap, {
|
1834
1975
|
modulePath: implImport.path,
|
1835
1976
|
});
|
1836
1977
|
}
|
1837
1978
|
});
|
1838
|
-
return completionMap;
|
1839
1979
|
}
|
1840
1980
|
_findMatchingKeywords(keywordList, partialMatch) {
|
1841
1981
|
return keywordList.filter((keyword) => {
|
@@ -1991,132 +2131,6 @@ class CompletionProvider {
|
|
1991
2131
|
importText,
|
1992
2132
|
};
|
1993
2133
|
}
|
1994
|
-
_addNameToCompletions(name, itemKind, filter, completionMap, detail) {
|
1995
|
-
var _a, _b, _c, _d;
|
1996
|
-
// Auto importer already filtered out unnecessary ones. No need to do it again.
|
1997
|
-
const similarity = (detail === null || detail === void 0 ? void 0 : detail.autoImportText) ? true : StringUtils.isPatternInSymbol(filter, name);
|
1998
|
-
if (!similarity) {
|
1999
|
-
return;
|
2000
|
-
}
|
2001
|
-
if (completionMap.has(name, CompletionMap.matchKindAndImportText, itemKind, (_a = detail === null || detail === void 0 ? void 0 : detail.autoImportText) === null || _a === void 0 ? void 0 : _a.importText)) {
|
2002
|
-
return;
|
2003
|
-
}
|
2004
|
-
const completionItem = vscode_languageserver_1.CompletionItem.create(name);
|
2005
|
-
completionItem.kind = itemKind;
|
2006
|
-
if (detail === null || detail === void 0 ? void 0 : detail.extraCommitChars) {
|
2007
|
-
this.addExtraCommitChar(completionItem);
|
2008
|
-
}
|
2009
|
-
const completionItemData = {
|
2010
|
-
workspacePath: this._workspacePath,
|
2011
|
-
filePath: this.filePath,
|
2012
|
-
position: this.position,
|
2013
|
-
};
|
2014
|
-
if ((detail === null || detail === void 0 ? void 0 : detail.funcParensDisabled) || !this.options.snippet) {
|
2015
|
-
completionItemData.funcParensDisabled = true;
|
2016
|
-
}
|
2017
|
-
if (detail === null || detail === void 0 ? void 0 : detail.modulePath) {
|
2018
|
-
completionItemData.modulePath = detail.modulePath;
|
2019
|
-
}
|
2020
|
-
completionItem.data = (0, lspUtils_1.toLSPAny)(completionItemData);
|
2021
|
-
if ((detail === null || detail === void 0 ? void 0 : detail.sortText) || (detail === null || detail === void 0 ? void 0 : detail.itemDetail)) {
|
2022
|
-
completionItem.sortText = detail.sortText;
|
2023
|
-
completionItem.detail = detail.itemDetail;
|
2024
|
-
}
|
2025
|
-
else if (detail === null || detail === void 0 ? void 0 : detail.autoImportText) {
|
2026
|
-
// Force auto-import entries to the end.
|
2027
|
-
completionItem.sortText = this._makeSortText(SortCategory.AutoImport, `${name}.${this._formatInteger(detail.autoImportText.source.length, 2)}.${detail.autoImportText.source}`, detail.autoImportText.importText);
|
2028
|
-
completionItemData.autoImportText = detail.autoImportText.importText;
|
2029
|
-
completionItem.detail = exports.autoImportDetail;
|
2030
|
-
if (detail.autoImportText.source) {
|
2031
|
-
completionItem.labelDetails = { description: detail.autoImportText.source };
|
2032
|
-
}
|
2033
|
-
}
|
2034
|
-
else if (itemKind === vscode_languageserver_1.CompletionItemKind.EnumMember) {
|
2035
|
-
// Handle enum members separately so they are sorted above other symbols.
|
2036
|
-
completionItem.sortText = this._makeSortText(SortCategory.EnumMember, name);
|
2037
|
-
}
|
2038
|
-
else if (SymbolNameUtils.isDunderName(name)) {
|
2039
|
-
// Force dunder-named symbols to appear after all other symbols.
|
2040
|
-
completionItem.sortText = this._makeSortText(SortCategory.DunderSymbol, name);
|
2041
|
-
}
|
2042
|
-
else if (filter === '' && SymbolNameUtils.isPrivateOrProtectedName(name)) {
|
2043
|
-
// Distinguish between normal and private symbols only if there is
|
2044
|
-
// currently no filter text. Once we get a single character to filter
|
2045
|
-
// upon, we'll no longer differentiate.
|
2046
|
-
completionItem.sortText = this._makeSortText(SortCategory.PrivateSymbol, name);
|
2047
|
-
}
|
2048
|
-
else {
|
2049
|
-
completionItem.sortText = this._makeSortText(SortCategory.NormalSymbol, name);
|
2050
|
-
}
|
2051
|
-
completionItemData.symbolLabel = name;
|
2052
|
-
if (this.options.format === vscode_languageserver_1.MarkupKind.Markdown) {
|
2053
|
-
let markdownString = '';
|
2054
|
-
if (detail === null || detail === void 0 ? void 0 : detail.autoImportText) {
|
2055
|
-
markdownString += detail.autoImportText.importText;
|
2056
|
-
if (detail.typeDetail || detail.documentation) {
|
2057
|
-
// Micro perf optimization to not create new string from trimEnd.
|
2058
|
-
markdownString += '\n\n';
|
2059
|
-
}
|
2060
|
-
}
|
2061
|
-
if (detail === null || detail === void 0 ? void 0 : detail.typeDetail) {
|
2062
|
-
markdownString += '```python\n' + detail.typeDetail + '\n```\n';
|
2063
|
-
}
|
2064
|
-
if (detail === null || detail === void 0 ? void 0 : detail.documentation) {
|
2065
|
-
markdownString += '---\n';
|
2066
|
-
markdownString += (0, docStringConversion_1.convertDocStringToMarkdown)(detail.documentation);
|
2067
|
-
}
|
2068
|
-
markdownString = markdownString.trimEnd();
|
2069
|
-
if (markdownString) {
|
2070
|
-
completionItem.documentation = {
|
2071
|
-
kind: vscode_languageserver_1.MarkupKind.Markdown,
|
2072
|
-
value: markdownString,
|
2073
|
-
};
|
2074
|
-
}
|
2075
|
-
}
|
2076
|
-
else if (this.options.format === vscode_languageserver_1.MarkupKind.PlainText) {
|
2077
|
-
let plainTextString = '';
|
2078
|
-
if (detail === null || detail === void 0 ? void 0 : detail.autoImportText) {
|
2079
|
-
plainTextString += detail.autoImportText.importText;
|
2080
|
-
if (detail.typeDetail || detail.documentation) {
|
2081
|
-
// Micro perf optimization to not create new string from trimEnd.
|
2082
|
-
plainTextString += '\n\n';
|
2083
|
-
}
|
2084
|
-
}
|
2085
|
-
if (detail === null || detail === void 0 ? void 0 : detail.typeDetail) {
|
2086
|
-
plainTextString += detail.typeDetail + '\n';
|
2087
|
-
}
|
2088
|
-
if (detail === null || detail === void 0 ? void 0 : detail.documentation) {
|
2089
|
-
plainTextString += '\n' + (0, docStringConversion_1.convertDocStringToPlainText)(detail.documentation);
|
2090
|
-
}
|
2091
|
-
plainTextString = plainTextString.trimEnd();
|
2092
|
-
if (plainTextString) {
|
2093
|
-
completionItem.documentation = {
|
2094
|
-
kind: vscode_languageserver_1.MarkupKind.PlainText,
|
2095
|
-
value: plainTextString,
|
2096
|
-
};
|
2097
|
-
}
|
2098
|
-
}
|
2099
|
-
else {
|
2100
|
-
(0, debug_1.fail)(`Unsupported markup type: ${this.options.format}`);
|
2101
|
-
}
|
2102
|
-
if ((_b = detail === null || detail === void 0 ? void 0 : detail.edits) === null || _b === void 0 ? void 0 : _b.format) {
|
2103
|
-
completionItem.insertTextFormat = detail.edits.format;
|
2104
|
-
}
|
2105
|
-
if ((_c = detail === null || detail === void 0 ? void 0 : detail.edits) === null || _c === void 0 ? void 0 : _c.textEdit) {
|
2106
|
-
completionItem.textEdit = detail.edits.textEdit;
|
2107
|
-
}
|
2108
|
-
if ((_d = detail === null || detail === void 0 ? void 0 : detail.edits) === null || _d === void 0 ? void 0 : _d.additionalTextEdits) {
|
2109
|
-
completionItem.additionalTextEdits = (0, workspaceEditUtils_1.convertToTextEdits)(detail.edits.additionalTextEdits);
|
2110
|
-
// This is for auto import entries from indices which skip symbols.
|
2111
|
-
if (this._itemToResolve) {
|
2112
|
-
const data = (0, lspUtils_1.fromLSPAny)(this._itemToResolve.data);
|
2113
|
-
if (data.autoImportText === completionItemData.autoImportText) {
|
2114
|
-
this._itemToResolve.additionalTextEdits = completionItem.additionalTextEdits;
|
2115
|
-
}
|
2116
|
-
}
|
2117
|
-
}
|
2118
|
-
completionMap.set(completionItem);
|
2119
|
-
}
|
2120
2134
|
_getRecentListIndex(name, autoImportText) {
|
2121
2135
|
return CompletionProvider._mostRecentCompletions.findIndex((item) => item.label === name && item.autoImportText === autoImportText);
|
2122
2136
|
}
|
@@ -2235,7 +2249,7 @@ class CompletionProvider {
|
|
2235
2249
|
completionMap.set(completionItem);
|
2236
2250
|
}
|
2237
2251
|
completions.forEach((modulePath, completionName) => {
|
2238
|
-
this.
|
2252
|
+
this.addNameToCompletions(completionName, vscode_languageserver_1.CompletionItemKind.Module, '', completionMap, {
|
2239
2253
|
sortText: this._makeSortText(SortCategory.ImportModuleName, completionName),
|
2240
2254
|
modulePath,
|
2241
2255
|
});
|