@zzzen/pyright-internal 1.2.0-dev.20230820 → 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 +47 -64
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +24 -3
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +2 -1
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +1 -1
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/decorators.js +11 -6
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/deprecatedSymbols.d.ts +9 -0
- package/dist/analyzer/deprecatedSymbols.js +303 -0
- package/dist/analyzer/deprecatedSymbols.js.map +1 -0
- package/dist/analyzer/docStringConversion.js +7 -1
- package/dist/analyzer/docStringConversion.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +6 -4
- package/dist/analyzer/importResolver.js +21 -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 +10 -23
- package/dist/analyzer/program.js +94 -92
- 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 +10 -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 +729 -592
- 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 +93 -18
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +2 -2
- package/dist/analyzer/typeUtils.js +32 -13
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +3 -1
- package/dist/analyzer/typeVarContext.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 +6 -1
- package/dist/analyzer/types.js +19 -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/cancellationUtils.d.ts +2 -1
- package/dist/common/cancellationUtils.js +3 -0
- package/dist/common/cancellationUtils.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 +5 -1
- package/dist/common/configOptions.js +21 -4
- 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/diagnosticRules.d.ts +1 -0
- package/dist/common/diagnosticRules.js +1 -0
- package/dist/common/diagnosticRules.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 +187 -173
- 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 +8 -0
- package/dist/localization/localize.js +2 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +15 -10
- package/dist/localization/package.nls.de.json +11 -6
- package/dist/localization/package.nls.en-us.json +6 -4
- package/dist/localization/package.nls.es.json +16 -11
- package/dist/localization/package.nls.fr.json +17 -12
- package/dist/localization/package.nls.it.json +17 -12
- package/dist/localization/package.nls.ja.json +11 -6
- package/dist/localization/package.nls.ko.json +15 -10
- package/dist/localization/package.nls.pl.json +14 -9
- package/dist/localization/package.nls.pt-br.json +18 -13
- package/dist/localization/package.nls.qps-ploc.json +18 -13
- package/dist/localization/package.nls.ru.json +15 -10
- package/dist/localization/package.nls.tr.json +11 -6
- package/dist/localization/package.nls.zh-cn.json +14 -9
- package/dist/localization/package.nls.zh-tw.json +11 -6
- package/dist/parser/parser.js +2 -0
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.d.ts +1 -1
- package/dist/parser/tokenizer.js +9 -5
- package/dist/parser/tokenizer.js.map +1 -1
- 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 +34 -13
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/completions.test.js +69 -2
- 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/docStringConversion.test.js +23 -0
- package/dist/tests/docStringConversion.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 +6 -2
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +9 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +17 -23
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +12 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +24 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +24 -20
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +2 -1
- package/dist/workspaceFactory.js +15 -6
- 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,
|
@@ -509,11 +516,17 @@ class CompletionProvider {
|
|
509
516
|
if ((0, types_1.isClass)(subtype)) {
|
510
517
|
const instance = types_1.TypeBase.isInstance(subtype);
|
511
518
|
if (types_1.ClassType.isEnumClass(subtype) && instance) {
|
512
|
-
// We don't add members for instances of enum members.
|
519
|
+
// We don't add members for instances of enum members, but do add members of `enum.Enum` itself.
|
513
520
|
// ex) 'MyEnum.member.' <= here
|
514
|
-
|
521
|
+
const enumType = subtype.details.baseClasses.find((t) => (0, types_1.isClass)(t) && types_1.ClassType.isBuiltIn(t, 'Enum'));
|
522
|
+
if (!enumType) {
|
523
|
+
return;
|
524
|
+
}
|
525
|
+
(0, typeUtils_1.getMembersForClass)(enumType, symbolTable, /* instance */ true);
|
526
|
+
}
|
527
|
+
else {
|
528
|
+
(0, typeUtils_1.getMembersForClass)(subtype, symbolTable, instance);
|
515
529
|
}
|
516
|
-
(0, typeUtils_1.getMembersForClass)(subtype, symbolTable, instance);
|
517
530
|
}
|
518
531
|
else if ((0, types_1.isModule)(subtype)) {
|
519
532
|
(0, typeUtils_1.getMembersForModule)(subtype, symbolTable);
|
@@ -566,7 +579,7 @@ class CompletionProvider {
|
|
566
579
|
});
|
567
580
|
}
|
568
581
|
else {
|
569
|
-
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, {
|
570
583
|
extraCommitChars: true,
|
571
584
|
autoImportText: this._getAutoImportText(result.name, result.source, result.alias),
|
572
585
|
edits: {
|
@@ -583,6 +596,132 @@ class CompletionProvider {
|
|
583
596
|
addExtraCommitChar(item) {
|
584
597
|
// extra commit char is not supported.
|
585
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
|
+
}
|
586
725
|
get _fileContents() {
|
587
726
|
var _a, _b;
|
588
727
|
return (_b = (_a = this.parseResults) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : '';
|
@@ -1031,7 +1170,7 @@ class CompletionProvider {
|
|
1031
1170
|
enforcePythonSyntax: true,
|
1032
1171
|
expandTypeAlias: false,
|
1033
1172
|
});
|
1034
|
-
this.
|
1173
|
+
this.addNameToCompletions(text, vscode_languageserver_1.CompletionItemKind.Reference, priorWord, completionMap, {
|
1035
1174
|
sortText: this._makeSortText(SortCategory.LikelyKeyword, text),
|
1036
1175
|
});
|
1037
1176
|
return;
|
@@ -1068,7 +1207,7 @@ class CompletionProvider {
|
|
1068
1207
|
2 /* DoNotLimitStringLength */
|
1069
1208
|
: 2 /* DoNotLimitStringLength */;
|
1070
1209
|
const text = `${ParseTreeUtils.printExpression(declWithTypeAnnotations[declWithTypeAnnotations.length - 1].typeAnnotationNode, printFlags)}`;
|
1071
|
-
this.
|
1210
|
+
this.addNameToCompletions(text, vscode_languageserver_1.CompletionItemKind.Reference, priorWord, completionMap, {
|
1072
1211
|
sortText: this._makeSortText(SortCategory.LikelyKeyword, text),
|
1073
1212
|
});
|
1074
1213
|
}
|
@@ -1320,7 +1459,7 @@ class CompletionProvider {
|
|
1320
1459
|
if (types_1.ClassType.isBuiltIn(v, 'str')) {
|
1321
1460
|
const value = (0, typePrinter_1.printLiteralValue)(v, quoteValue.quoteCharacter);
|
1322
1461
|
if (quoteValue.stringValue === undefined) {
|
1323
|
-
this.
|
1462
|
+
this.addNameToCompletions(value, vscode_languageserver_1.CompletionItemKind.Constant, priorWord, completionMap, {
|
1324
1463
|
sortText: this._makeSortText(SortCategory.LiteralValue, v.literalValue),
|
1325
1464
|
});
|
1326
1465
|
}
|
@@ -1512,7 +1651,7 @@ class CompletionProvider {
|
|
1512
1651
|
: undefined;
|
1513
1652
|
if (nodeForExpectedType) {
|
1514
1653
|
const expectedTypeResult = this.evaluator.getExpectedType(nodeForExpectedType);
|
1515
|
-
if (expectedTypeResult && (0, typeUtils_1.
|
1654
|
+
if (expectedTypeResult && (0, typeUtils_1.containsLiteralType)(expectedTypeResult.type)) {
|
1516
1655
|
this._addLiteralValuesForTargetType(expectedTypeResult.type, priorWord, priorText, postText, completionMap);
|
1517
1656
|
return true;
|
1518
1657
|
}
|
@@ -1566,7 +1705,7 @@ class CompletionProvider {
|
|
1566
1705
|
this._addStringLiteralToCompletions(keyWithoutQuote, quoteInfo, postText, completionMap, exports.dictionaryKeyDetail);
|
1567
1706
|
}
|
1568
1707
|
else {
|
1569
|
-
this.
|
1708
|
+
this.addNameToCompletions(key, vscode_languageserver_1.CompletionItemKind.Constant, priorWord, completionMap, {
|
1570
1709
|
sortText: this._makeSortText(SortCategory.LiteralValue, key),
|
1571
1710
|
itemDetail: exports.dictionaryKeyDetail,
|
1572
1711
|
});
|
@@ -1581,7 +1720,7 @@ class CompletionProvider {
|
|
1581
1720
|
const supportedOperators = [2 /* Assign */, 12 /* Equals */, 28 /* NotEquals */];
|
1582
1721
|
if (comparison.nodeType === 7 /* BinaryOperation */ && supportedOperators.includes(comparison.operator)) {
|
1583
1722
|
const type = this.evaluator.getType(comparison.leftExpression);
|
1584
|
-
if (type && (0, typeUtils_1.
|
1723
|
+
if (type && (0, typeUtils_1.containsLiteralType)(type)) {
|
1585
1724
|
this._addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
1586
1725
|
return true;
|
1587
1726
|
}
|
@@ -1591,7 +1730,7 @@ class CompletionProvider {
|
|
1591
1730
|
if (assignmentExpression.nodeType === 4 /* AssignmentExpression */ &&
|
1592
1731
|
assignmentExpression.rightExpression === parentAndChild.child) {
|
1593
1732
|
const type = this.evaluator.getType(assignmentExpression.name);
|
1594
|
-
if (type && (0, typeUtils_1.
|
1733
|
+
if (type && (0, typeUtils_1.containsLiteralType)(type)) {
|
1595
1734
|
this._addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
1596
1735
|
return true;
|
1597
1736
|
}
|
@@ -1606,7 +1745,7 @@ class CompletionProvider {
|
|
1606
1745
|
caseNode.suite === parentAndChild.child &&
|
1607
1746
|
((_c = caseNode.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 63 /* Match */) {
|
1608
1747
|
const type = this.evaluator.getType(caseNode.parent.subjectExpression);
|
1609
|
-
if (type && (0, typeUtils_1.
|
1748
|
+
if (type && (0, typeUtils_1.containsLiteralType)(type)) {
|
1610
1749
|
this._addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
1611
1750
|
return true;
|
1612
1751
|
}
|
@@ -1621,7 +1760,7 @@ class CompletionProvider {
|
|
1621
1760
|
((_e = patternLiteral.parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 64 /* Case */ &&
|
1622
1761
|
((_f = patternLiteral.parent.parent.parent) === null || _f === void 0 ? void 0 : _f.nodeType) === 63 /* Match */) {
|
1623
1762
|
const type = this.evaluator.getType(patternLiteral.parent.parent.parent.subjectExpression);
|
1624
|
-
if (type && (0, typeUtils_1.
|
1763
|
+
if (type && (0, typeUtils_1.containsLiteralType)(type)) {
|
1625
1764
|
this._addLiteralValuesForTargetType(type, priorWord, priorText, postText, completionMap);
|
1626
1765
|
return true;
|
1627
1766
|
}
|
@@ -1760,37 +1899,38 @@ class CompletionProvider {
|
|
1760
1899
|
return this._tryAddTypedDictKeys(baseType, [], priorWord, priorText, postText, completionMap);
|
1761
1900
|
}
|
1762
1901
|
_addStringLiteralToCompletions(value, quoteInfo, postText, completionMap, detail) {
|
1763
|
-
if (StringUtils.isPatternInSymbol(quoteInfo.filterText || '', value)) {
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
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++;
|
1785
1925
|
}
|
1786
|
-
const range = {
|
1787
|
-
start: { line: this.position.line, character: rangeStartCol },
|
1788
|
-
end: { line: this.position.line, character: rangeEndCol },
|
1789
|
-
};
|
1790
|
-
completionItem.textEdit = vscode_languageserver_1.TextEdit.replace(range, valueWithQuotes);
|
1791
|
-
completionItem.detail = detail;
|
1792
|
-
completionMap.set(completionItem);
|
1793
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);
|
1794
1934
|
}
|
1795
1935
|
_getImportFromCompletions(importFromNode, priorWord) {
|
1796
1936
|
var _a;
|
@@ -1824,7 +1964,7 @@ class CompletionProvider {
|
|
1824
1964
|
// Add the implicit imports.
|
1825
1965
|
importInfo.implicitImports.forEach((implImport) => {
|
1826
1966
|
if (!importFromNode.imports.find((imp) => imp.name.value === implImport.name)) {
|
1827
|
-
this.
|
1967
|
+
this.addNameToCompletions(implImport.name, vscode_languageserver_1.CompletionItemKind.Module, priorWord, completionMap, {
|
1828
1968
|
modulePath: implImport.path,
|
1829
1969
|
});
|
1830
1970
|
}
|
@@ -1985,132 +2125,6 @@ class CompletionProvider {
|
|
1985
2125
|
importText,
|
1986
2126
|
};
|
1987
2127
|
}
|
1988
|
-
_addNameToCompletions(name, itemKind, filter, completionMap, detail) {
|
1989
|
-
var _a, _b, _c, _d;
|
1990
|
-
// Auto importer already filtered out unnecessary ones. No need to do it again.
|
1991
|
-
const similarity = (detail === null || detail === void 0 ? void 0 : detail.autoImportText) ? true : StringUtils.isPatternInSymbol(filter, name);
|
1992
|
-
if (!similarity) {
|
1993
|
-
return;
|
1994
|
-
}
|
1995
|
-
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)) {
|
1996
|
-
return;
|
1997
|
-
}
|
1998
|
-
const completionItem = vscode_languageserver_1.CompletionItem.create(name);
|
1999
|
-
completionItem.kind = itemKind;
|
2000
|
-
if (detail === null || detail === void 0 ? void 0 : detail.extraCommitChars) {
|
2001
|
-
this.addExtraCommitChar(completionItem);
|
2002
|
-
}
|
2003
|
-
const completionItemData = {
|
2004
|
-
workspacePath: this._workspacePath,
|
2005
|
-
filePath: this.filePath,
|
2006
|
-
position: this.position,
|
2007
|
-
};
|
2008
|
-
if ((detail === null || detail === void 0 ? void 0 : detail.funcParensDisabled) || !this.options.snippet) {
|
2009
|
-
completionItemData.funcParensDisabled = true;
|
2010
|
-
}
|
2011
|
-
if (detail === null || detail === void 0 ? void 0 : detail.modulePath) {
|
2012
|
-
completionItemData.modulePath = detail.modulePath;
|
2013
|
-
}
|
2014
|
-
completionItem.data = (0, lspUtils_1.toLSPAny)(completionItemData);
|
2015
|
-
if ((detail === null || detail === void 0 ? void 0 : detail.sortText) || (detail === null || detail === void 0 ? void 0 : detail.itemDetail)) {
|
2016
|
-
completionItem.sortText = detail.sortText;
|
2017
|
-
completionItem.detail = detail.itemDetail;
|
2018
|
-
}
|
2019
|
-
else if (detail === null || detail === void 0 ? void 0 : detail.autoImportText) {
|
2020
|
-
// Force auto-import entries to the end.
|
2021
|
-
completionItem.sortText = this._makeSortText(SortCategory.AutoImport, `${name}.${this._formatInteger(detail.autoImportText.source.length, 2)}.${detail.autoImportText.source}`, detail.autoImportText.importText);
|
2022
|
-
completionItemData.autoImportText = detail.autoImportText.importText;
|
2023
|
-
completionItem.detail = exports.autoImportDetail;
|
2024
|
-
if (detail.autoImportText.source) {
|
2025
|
-
completionItem.labelDetails = { description: detail.autoImportText.source };
|
2026
|
-
}
|
2027
|
-
}
|
2028
|
-
else if (itemKind === vscode_languageserver_1.CompletionItemKind.EnumMember) {
|
2029
|
-
// Handle enum members separately so they are sorted above other symbols.
|
2030
|
-
completionItem.sortText = this._makeSortText(SortCategory.EnumMember, name);
|
2031
|
-
}
|
2032
|
-
else if (SymbolNameUtils.isDunderName(name)) {
|
2033
|
-
// Force dunder-named symbols to appear after all other symbols.
|
2034
|
-
completionItem.sortText = this._makeSortText(SortCategory.DunderSymbol, name);
|
2035
|
-
}
|
2036
|
-
else if (filter === '' && SymbolNameUtils.isPrivateOrProtectedName(name)) {
|
2037
|
-
// Distinguish between normal and private symbols only if there is
|
2038
|
-
// currently no filter text. Once we get a single character to filter
|
2039
|
-
// upon, we'll no longer differentiate.
|
2040
|
-
completionItem.sortText = this._makeSortText(SortCategory.PrivateSymbol, name);
|
2041
|
-
}
|
2042
|
-
else {
|
2043
|
-
completionItem.sortText = this._makeSortText(SortCategory.NormalSymbol, name);
|
2044
|
-
}
|
2045
|
-
completionItemData.symbolLabel = name;
|
2046
|
-
if (this.options.format === vscode_languageserver_1.MarkupKind.Markdown) {
|
2047
|
-
let markdownString = '';
|
2048
|
-
if (detail === null || detail === void 0 ? void 0 : detail.autoImportText) {
|
2049
|
-
markdownString += detail.autoImportText.importText;
|
2050
|
-
if (detail.typeDetail || detail.documentation) {
|
2051
|
-
// Micro perf optimization to not create new string from trimEnd.
|
2052
|
-
markdownString += '\n\n';
|
2053
|
-
}
|
2054
|
-
}
|
2055
|
-
if (detail === null || detail === void 0 ? void 0 : detail.typeDetail) {
|
2056
|
-
markdownString += '```python\n' + detail.typeDetail + '\n```\n';
|
2057
|
-
}
|
2058
|
-
if (detail === null || detail === void 0 ? void 0 : detail.documentation) {
|
2059
|
-
markdownString += '---\n';
|
2060
|
-
markdownString += (0, docStringConversion_1.convertDocStringToMarkdown)(detail.documentation);
|
2061
|
-
}
|
2062
|
-
markdownString = markdownString.trimEnd();
|
2063
|
-
if (markdownString) {
|
2064
|
-
completionItem.documentation = {
|
2065
|
-
kind: vscode_languageserver_1.MarkupKind.Markdown,
|
2066
|
-
value: markdownString,
|
2067
|
-
};
|
2068
|
-
}
|
2069
|
-
}
|
2070
|
-
else if (this.options.format === vscode_languageserver_1.MarkupKind.PlainText) {
|
2071
|
-
let plainTextString = '';
|
2072
|
-
if (detail === null || detail === void 0 ? void 0 : detail.autoImportText) {
|
2073
|
-
plainTextString += detail.autoImportText.importText;
|
2074
|
-
if (detail.typeDetail || detail.documentation) {
|
2075
|
-
// Micro perf optimization to not create new string from trimEnd.
|
2076
|
-
plainTextString += '\n\n';
|
2077
|
-
}
|
2078
|
-
}
|
2079
|
-
if (detail === null || detail === void 0 ? void 0 : detail.typeDetail) {
|
2080
|
-
plainTextString += detail.typeDetail + '\n';
|
2081
|
-
}
|
2082
|
-
if (detail === null || detail === void 0 ? void 0 : detail.documentation) {
|
2083
|
-
plainTextString += '\n' + (0, docStringConversion_1.convertDocStringToPlainText)(detail.documentation);
|
2084
|
-
}
|
2085
|
-
plainTextString = plainTextString.trimEnd();
|
2086
|
-
if (plainTextString) {
|
2087
|
-
completionItem.documentation = {
|
2088
|
-
kind: vscode_languageserver_1.MarkupKind.PlainText,
|
2089
|
-
value: plainTextString,
|
2090
|
-
};
|
2091
|
-
}
|
2092
|
-
}
|
2093
|
-
else {
|
2094
|
-
(0, debug_1.fail)(`Unsupported markup type: ${this.options.format}`);
|
2095
|
-
}
|
2096
|
-
if ((_b = detail === null || detail === void 0 ? void 0 : detail.edits) === null || _b === void 0 ? void 0 : _b.format) {
|
2097
|
-
completionItem.insertTextFormat = detail.edits.format;
|
2098
|
-
}
|
2099
|
-
if ((_c = detail === null || detail === void 0 ? void 0 : detail.edits) === null || _c === void 0 ? void 0 : _c.textEdit) {
|
2100
|
-
completionItem.textEdit = detail.edits.textEdit;
|
2101
|
-
}
|
2102
|
-
if ((_d = detail === null || detail === void 0 ? void 0 : detail.edits) === null || _d === void 0 ? void 0 : _d.additionalTextEdits) {
|
2103
|
-
completionItem.additionalTextEdits = (0, workspaceEditUtils_1.convertToTextEdits)(detail.edits.additionalTextEdits);
|
2104
|
-
// This is for auto import entries from indices which skip symbols.
|
2105
|
-
if (this._itemToResolve) {
|
2106
|
-
const data = (0, lspUtils_1.fromLSPAny)(this._itemToResolve.data);
|
2107
|
-
if (data.autoImportText === completionItemData.autoImportText) {
|
2108
|
-
this._itemToResolve.additionalTextEdits = completionItem.additionalTextEdits;
|
2109
|
-
}
|
2110
|
-
}
|
2111
|
-
}
|
2112
|
-
completionMap.set(completionItem);
|
2113
|
-
}
|
2114
2128
|
_getRecentListIndex(name, autoImportText) {
|
2115
2129
|
return CompletionProvider._mostRecentCompletions.findIndex((item) => item.label === name && item.autoImportText === autoImportText);
|
2116
2130
|
}
|
@@ -2229,7 +2243,7 @@ class CompletionProvider {
|
|
2229
2243
|
completionMap.set(completionItem);
|
2230
2244
|
}
|
2231
2245
|
completions.forEach((modulePath, completionName) => {
|
2232
|
-
this.
|
2246
|
+
this.addNameToCompletions(completionName, vscode_languageserver_1.CompletionItemKind.Module, '', completionMap, {
|
2233
2247
|
sortText: this._makeSortText(SortCategory.ImportModuleName, completionName),
|
2234
2248
|
modulePath,
|
2235
2249
|
});
|