Skip to content

Commit b6607f1

Browse files
committed
Fix completions at type-only export specifiers
1 parent af3a377 commit b6607f1

4 files changed

Lines changed: 57 additions & 3 deletions

File tree

src/compiler/utilitiesPublic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ export function isTypeOnlyExportDeclaration(node: Node): node is TypeOnlyExportD
15501550
case SyntaxKind.ExportSpecifier:
15511551
return (node as ExportSpecifier).isTypeOnly || (node as ExportSpecifier).parent.parent.isTypeOnly;
15521552
case SyntaxKind.ExportDeclaration:
1553-
return (node as ExportDeclaration).isTypeOnly && !!(node as ExportDeclaration).moduleSpecifier && !(node as ExportDeclaration).exportClause;
1553+
return (node as ExportDeclaration).isTypeOnly;
15541554
case SyntaxKind.NamespaceExport:
15551555
return (node as NamespaceExport).parent.isTypeOnly;
15561556
}

src/services/completions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ import {
179179
isImportDeclaration,
180180
isImportEqualsDeclaration,
181181
isImportKeyword,
182+
isImportOrExportSpecifier,
182183
isImportSpecifier,
183184
isInComment,
184185
isIndexSignatureDeclaration,
@@ -4651,7 +4652,7 @@ function getCompletionData(
46514652
if (!namedImportsOrExports) return GlobalsSearch.Continue;
46524653

46534654
// We can at least offer `type` at `import { |`
4654-
if (!isTypeKeywordTokenOrIdentifier(contextToken)) {
4655+
if (!isTypeKeywordTokenOrIdentifier(contextToken) && !isTypeOnlyImportOrExportDeclaration(contextToken.kind === SyntaxKind.OpenBraceToken || contextToken.kind === SyntaxKind.CommaToken ? contextToken.parent.parent : contextToken.parent)) {
46554656
keywordFilters = KeywordCompletionFilters.TypeKeyword;
46564657
}
46574658

@@ -5007,7 +5008,8 @@ function getCompletionData(
50075008

50085009
case SyntaxKind.TypeKeyword:
50095010
// import { type foo| }
5010-
return containingNodeKind !== SyntaxKind.ImportSpecifier;
5011+
// export { type foo| }
5012+
return !isImportOrExportSpecifier(parent);
50115013

50125014
case SyntaxKind.AsteriskToken:
50135015
return isFunctionLike(contextToken.parent) && !isMethodDeclaration(contextToken.parent);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @Filename: m1.ts
4+
//// export var foo: number = 1;
5+
//// export var jkl: number = 2;
6+
//// export type MyType = string;
7+
8+
// @Filename: m2.ts
9+
//// export { /*1*/ } from "./m1"
10+
//// export type { /*2*/ } from "./m1"
11+
//// export { type /*3*/ } from "./m1"
12+
//// export { foo as foo1, /*4*/ } from "./m1"
13+
//// export type { foo as foo2, /*5*/ } from "./m1"
14+
////
15+
//// export { M/*6*/ } from "./m1"
16+
//// export type { M/*7*/ } from "./m1"
17+
//// export { type M/*8*/ } from "./m1"
18+
19+
const type = { name: "type", sortText: completion.SortText.GlobalsOrKeywords };
20+
21+
verify.completions(
22+
{ marker: ["1", "6"], exact: ["foo", "jkl", "MyType", type] },
23+
{ marker: ["2", "3", "7", "8"], exact: ["foo", "jkl", "MyType"] },
24+
{ marker: "4", exact: ["jkl", "MyType", type] },
25+
{ marker: "5", exact: ["jkl", "MyType"] },
26+
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @Filename: m1.ts
4+
//// export var foo: number = 1;
5+
//// export var jkl: number = 2;
6+
//// export type MyType = string;
7+
8+
// @Filename: m2.ts
9+
//// import { /*1*/ } from "./m1"
10+
//// import type { /*2*/ } from "./m1"
11+
//// import { type /*3*/ } from "./m1"
12+
//// import { foo as foo1, /*4*/ } from "./m1"
13+
//// import type { foo as foo2, /*5*/ } from "./m1"
14+
////
15+
//// import { M/*6*/ } from "./m1"
16+
//// import type { M/*7*/ } from "./m1"
17+
//// import { type M/*8*/ } from "./m1"
18+
19+
const type = { name: "type", sortText: completion.SortText.GlobalsOrKeywords };
20+
21+
verify.completions(
22+
{ marker: ["1", "6"], exact: ["foo", "jkl", "MyType", type] },
23+
{ marker: ["2", "3", "7", "8"], exact: ["foo", "jkl", "MyType"] },
24+
{ marker: "4", exact: ["jkl", "MyType", type] },
25+
{ marker: "5", exact: ["jkl", "MyType"] },
26+
);

0 commit comments

Comments
 (0)