@@ -1103,6 +1103,17 @@ abstract class SymbolDataResolver {
11031103 return sourceFiles [ 0 ] ;
11041104 }
11051105
1106+ public getIdentifierInformation ( sourceFile : ts . SourceFile , symbol : ts . Symbol , declaration : ts . Node ) : [ ts . Node , string ] | [ undefined , undefined ] {
1107+ if ( tss . isNamedDeclaration ( declaration ) ) {
1108+ let name = declaration . name ;
1109+ return [ name , name . getText ( ) ] ;
1110+ }
1111+ if ( tss . isValueModule ( symbol ) && ts . isSourceFile ( declaration ) ) {
1112+ return [ declaration , '' ] ;
1113+ }
1114+ return [ undefined , undefined ] ;
1115+ }
1116+
11061117 public abstract resolve ( sourceFile : ts . SourceFile | undefined , id : SymbolId , symbol : ts . Symbol , location ?: ts . Node , scope ?: ts . Node ) : SymbolData ;
11071118}
11081119
@@ -1193,26 +1204,22 @@ class UnionOrIntersectionResolver extends SymbolDataResolver {
11931204 }
11941205
11951206 public resolve ( sourceFile : ts . SourceFile , id : SymbolId , symbol : ts . Symbol , location ?: ts . Node , scope ?: ts . Node ) : SymbolData {
1196- if ( location === undefined ) {
1197- throw new Error ( `Union or intersection resolver requires a location` ) ;
1198- }
1199- let type = this . typeChecker . getTypeOfSymbolAtLocation ( symbol , location ) ;
1200- if ( ! type . isUnionOrIntersection ( ) ) {
1201- throw new Error ( `Type is not a union or intersection type` ) ;
1202- }
1203- if ( type . types . length > 0 ) {
1204- let datas : SymbolData [ ] = [ ] ;
1205- for ( let typeElem of type . types ) {
1206- let symbol = typeElem . symbol ;
1207- // This happens for base types like undefined, number, ....
1208- if ( symbol !== undefined ) {
1209- datas . push ( this . resolverContext . getOrCreateSymbolData ( symbol ) ) ;
1210- }
1207+ const composites = tss . getCompositeSymbols ( this . typeChecker , symbol , location ) ;
1208+ if ( composites !== undefined ) {
1209+ const datas : SymbolData [ ] = [ ] ;
1210+ for ( let symbol of composites ) {
1211+ datas . push ( this . resolverContext . getOrCreateSymbolData ( symbol ) ) ;
12111212 }
12121213 return new UnionOrIntersectionSymbolData ( this . symbolDataContext , id , sourceFile , datas ) ;
12131214 } else {
12141215 return new StandardSymbolData ( this . symbolDataContext , id , undefined ) ;
12151216 }
1217+ // We have something like x: { prop: number} | { prop: string };
1218+ throw new Error ( `Union or intersection resolver requires a location` ) ;
1219+ }
1220+
1221+ public getIdentifierInformation ( sourceFile : ts . SourceFile , symbol : ts . Symbol , declaration : ts . Node ) : [ ts . Node , string ] | [ undefined , undefined ] {
1222+ return [ declaration , declaration . getText ( ) ] ;
12161223 }
12171224}
12181225
@@ -2051,7 +2058,7 @@ class Visitor implements ResolverContext {
20512058 let hover : lsp . Hover | undefined ;
20522059 for ( let declaration of declarations ) {
20532060 const sourceFile = declaration . getSourceFile ( ) ;
2054- const [ identifierNode , identifierText ] = this . getIdentifierInformation ( sourceFile , symbol , declaration ) ;
2061+ const [ identifierNode , identifierText ] = resolver . getIdentifierInformation ( sourceFile , symbol , declaration ) ;
20552062 if ( identifierNode !== undefined && identifierText !== undefined ) {
20562063 const documentData = this . getOrCreateDocumentData ( sourceFile ) ;
20572064 const range = ts . isSourceFile ( declaration ) ? { start : { line : 0 , character : 0 } , end : { line : 0 , character : 0 } } : Converter . rangeFromNode ( sourceFile , identifierNode ) ;
@@ -2100,17 +2107,6 @@ class Visitor implements ResolverContext {
21002107 return result ;
21012108 }
21022109
2103- private getIdentifierInformation ( sourceFile : ts . SourceFile , symbol : ts . Symbol , declaration : ts . Node ) : [ ts . Node , string ] | [ undefined , undefined ] {
2104- if ( tss . isNamedDeclaration ( declaration ) ) {
2105- let name = declaration . name ;
2106- return [ name , name . getText ( ) ] ;
2107- }
2108- if ( tss . isValueModule ( symbol ) && ts . isSourceFile ( declaration ) ) {
2109- return [ declaration , '' ] ;
2110- }
2111- return [ undefined , undefined ] ;
2112- }
2113-
21142110 private resolveEmittingNode ( symbol : ts . Symbol , isExported : boolean ) : ts . Node | undefined {
21152111 // The symbol has a export path so we can't bind this to a node
21162112 // Note that we even treat private class members like this. Reason being
@@ -2146,11 +2142,16 @@ class Visitor implements ResolverContext {
21462142
21472143 private getResolver ( symbol : ts . Symbol , location ?: ts . Node ) : SymbolDataResolver {
21482144 if ( location !== undefined && tss . isTransient ( symbol ) ) {
2149- let type = this . typeChecker . getTypeOfSymbolAtLocation ( symbol , location ) ;
2150- if ( type . isUnionOrIntersection ( ) ) {
2145+ if ( tss . isComposite ( this . typeChecker , symbol , location ) ) {
21512146 return this . symbolDataResolvers . unionOrIntersection ;
21522147 } else {
2153- return this . symbolDataResolvers . transient ;
2148+ // Problem: Symbols that come from the lib*.d.ts files are marked transient
2149+ // as well. Check if the symbol has some other meaningful flags
2150+ if ( ( symbol . getFlags ( ) & ~ ts . SymbolFlags . Transient ) !== 0 ) {
2151+ return this . symbolDataResolvers . standard ;
2152+ } else {
2153+ return this . symbolDataResolvers . transient ;
2154+ }
21542155 }
21552156 }
21562157 if ( tss . isTypeAlias ( symbol ) ) {
0 commit comments