@zzzen/pyright-internal 1.2.0-dev.20230827 → 1.2.0-dev.20230903
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 +1 -0
- 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/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 +16 -11
- 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/program.d.ts +7 -20
- package/dist/analyzer/program.js +89 -83
- 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/service.d.ts +6 -3
- package/dist/analyzer/service.js +26 -8
- 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/typeEvaluator.js +199 -160
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +78 -14
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.js +23 -9
- 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/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 +16 -3
- 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 +4 -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/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 +8 -8
- package/dist/languageServerBase.js +3 -2
- 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 +4 -3
- package/dist/languageService/completionProvider.js +178 -170
- 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 +5 -0
- package/dist/localization/localize.js +1 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +18 -15
- package/dist/localization/package.nls.de.json +18 -15
- package/dist/localization/package.nls.en-us.json +4 -3
- package/dist/localization/package.nls.es.json +18 -15
- package/dist/localization/package.nls.fr.json +18 -15
- package/dist/localization/package.nls.it.json +18 -15
- package/dist/localization/package.nls.ja.json +18 -15
- package/dist/localization/package.nls.ko.json +18 -15
- package/dist/localization/package.nls.pl.json +18 -15
- package/dist/localization/package.nls.pt-br.json +18 -15
- package/dist/localization/package.nls.qps-ploc.json +6 -3
- package/dist/localization/package.nls.ru.json +18 -15
- package/dist/localization/package.nls.tr.json +18 -15
- package/dist/localization/package.nls.zh-cn.json +18 -15
- package/dist/localization/package.nls.zh-tw.json +18 -15
- package/dist/pyright.js +6 -4
- package/dist/pyright.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +6 -9
- 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 +9 -9
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/completions.test.js +30 -0
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/config.test.js +23 -17
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js +8 -8
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js.map +1 -1
- package/dist/tests/fourslash/importnotresolved.fourslash.js +2 -2
- package/dist/tests/fourslash/importnotresolved.fourslash.js.map +1 -1
- 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.d.ts +2 -0
- package/dist/tests/harness/fourslash/testState.js +5 -1
- package/dist/tests/harness/fourslash/testState.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/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/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 +3 -3
- 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 +12 -3
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
@@ -405,6 +405,10 @@ class CompletionProvider {
|
|
405
405
|
};
|
406
406
|
return vscode_languageserver_1.TextEdit.replace(range, text);
|
407
407
|
}
|
408
|
+
shouldProcessDeclaration(declaration) {
|
409
|
+
// By default, we allow all symbol/decl to be included in the completion.
|
410
|
+
return true;
|
411
|
+
}
|
408
412
|
addSymbol(name, symbol, priorWord, completionMap, detail) {
|
409
413
|
var _a, _b, _c, _d;
|
410
414
|
// Make sure we don't crash due to OOM.
|
@@ -416,6 +420,9 @@ class CompletionProvider {
|
|
416
420
|
primaryDecl = declarations[declarations.length - 1];
|
417
421
|
}
|
418
422
|
}
|
423
|
+
if (!this.shouldProcessDeclaration(primaryDecl)) {
|
424
|
+
return;
|
425
|
+
}
|
419
426
|
primaryDecl = primaryDecl
|
420
427
|
? (_a = this.evaluator.resolveAliasDeclaration(primaryDecl, /* resolveLocalNames */ true)) !== null && _a !== void 0 ? _a : primaryDecl
|
421
428
|
: undefined;
|
@@ -444,7 +451,7 @@ class CompletionProvider {
|
|
444
451
|
// Can't resolve. so bail out.
|
445
452
|
return;
|
446
453
|
}
|
447
|
-
const typeDetail = (0, completionProviderUtils_1.getTypeDetail)(this.evaluator,
|
454
|
+
const typeDetail = (0, completionProviderUtils_1.getTypeDetail)(this.evaluator, type, primaryDecl, name, detail, this.configOptions.functionSignatureDisplay);
|
448
455
|
const documentation = (0, tooltipUtils_1.getDocumentationPartsForTypeAndDecl)(this.sourceMapper, type, primaryDecl, this.evaluator, {
|
449
456
|
name,
|
450
457
|
symbol,
|
@@ -471,7 +478,7 @@ class CompletionProvider {
|
|
471
478
|
((_c = primaryDecl.node.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* Assignment */) {
|
472
479
|
itemKind = vscode_languageserver_1.CompletionItemKind.EnumMember;
|
473
480
|
}
|
474
|
-
this.
|
481
|
+
this.addNameToCompletions((_d = detail.autoImportAlias) !== null && _d !== void 0 ? _d : name, itemKind, priorWord, completionMap, {
|
475
482
|
autoImportText,
|
476
483
|
extraCommitChars: detail.extraCommitChars,
|
477
484
|
funcParensDisabled: detail.funcParensDisabled,
|
@@ -483,7 +490,7 @@ class CompletionProvider {
|
|
483
490
|
const synthesizedType = symbol.getSynthesizedType();
|
484
491
|
if (synthesizedType) {
|
485
492
|
const itemKind = this._convertTypeToItemKind(synthesizedType);
|
486
|
-
this.
|
493
|
+
this.addNameToCompletions(name, itemKind, priorWord, completionMap, {
|
487
494
|
extraCommitChars: detail.extraCommitChars,
|
488
495
|
funcParensDisabled: detail.funcParensDisabled,
|
489
496
|
edits: detail.edits,
|
@@ -572,7 +579,7 @@ class CompletionProvider {
|
|
572
579
|
});
|
573
580
|
}
|
574
581
|
else {
|
575
|
-
this.
|
582
|
+
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
583
|
extraCommitChars: true,
|
577
584
|
autoImportText: this._getAutoImportText(result.name, result.source, result.alias),
|
578
585
|
edits: {
|
@@ -589,6 +596,132 @@ class CompletionProvider {
|
|
589
596
|
addExtraCommitChar(item) {
|
590
597
|
// extra commit char is not supported.
|
591
598
|
}
|
599
|
+
addNameToCompletions(name, itemKind, filter, completionMap, detail) {
|
600
|
+
var _a, _b, _c, _d;
|
601
|
+
// Auto importer already filtered out unnecessary ones. No need to do it again.
|
602
|
+
const similarity = (detail === null || detail === void 0 ? void 0 : detail.autoImportText) ? true : StringUtils.isPatternInSymbol(filter, name);
|
603
|
+
if (!similarity) {
|
604
|
+
return;
|
605
|
+
}
|
606
|
+
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)) {
|
607
|
+
return;
|
608
|
+
}
|
609
|
+
const completionItem = vscode_languageserver_1.CompletionItem.create(name);
|
610
|
+
completionItem.kind = itemKind;
|
611
|
+
if (detail === null || detail === void 0 ? void 0 : detail.extraCommitChars) {
|
612
|
+
this.addExtraCommitChar(completionItem);
|
613
|
+
}
|
614
|
+
const completionItemData = {
|
615
|
+
workspacePath: this._workspacePath,
|
616
|
+
filePath: this.filePath,
|
617
|
+
position: this.position,
|
618
|
+
};
|
619
|
+
if ((detail === null || detail === void 0 ? void 0 : detail.funcParensDisabled) || !this.options.snippet) {
|
620
|
+
completionItemData.funcParensDisabled = true;
|
621
|
+
}
|
622
|
+
if (detail === null || detail === void 0 ? void 0 : detail.modulePath) {
|
623
|
+
completionItemData.modulePath = detail.modulePath;
|
624
|
+
}
|
625
|
+
completionItem.data = (0, lspUtils_1.toLSPAny)(completionItemData);
|
626
|
+
if ((detail === null || detail === void 0 ? void 0 : detail.sortText) || (detail === null || detail === void 0 ? void 0 : detail.itemDetail)) {
|
627
|
+
completionItem.sortText = detail.sortText;
|
628
|
+
completionItem.detail = detail.itemDetail;
|
629
|
+
}
|
630
|
+
else if (detail === null || detail === void 0 ? void 0 : detail.autoImportText) {
|
631
|
+
// Force auto-import entries to the end.
|
632
|
+
completionItem.sortText = this._makeSortText(SortCategory.AutoImport, `${name}.${this._formatInteger(detail.autoImportText.source.length, 2)}.${detail.autoImportText.source}`, detail.autoImportText.importText);
|
633
|
+
completionItemData.autoImportText = detail.autoImportText.importText;
|
634
|
+
completionItem.detail = exports.autoImportDetail;
|
635
|
+
if (detail.autoImportText.source) {
|
636
|
+
completionItem.labelDetails = { description: detail.autoImportText.source };
|
637
|
+
}
|
638
|
+
}
|
639
|
+
else if (itemKind === vscode_languageserver_1.CompletionItemKind.EnumMember) {
|
640
|
+
// Handle enum members separately so they are sorted above other symbols.
|
641
|
+
completionItem.sortText = this._makeSortText(SortCategory.EnumMember, name);
|
642
|
+
}
|
643
|
+
else if (SymbolNameUtils.isDunderName(name)) {
|
644
|
+
// Force dunder-named symbols to appear after all other symbols.
|
645
|
+
completionItem.sortText = this._makeSortText(SortCategory.DunderSymbol, name);
|
646
|
+
}
|
647
|
+
else if (filter === '' && SymbolNameUtils.isPrivateOrProtectedName(name)) {
|
648
|
+
// Distinguish between normal and private symbols only if there is
|
649
|
+
// currently no filter text. Once we get a single character to filter
|
650
|
+
// upon, we'll no longer differentiate.
|
651
|
+
completionItem.sortText = this._makeSortText(SortCategory.PrivateSymbol, name);
|
652
|
+
}
|
653
|
+
else {
|
654
|
+
completionItem.sortText = this._makeSortText(SortCategory.NormalSymbol, name);
|
655
|
+
}
|
656
|
+
completionItemData.symbolLabel = name;
|
657
|
+
if (this.options.format === vscode_languageserver_1.MarkupKind.Markdown) {
|
658
|
+
let markdownString = '';
|
659
|
+
if (detail === null || detail === void 0 ? void 0 : detail.autoImportText) {
|
660
|
+
markdownString += detail.autoImportText.importText;
|
661
|
+
if (detail.typeDetail || detail.documentation) {
|
662
|
+
// Micro perf optimization to not create new string from trimEnd.
|
663
|
+
markdownString += '\n\n';
|
664
|
+
}
|
665
|
+
}
|
666
|
+
if (detail === null || detail === void 0 ? void 0 : detail.typeDetail) {
|
667
|
+
markdownString += '```python\n' + detail.typeDetail + '\n```\n';
|
668
|
+
}
|
669
|
+
if (detail === null || detail === void 0 ? void 0 : detail.documentation) {
|
670
|
+
markdownString += '---\n';
|
671
|
+
markdownString += (0, docStringConversion_1.convertDocStringToMarkdown)(detail.documentation);
|
672
|
+
}
|
673
|
+
markdownString = markdownString.trimEnd();
|
674
|
+
if (markdownString) {
|
675
|
+
completionItem.documentation = {
|
676
|
+
kind: vscode_languageserver_1.MarkupKind.Markdown,
|
677
|
+
value: markdownString,
|
678
|
+
};
|
679
|
+
}
|
680
|
+
}
|
681
|
+
else if (this.options.format === vscode_languageserver_1.MarkupKind.PlainText) {
|
682
|
+
let plainTextString = '';
|
683
|
+
if (detail === null || detail === void 0 ? void 0 : detail.autoImportText) {
|
684
|
+
plainTextString += detail.autoImportText.importText;
|
685
|
+
if (detail.typeDetail || detail.documentation) {
|
686
|
+
// Micro perf optimization to not create new string from trimEnd.
|
687
|
+
plainTextString += '\n\n';
|
688
|
+
}
|
689
|
+
}
|
690
|
+
if (detail === null || detail === void 0 ? void 0 : detail.typeDetail) {
|
691
|
+
plainTextString += detail.typeDetail + '\n';
|
692
|
+
}
|
693
|
+
if (detail === null || detail === void 0 ? void 0 : detail.documentation) {
|
694
|
+
plainTextString += '\n' + (0, docStringConversion_1.convertDocStringToPlainText)(detail.documentation);
|
695
|
+
}
|
696
|
+
plainTextString = plainTextString.trimEnd();
|
697
|
+
if (plainTextString) {
|
698
|
+
completionItem.documentation = {
|
699
|
+
kind: vscode_languageserver_1.MarkupKind.PlainText,
|
700
|
+
value: plainTextString,
|
701
|
+
};
|
702
|
+
}
|
703
|
+
}
|
704
|
+
else {
|
705
|
+
(0, debug_1.fail)(`Unsupported markup type: ${this.options.format}`);
|
706
|
+
}
|
707
|
+
if ((_b = detail === null || detail === void 0 ? void 0 : detail.edits) === null || _b === void 0 ? void 0 : _b.format) {
|
708
|
+
completionItem.insertTextFormat = detail.edits.format;
|
709
|
+
}
|
710
|
+
if ((_c = detail === null || detail === void 0 ? void 0 : detail.edits) === null || _c === void 0 ? void 0 : _c.textEdit) {
|
711
|
+
completionItem.textEdit = detail.edits.textEdit;
|
712
|
+
}
|
713
|
+
if ((_d = detail === null || detail === void 0 ? void 0 : detail.edits) === null || _d === void 0 ? void 0 : _d.additionalTextEdits) {
|
714
|
+
completionItem.additionalTextEdits = (0, workspaceEditUtils_1.convertToTextEdits)(detail.edits.additionalTextEdits);
|
715
|
+
// This is for auto import entries from indices which skip symbols.
|
716
|
+
if (this._itemToResolve) {
|
717
|
+
const data = (0, lspUtils_1.fromLSPAny)(this._itemToResolve.data);
|
718
|
+
if (data.autoImportText === completionItemData.autoImportText) {
|
719
|
+
this._itemToResolve.additionalTextEdits = completionItem.additionalTextEdits;
|
720
|
+
}
|
721
|
+
}
|
722
|
+
}
|
723
|
+
completionMap.set(completionItem);
|
724
|
+
}
|
592
725
|
get _fileContents() {
|
593
726
|
var _a, _b;
|
594
727
|
return (_b = (_a = this.parseResults) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : '';
|
@@ -1037,7 +1170,7 @@ class CompletionProvider {
|
|
1037
1170
|
enforcePythonSyntax: true,
|
1038
1171
|
expandTypeAlias: false,
|
1039
1172
|
});
|
1040
|
-
this.
|
1173
|
+
this.addNameToCompletions(text, vscode_languageserver_1.CompletionItemKind.Reference, priorWord, completionMap, {
|
1041
1174
|
sortText: this._makeSortText(SortCategory.LikelyKeyword, text),
|
1042
1175
|
});
|
1043
1176
|
return;
|
@@ -1074,7 +1207,7 @@ class CompletionProvider {
|
|
1074
1207
|
2 /* DoNotLimitStringLength */
|
1075
1208
|
: 2 /* DoNotLimitStringLength */;
|
1076
1209
|
const text = `${ParseTreeUtils.printExpression(declWithTypeAnnotations[declWithTypeAnnotations.length - 1].typeAnnotationNode, printFlags)}`;
|
1077
|
-
this.
|
1210
|
+
this.addNameToCompletions(text, vscode_languageserver_1.CompletionItemKind.Reference, priorWord, completionMap, {
|
1078
1211
|
sortText: this._makeSortText(SortCategory.LikelyKeyword, text),
|
1079
1212
|
});
|
1080
1213
|
}
|
@@ -1326,7 +1459,7 @@ class CompletionProvider {
|
|
1326
1459
|
if (types_1.ClassType.isBuiltIn(v, 'str')) {
|
1327
1460
|
const value = (0, typePrinter_1.printLiteralValue)(v, quoteValue.quoteCharacter);
|
1328
1461
|
if (quoteValue.stringValue === undefined) {
|
1329
|
-
this.
|
1462
|
+
this.addNameToCompletions(value, vscode_languageserver_1.CompletionItemKind.Constant, priorWord, completionMap, {
|
1330
1463
|
sortText: this._makeSortText(SortCategory.LiteralValue, v.literalValue),
|
1331
1464
|
});
|
1332
1465
|
}
|
@@ -1518,7 +1651,7 @@ class CompletionProvider {
|
|
1518
1651
|
: undefined;
|
1519
1652
|
if (nodeForExpectedType) {
|
1520
1653
|
const expectedTypeResult = this.evaluator.getExpectedType(nodeForExpectedType);
|
1521
|
-
if (expectedTypeResult && (0, typeUtils_1.
|
1654
|
+
if (expectedTypeResult && (0, typeUtils_1.containsLiteralType)(expectedTypeResult.type)) {
|
1522
1655
|
this._addLiteralValuesForTargetType(expectedTypeResult.type, priorWord, priorText, postText, completionMap);
|
1523
1656
|
return true;
|
1524
1657
|
}
|
@@ -1572,7 +1705,7 @@ class CompletionProvider {
|
|
1572
1705
|
this._addStringLiteralToCompletions(keyWithoutQuote, quoteInfo, postText, completionMap, exports.dictionaryKeyDetail);
|
1573
1706
|
}
|
1574
1707
|
else {
|
1575
|
-
this.
|
1708
|
+
this.addNameToCompletions(key, vscode_languageserver_1.CompletionItemKind.Constant, priorWord, completionMap, {
|
1576
1709
|
sortText: this._makeSortText(SortCategory.LiteralValue, key),
|
1577
1710
|
itemDetail: exports.dictionaryKeyDetail,
|
1578
1711
|
});
|
@@ -1587,7 +1720,7 @@ class CompletionProvider {
|
|
1587
1720
|
const supportedOperators = [2 /* Assign */, 12 /* Equals */, 28 /* NotEquals */];
|
1588
1721
|
if (comparison.nodeType === 7 /* BinaryOperation */ && supportedOperators.includes(comparison.operator)) {
|
1589
1722
|
const type = this.evaluator.getType(comparison.leftExpression);
|
1590
|
-
if (type && (0, typeUtils_1.
|
1723
|
+
if (type && (0, typeUtils_1.containsLiteralType)(type)) {
|
1591
1724
|
this._addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
1592
1725
|
return true;
|
1593
1726
|
}
|
@@ -1597,7 +1730,7 @@ class CompletionProvider {
|
|
1597
1730
|
if (assignmentExpression.nodeType === 4 /* AssignmentExpression */ &&
|
1598
1731
|
assignmentExpression.rightExpression === parentAndChild.child) {
|
1599
1732
|
const type = this.evaluator.getType(assignmentExpression.name);
|
1600
|
-
if (type && (0, typeUtils_1.
|
1733
|
+
if (type && (0, typeUtils_1.containsLiteralType)(type)) {
|
1601
1734
|
this._addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
1602
1735
|
return true;
|
1603
1736
|
}
|
@@ -1612,7 +1745,7 @@ class CompletionProvider {
|
|
1612
1745
|
caseNode.suite === parentAndChild.child &&
|
1613
1746
|
((_c = caseNode.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 63 /* Match */) {
|
1614
1747
|
const type = this.evaluator.getType(caseNode.parent.subjectExpression);
|
1615
|
-
if (type && (0, typeUtils_1.
|
1748
|
+
if (type && (0, typeUtils_1.containsLiteralType)(type)) {
|
1616
1749
|
this._addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
1617
1750
|
return true;
|
1618
1751
|
}
|
@@ -1627,7 +1760,7 @@ class CompletionProvider {
|
|
1627
1760
|
((_e = patternLiteral.parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 64 /* Case */ &&
|
1628
1761
|
((_f = patternLiteral.parent.parent.parent) === null || _f === void 0 ? void 0 : _f.nodeType) === 63 /* Match */) {
|
1629
1762
|
const type = this.evaluator.getType(patternLiteral.parent.parent.parent.subjectExpression);
|
1630
|
-
if (type && (0, typeUtils_1.
|
1763
|
+
if (type && (0, typeUtils_1.containsLiteralType)(type)) {
|
1631
1764
|
this._addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
1632
1765
|
return true;
|
1633
1766
|
}
|
@@ -1766,37 +1899,38 @@ class CompletionProvider {
|
|
1766
1899
|
return this._tryAddTypedDictKeys(baseType, [], priorWord, priorText, postText, completionMap);
|
1767
1900
|
}
|
1768
1901
|
_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
|
-
|
1902
|
+
if (!StringUtils.isPatternInSymbol(quoteInfo.filterText || '', value)) {
|
1903
|
+
return;
|
1904
|
+
}
|
1905
|
+
const valueWithQuotes = `${quoteInfo.quoteCharacter}${value}${quoteInfo.quoteCharacter}`;
|
1906
|
+
if (completionMap.has(valueWithQuotes)) {
|
1907
|
+
return;
|
1908
|
+
}
|
1909
|
+
const completionItem = vscode_languageserver_1.CompletionItem.create(valueWithQuotes);
|
1910
|
+
completionItem.kind = vscode_languageserver_1.CompletionItemKind.Constant;
|
1911
|
+
completionItem.sortText = this._makeSortText(SortCategory.LiteralValue, valueWithQuotes);
|
1912
|
+
let rangeStartCol = this.position.character;
|
1913
|
+
if (quoteInfo.stringValue !== undefined) {
|
1914
|
+
rangeStartCol -= quoteInfo.stringValue.length + 1;
|
1915
|
+
}
|
1916
|
+
else if (quoteInfo.priorWord) {
|
1917
|
+
rangeStartCol -= quoteInfo.priorWord.length;
|
1918
|
+
}
|
1919
|
+
// If the text after the insertion point is the closing quote,
|
1920
|
+
// replace it.
|
1921
|
+
let rangeEndCol = this.position.character;
|
1922
|
+
if (postText !== undefined) {
|
1923
|
+
if (postText.startsWith(quoteInfo.quoteCharacter)) {
|
1924
|
+
rangeEndCol++;
|
1791
1925
|
}
|
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
1926
|
}
|
1927
|
+
const range = {
|
1928
|
+
start: { line: this.position.line, character: rangeStartCol },
|
1929
|
+
end: { line: this.position.line, character: rangeEndCol },
|
1930
|
+
};
|
1931
|
+
completionItem.textEdit = vscode_languageserver_1.TextEdit.replace(range, valueWithQuotes);
|
1932
|
+
completionItem.detail = detail;
|
1933
|
+
completionMap.set(completionItem);
|
1800
1934
|
}
|
1801
1935
|
_getImportFromCompletions(importFromNode, priorWord) {
|
1802
1936
|
var _a;
|
@@ -1830,7 +1964,7 @@ class CompletionProvider {
|
|
1830
1964
|
// Add the implicit imports.
|
1831
1965
|
importInfo.implicitImports.forEach((implImport) => {
|
1832
1966
|
if (!importFromNode.imports.find((imp) => imp.name.value === implImport.name)) {
|
1833
|
-
this.
|
1967
|
+
this.addNameToCompletions(implImport.name, vscode_languageserver_1.CompletionItemKind.Module, priorWord, completionMap, {
|
1834
1968
|
modulePath: implImport.path,
|
1835
1969
|
});
|
1836
1970
|
}
|
@@ -1991,132 +2125,6 @@ class CompletionProvider {
|
|
1991
2125
|
importText,
|
1992
2126
|
};
|
1993
2127
|
}
|
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
2128
|
_getRecentListIndex(name, autoImportText) {
|
2121
2129
|
return CompletionProvider._mostRecentCompletions.findIndex((item) => item.label === name && item.autoImportText === autoImportText);
|
2122
2130
|
}
|
@@ -2235,7 +2243,7 @@ class CompletionProvider {
|
|
2235
2243
|
completionMap.set(completionItem);
|
2236
2244
|
}
|
2237
2245
|
completions.forEach((modulePath, completionName) => {
|
2238
|
-
this.
|
2246
|
+
this.addNameToCompletions(completionName, vscode_languageserver_1.CompletionItemKind.Module, '', completionMap, {
|
2239
2247
|
sortText: this._makeSortText(SortCategory.ImportModuleName, completionName),
|
2240
2248
|
modulePath,
|
2241
2249
|
});
|