@@ -1271,6 +1271,7 @@ namespace ts.Completions {
1271
1271
function tryGetGlobalSymbols ( ) : boolean {
1272
1272
const result : GlobalsSearch = tryGetObjectLikeCompletionSymbols ( )
1273
1273
|| tryGetImportOrExportClauseCompletionSymbols ( )
1274
+ || tryGetLocalNamedExportCompletionSymbols ( )
1274
1275
|| tryGetConstructorCompletion ( )
1275
1276
|| tryGetClassLikeCompletionSymbols ( )
1276
1277
|| tryGetJsxCompletionSymbols ( )
@@ -1881,19 +1882,17 @@ namespace ts.Completions {
1881
1882
* export { | };
1882
1883
*
1883
1884
* Relevant symbols are stored in the captured 'symbols' variable.
1884
- *
1885
- * @returns true if 'symbols' was successfully populated; false otherwise.
1886
1885
*/
1887
1886
function tryGetImportOrExportClauseCompletionSymbols ( ) : GlobalsSearch {
1888
1887
// `import { |` or `import { a as 0, | }`
1889
1888
const namedImportsOrExports = contextToken && ( contextToken . kind === SyntaxKind . OpenBraceToken || contextToken . kind === SyntaxKind . CommaToken )
1890
1889
? tryCast ( contextToken . parent , isNamedImportsOrExports ) : undefined ;
1891
1890
if ( ! namedImportsOrExports ) return GlobalsSearch . Continue ;
1892
1891
1893
- // cursor is in an import clause
1894
- // try to show exported member for imported module
1892
+ // try to show exported member for imported/re-exported module
1895
1893
const { moduleSpecifier } = namedImportsOrExports . kind === SyntaxKind . NamedImports ? namedImportsOrExports . parent . parent : namedImportsOrExports . parent ;
1896
- const moduleSpecifierSymbol = typeChecker . getSymbolAtLocation ( moduleSpecifier ! ) ; // TODO: GH#18217
1894
+ if ( ! moduleSpecifier ) return namedImportsOrExports . kind === SyntaxKind . NamedImports ? GlobalsSearch . Fail : GlobalsSearch . Continue ;
1895
+ const moduleSpecifierSymbol = typeChecker . getSymbolAtLocation ( moduleSpecifier ) ; // TODO: GH#18217
1897
1896
if ( ! moduleSpecifierSymbol ) return GlobalsSearch . Fail ;
1898
1897
1899
1898
completionKind = CompletionKind . MemberLike ;
@@ -1904,6 +1903,36 @@ namespace ts.Completions {
1904
1903
return GlobalsSearch . Success ;
1905
1904
}
1906
1905
1906
+ /**
1907
+ * Adds local declarations for completions in named exports:
1908
+ *
1909
+ * export { | };
1910
+ *
1911
+ * Does not check for the absence of a module specifier (`export {} from "./other"`)
1912
+ * because `tryGetImportOrExportClauseCompletionSymbols` runs first and handles that,
1913
+ * preventing this function from running.
1914
+ */
1915
+ function tryGetLocalNamedExportCompletionSymbols ( ) : GlobalsSearch {
1916
+ const namedExports = contextToken && ( contextToken . kind === SyntaxKind . OpenBraceToken || contextToken . kind === SyntaxKind . CommaToken )
1917
+ ? tryCast ( contextToken . parent , isNamedExports )
1918
+ : undefined ;
1919
+
1920
+ if ( ! namedExports ) {
1921
+ return GlobalsSearch . Continue ;
1922
+ }
1923
+
1924
+ const localsContainer = findAncestor ( namedExports , or ( isSourceFile , isModuleDeclaration ) ) ! ;
1925
+ completionKind = CompletionKind . None ;
1926
+ isNewIdentifierLocation = false ;
1927
+ localsContainer . locals ?. forEach ( ( symbol , name ) => {
1928
+ symbols . push ( symbol ) ;
1929
+ if ( localsContainer . symbol ?. exports ?. has ( name ) ) {
1930
+ symbolToSortTextMap [ getSymbolId ( symbol ) ] = SortText . OptionalMember ;
1931
+ }
1932
+ } ) ;
1933
+ return GlobalsSearch . Success ;
1934
+ }
1935
+
1907
1936
/**
1908
1937
* Aggregates relevant symbols for completion in class declaration
1909
1938
* Relevant symbols are stored in the captured 'symbols' variable.
@@ -2299,7 +2328,7 @@ namespace ts.Completions {
2299
2328
}
2300
2329
}
2301
2330
2302
- // Set SortText to OptionalMember if it is an optinoal member
2331
+ // Set SortText to OptionalMember if it is an optional member
2303
2332
function setSortTextToOptionalMember ( ) {
2304
2333
symbols . forEach ( m => {
2305
2334
if ( m . flags & SymbolFlags . Optional ) {
0 commit comments