mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
fix(54818): "from" keyword displaying incorrect completions (#54843)
This commit is contained in:
parent
bd1e9752d2
commit
a437de66b6
@ -2847,7 +2847,7 @@ function getCompletionEntryCodeActionsAndSourceDisplay(
|
||||
cancellationToken: CancellationToken,
|
||||
): CodeActionsAndSourceDisplay {
|
||||
if (data?.moduleSpecifier) {
|
||||
if (previousToken && getImportStatementCompletionInfo(contextToken || previousToken).replacementSpan) {
|
||||
if (previousToken && getImportStatementCompletionInfo(contextToken || previousToken, sourceFile).replacementSpan) {
|
||||
// Import statement completion: 'import c|'
|
||||
return { codeActions: undefined, sourceDisplay: [textPart(data.moduleSpecifier)] };
|
||||
}
|
||||
@ -3176,7 +3176,7 @@ function getCompletionData(
|
||||
let flags = CompletionInfoFlags.None;
|
||||
|
||||
if (contextToken) {
|
||||
const importStatementCompletionInfo = getImportStatementCompletionInfo(contextToken);
|
||||
const importStatementCompletionInfo = getImportStatementCompletionInfo(contextToken, sourceFile);
|
||||
if (importStatementCompletionInfo.keywordCompletion) {
|
||||
if (importStatementCompletionInfo.isKeywordOnlyCompletion) {
|
||||
return {
|
||||
@ -5469,7 +5469,7 @@ export interface ImportStatementCompletionInfo {
|
||||
replacementSpan: TextSpan | undefined;
|
||||
}
|
||||
|
||||
function getImportStatementCompletionInfo(contextToken: Node): ImportStatementCompletionInfo {
|
||||
function getImportStatementCompletionInfo(contextToken: Node, sourceFile: SourceFile): ImportStatementCompletionInfo {
|
||||
let keywordCompletion: TokenSyntaxKind | undefined;
|
||||
let isKeywordOnlyCompletion = false;
|
||||
const candidate = getCandidate();
|
||||
@ -5485,6 +5485,15 @@ function getImportStatementCompletionInfo(contextToken: Node): ImportStatementCo
|
||||
function getCandidate() {
|
||||
const parent = contextToken.parent;
|
||||
if (isImportEqualsDeclaration(parent)) {
|
||||
// import Foo |
|
||||
// import Foo f|
|
||||
const lastToken = parent.getLastToken(sourceFile);
|
||||
if (isIdentifier(contextToken) && lastToken !== contextToken) {
|
||||
keywordCompletion = SyntaxKind.FromKeyword;
|
||||
isKeywordOnlyCompletion = true;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
keywordCompletion = contextToken.kind === SyntaxKind.TypeKeyword ? undefined : SyntaxKind.TypeKeyword;
|
||||
return isModuleSpecifierMissingOrEmpty(parent.moduleReference) ? parent : undefined;
|
||||
}
|
||||
|
||||
25
tests/cases/fourslash/importStatementCompletions4.ts
Normal file
25
tests/cases/fourslash/importStatementCompletions4.ts
Normal file
@ -0,0 +1,25 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
////import Foo /*a*/
|
||||
////
|
||||
////function fromBar() {}
|
||||
|
||||
// @Filename: /b.jsx
|
||||
////import Foo /*b*/
|
||||
////
|
||||
////function fromBar() {}
|
||||
|
||||
verify.completions({
|
||||
marker: ["a", "b"],
|
||||
exact: {
|
||||
name: "from",
|
||||
sortText: completion.SortText.GlobalsOrKeywords,
|
||||
},
|
||||
preferences: {
|
||||
includeCompletionsForImportStatements: true,
|
||||
includeInsertTextCompletions: true,
|
||||
},
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user