MCPcopy
hub / github.com/microsoft/typescript-go / getQuickInfoAndDeclarationAtLocation

Function getQuickInfoAndDeclarationAtLocation

internal/ls/hover.go:275–775  ·  view source on GitHub ↗

getQuickInfoAndDeclarationAtLocation builds classified display parts using displayPartsWriter when vsCapability is true. When vsCapability is false, it still builds the plain text string but skips classification runs.

(c *checker.Checker, symbol *ast.Symbol, node *ast.Node, vc *checker.VerbosityContext, vsCapability bool, meaning ast.SemanticMeaning)

Source from the content-addressed store, hash-verified

273// getQuickInfoAndDeclarationAtLocation builds classified display parts using displayPartsWriter when vsCapability is true.
274// When vsCapability is false, it still builds the plain text string but skips classification runs.
275func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol, node *ast.Node, vc *checker.VerbosityContext, vsCapability bool, meaning ast.SemanticMeaning) symbolDisplayInfo {
276 container := getContainerNode(node)
277 if vc == nil {
278 vc = &checker.VerbosityContext{}
279 }
280 dpw := newDisplayPartsWriter(vsCapability)
281
282 // Source file for printer context
283 var sourceFile *ast.SourceFile
284 if node != nil {
285 sourceFile = ast.GetSourceFileOfNode(node)
286 }
287
288 // nodeBuilderFlags for classified output (same as signatureHelpNodeBuilderFlags)
289 const classifiedNodeBuilderFlags = nodebuilder.FlagsIgnoreErrors | nodebuilder.FlagsUseAliasDefinedOutsideCurrentScope | nodebuilder.FlagsWriteTypeParametersInQualifiedName
290
291 // writeTypeClassified writes a type to dpw with proper classification (punctuation, symbols, keywords).
292 // Falls back to flat text when vsCapability is false or when TypeToTypeNode fails.
293 writeTypeClassified := func(t *checker.Type, enclosing *ast.Node, flags checker.TypeFormatFlags) {
294 flags |= checker.TypeFormatFlagsMultilineObjectLiterals
295 if !vsCapability {
296 dpw.Write(c.TypeToStringEx(t, enclosing, flags, vc))
297 return
298 }
299 emitContext := printer.NewEmitContext()
300 idToSymbol := make(map[*ast.IdentifierNode]*ast.Symbol)
301 nb := checker.NewNodeBuilderEx(c, emitContext, idToSymbol)
302 combinedFlags := nodebuilder.Flags(flags&checker.TypeFormatFlagsNodeBuilderFlagsMask) | classifiedNodeBuilderFlags
303 typeNode := nb.TypeToTypeNode(t, enclosing, combinedFlags, nodebuilder.InternalFlagsNone, nil)
304 if typeNode == nil {
305 dpw.Write(c.TypeToStringEx(t, enclosing, flags, vc))
306 return
307 }
308 p := printer.NewPrinter(printer.PrinterOptions{NewLine: core.NewLineKindLF}, printer.PrintHandlers{}, emitContext)
309 p.IdToSymbol = idToSymbol
310 tempDpw := newDisplayPartsWriter(true)
311 p.Write(typeNode, sourceFile, tempDpw, nil)
312 dpw.WriteFrom(tempDpw)
313 }
314
315 // writeSignatureClassified writes a signature to dpw with proper classification.
316 writeSignatureClassified := func(sig *checker.Signature, enclosing *ast.Node, flags checker.TypeFormatFlags) {
317 flags |= checker.TypeFormatFlagsMultilineObjectLiterals
318 if !vsCapability {
319 dpw.Write(c.SignatureToStringEx(sig, enclosing, flags, vc))
320 return
321 }
322 isConstructor := sig.Flags()&checker.SignatureFlagsConstruct != 0 && flags&checker.TypeFormatFlagsWriteCallStyleSignature == 0
323 var sigOutput ast.Kind
324 if flags&checker.TypeFormatFlagsWriteArrowStyleSignature != 0 {
325 if isConstructor {
326 sigOutput = ast.KindConstructorType
327 } else {
328 sigOutput = ast.KindFunctionType
329 }
330 } else {
331 if isConstructor {
332 sigOutput = ast.KindConstructSignature

Calls 15

WriteMethod · 0.95
FlagsMethod · 0.95
SymbolMethod · 0.95
AsLiteralTypeMethod · 0.95
GetSourceFileOfNodeFunction · 0.92
NewEmitContextFunction · 0.92
NewNodeBuilderExFunction · 0.92
FlagsTypeAlias · 0.92
NewPrinterFunction · 0.92
IsInExpressionContextFunction · 0.92
IsThisInTypeQueryFunction · 0.92
IsMethodDeclarationFunction · 0.92

Tested by

no test coverage detected