@@ -182,6 +182,12 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
182182 var b strings.Builder
183183 var visitedAliases collections.Set [* ast.Symbol ]
184184 var aliasLevel int
185+ var firstDeclaration * ast.Node
186+ setDeclaration := func (declaration * ast.Node ) {
187+ if firstDeclaration == nil {
188+ firstDeclaration = declaration
189+ }
190+ }
185191 writeNewLine := func () {
186192 if b .Len () != 0 {
187193 b .WriteString ("\n " )
@@ -219,14 +225,13 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
219225 b .WriteString (">" )
220226 }
221227 }
222- var writeSymbol func (* ast.Symbol ) * ast.Node
223- writeSymbol = func (symbol * ast.Symbol ) * ast.Node {
224- var declaration * ast.Node
228+ var writeSymbol func (* ast.Symbol )
229+ writeSymbol = func (symbol * ast.Symbol ) {
225230 // Recursively write all meanings of alias
226231 if symbol .Flags & ast .SymbolFlagsAlias != 0 && visitedAliases .AddIfAbsent (symbol ) {
227232 if aliasedSymbol := c .GetAliasedSymbol (symbol ); aliasedSymbol != c .GetUnknownSymbol () {
228233 aliasLevel ++
229- declaration = writeSymbol (aliasedSymbol )
234+ writeSymbol (aliasedSymbol )
230235 aliasLevel --
231236 }
232237 }
@@ -238,19 +243,21 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
238243 flags = symbol .Flags & ast .SymbolFlagsType
239244 case ast .SemanticMeaningNamespace :
240245 flags = symbol .Flags & ast .SymbolFlagsNamespace
246+ default :
247+ flags = symbol .Flags & (ast .SymbolFlagsValue | ast .SymbolFlagsSignature | ast .SymbolFlagsType | ast .SymbolFlagsNamespace )
241248 }
242249 if flags == 0 {
250+ if aliasLevel != 0 || b .Len () != 0 {
251+ return
252+ }
243253 flags = symbol .Flags & (ast .SymbolFlagsValue | ast .SymbolFlagsSignature | ast .SymbolFlagsType | ast .SymbolFlagsNamespace )
244254 if flags == 0 {
245- return nil
255+ return
246256 }
247257 }
248258 if flags & ast .SymbolFlagsProperty != 0 && symbol .ValueDeclaration != nil && ast .IsMethodDeclaration (symbol .ValueDeclaration ) {
249259 flags = ast .SymbolFlagsMethod
250260 }
251- if flags & ast .SymbolFlagsValue != 0 {
252- declaration = symbol .ValueDeclaration
253- }
254261 if flags & (ast .SymbolFlagsVariable | ast .SymbolFlagsProperty | ast .SymbolFlagsAccessor ) != 0 {
255262 writeNewLine ()
256263 switch {
@@ -288,6 +295,7 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
288295 } else {
289296 b .WriteString (c .TypeToStringEx (c .GetTypeOfSymbolAtLocation (symbol , node ), container , typeFormatFlags ))
290297 }
298+ setDeclaration (symbol .ValueDeclaration )
291299 }
292300 if flags & ast .SymbolFlagsEnumMember != 0 {
293301 writeNewLine ()
@@ -298,33 +306,32 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
298306 b .WriteString (" = " )
299307 b .WriteString (t .AsLiteralType ().String ())
300308 }
309+ setDeclaration (symbol .ValueDeclaration )
301310 }
302311 if flags & (ast .SymbolFlagsFunction | ast .SymbolFlagsMethod ) != 0 {
303312 prefix := core .IfElse (flags & ast .SymbolFlagsMethod != 0 , "(method) " , "function " )
304313 if ast .IsIdentifier (node ) && ast .IsFunctionLikeDeclaration (node .Parent ) && node .Parent .Name () == node {
305- declaration = node .Parent
306- signatures := []* checker.Signature {c .GetSignatureFromDeclaration (declaration )}
314+ setDeclaration ( node .Parent )
315+ signatures := []* checker.Signature {c .GetSignatureFromDeclaration (node . Parent )}
307316 writeSignatures (signatures , prefix , symbol )
308317 } else {
309318 signatures := getSignaturesAtLocation (c , symbol , checker .SignatureKindCall , node )
310319 if len (signatures ) == 1 {
311320 if d := signatures [0 ].Declaration (); d != nil && d .Flags & ast .NodeFlagsJSDoc == 0 {
312- declaration = d
321+ setDeclaration ( d )
313322 }
314323 }
315324 writeSignatures (signatures , prefix , symbol )
316325 }
326+ setDeclaration (symbol .ValueDeclaration )
317327 }
318328 if flags & (ast .SymbolFlagsClass | ast .SymbolFlagsInterface ) != 0 {
319- if flags & ast .SymbolFlagsInterface != 0 && (declaration == nil || ast .IsIdentifier (node ) && ast .IsInterfaceDeclaration (node .Parent )) {
320- declaration = core .Find (symbol .Declarations , ast .IsInterfaceDeclaration )
321- }
322329 if node .Kind == ast .KindThisKeyword || ast .IsThisInTypeQuery (node ) {
323330 writeNewLine ()
324331 b .WriteString ("this" )
325332 } else if node .Kind == ast .KindConstructorKeyword && (ast .IsConstructorDeclaration (node .Parent ) || ast .IsConstructSignatureDeclaration (node .Parent )) {
326- declaration = node .Parent
327- signatures := []* checker.Signature {c .GetSignatureFromDeclaration (declaration )}
333+ setDeclaration ( node .Parent )
334+ signatures := []* checker.Signature {c .GetSignatureFromDeclaration (node . Parent )}
328335 writeSignatures (signatures , "constructor " , symbol )
329336 } else {
330337 var signatures []* checker.Signature
@@ -333,7 +340,7 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
333340 }
334341 if len (signatures ) == 1 {
335342 if d := signatures [0 ].Declaration (); d != nil && d .Flags & ast .NodeFlagsJSDoc == 0 {
336- declaration = d
343+ setDeclaration ( d )
337344 }
338345 writeSignatures (signatures , "constructor " , symbol )
339346 } else {
@@ -344,22 +351,23 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
344351 writeTypeParams (params )
345352 }
346353 }
354+ if flags & ast .SymbolFlagsClass != 0 {
355+ setDeclaration (symbol .ValueDeclaration )
356+ } else {
357+ setDeclaration (core .Find (symbol .Declarations , ast .IsInterfaceDeclaration ))
358+ }
347359 }
348360 if flags & ast .SymbolFlagsEnum != 0 {
349361 writeNewLine ()
350362 b .WriteString ("enum " )
351363 b .WriteString (c .SymbolToStringEx (symbol , container , ast .SymbolFlagsNone , symbolFormatFlags ))
352- if declaration == nil || ast .IsIdentifier (node ) && ast .IsEnumDeclaration (node .Parent ) {
353- declaration = core .Find (symbol .Declarations , ast .IsEnumDeclaration )
354- }
364+ setDeclaration (core .Find (symbol .Declarations , ast .IsEnumDeclaration ))
355365 }
356366 if flags & ast .SymbolFlagsModule != 0 {
357367 writeNewLine ()
358368 b .WriteString (core .IfElse (symbol .ValueDeclaration != nil && ast .IsSourceFile (symbol .ValueDeclaration ), "module " , "namespace " ))
359369 b .WriteString (c .SymbolToStringEx (symbol , container , ast .SymbolFlagsNone , symbolFormatFlags ))
360- if declaration == nil || ast .IsIdentifier (node ) && ast .IsModuleDeclaration (node .Parent ) {
361- declaration = core .Find (symbol .Declarations , ast .IsModuleDeclaration )
362- }
370+ setDeclaration (core .Find (symbol .Declarations , ast .IsModuleDeclaration ))
363371 }
364372 if flags & ast .SymbolFlagsTypeParameter != 0 {
365373 writeNewLine ()
@@ -371,9 +379,7 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
371379 b .WriteString (" extends " )
372380 b .WriteString (c .TypeToStringEx (cons , container , typeFormatFlags ))
373381 }
374- if declaration == nil || ast .IsIdentifier (node ) && ast .IsTypeParameterDeclaration (node .Parent ) {
375- declaration = core .Find (symbol .Declarations , ast .IsTypeParameterDeclaration )
376- }
382+ setDeclaration (core .Find (symbol .Declarations , ast .IsTypeParameterDeclaration ))
377383 }
378384 if flags & ast .SymbolFlagsTypeAlias != 0 {
379385 writeNewLine ()
@@ -384,17 +390,14 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
384390 b .WriteString (" = " )
385391 b .WriteString (c .TypeToStringEx (c .GetDeclaredTypeOfSymbol (symbol ), container , typeFormatFlags | checker .TypeFormatFlagsInTypeAlias ))
386392 }
387- if declaration == nil || ast .IsIdentifier (node ) && ast .IsTypeOrJSTypeAliasDeclaration (node .Parent ) {
388- declaration = core .Find (symbol .Declarations , ast .IsTypeOrJSTypeAliasDeclaration )
389- }
393+ setDeclaration (core .Find (symbol .Declarations , ast .IsTypeOrJSTypeAliasDeclaration ))
390394 }
391395 if flags & ast .SymbolFlagsSignature != 0 {
392396 writeNewLine ()
393397 b .WriteString (c .TypeToStringEx (c .GetTypeOfSymbol (symbol ), container , typeFormatFlags ))
394398 }
395- return declaration
396399 }
397- firstDeclaration := writeSymbol (symbol )
400+ writeSymbol (symbol )
398401 return b .String (), firstDeclaration
399402}
400403
0 commit comments