@@ -1329,7 +1329,11 @@ function completionInfoFromData(
1329
1329
1330
1330
if ( keywordFilters !== KeywordCompletionFilters . None ) {
1331
1331
for ( const keywordEntry of getKeywordCompletions ( keywordFilters , ! insideJsDocTagTypeExpression && isSourceFileJS ( sourceFile ) ) ) {
1332
- if ( isTypeOnlyLocation && isTypeKeyword ( stringToToken ( keywordEntry . name ) ! ) || ! uniqueNames . has ( keywordEntry . name ) ) {
1332
+ if (
1333
+ isTypeOnlyLocation && isTypeKeyword ( stringToToken ( keywordEntry . name ) ! ) ||
1334
+ ! isTypeOnlyLocation && isContextualKeywordInAutoImportableExpressionSpace ( keywordEntry . name ) ||
1335
+ ! uniqueNames . has ( keywordEntry . name )
1336
+ ) {
1333
1337
uniqueNames . add ( keywordEntry . name ) ;
1334
1338
insertSorted ( entries , keywordEntry , compareCompletionEntries , /*allowDuplicates*/ true ) ;
1335
1339
}
@@ -5829,3 +5833,31 @@ function toUpperCharCode(charCode: number) {
5829
5833
}
5830
5834
return charCode ;
5831
5835
}
5836
+
5837
+ /**
5838
+ * These are all the contextual keywords that would be valid to auto-import
5839
+ * in expression space and also a valid keyword in the same location, depending
5840
+ * on what gets typed afterwards. In these cases, we want to offer both the
5841
+ * auto-import and the keyword completion. For example,
5842
+ *
5843
+ * ```ts
5844
+ * type
5845
+ * ```
5846
+ *
5847
+ * may be the beginning of a type alias declaration (keyword completion), or
5848
+ * it may be the beginning of
5849
+ *
5850
+ * ```ts
5851
+ * import { type } from "os";
5852
+ * type() === "Darwin" ? doSomething() : doSomethingElse();
5853
+ * ```
5854
+ */
5855
+ function isContextualKeywordInAutoImportableExpressionSpace ( keyword : string ) {
5856
+ return keyword === "abstract" ||
5857
+ keyword === "async" ||
5858
+ keyword === "await" ||
5859
+ keyword === "declare" ||
5860
+ keyword === "module" ||
5861
+ keyword === "namespace" ||
5862
+ keyword === "type" ;
5863
+ }
0 commit comments