MCPcopy Create free account
hub / github.com/Effect-TS/tsgo / FormatQuickInfo

Function FormatQuickInfo

internal/layergraph/format.go:307–370  ·  view source on GitHub ↗

FormatQuickInfo renders provider/requirer info as a JSDoc comment.

(
	c *checker.Checker,
	providersAndRequirers []ProviderRequirerInfo,
	sf *ast.SourceFile,
)

Source from the content-addressed store, hash-verified

305
306// FormatQuickInfo renders provider/requirer info as a JSDoc comment.
307func FormatQuickInfo(
308 c *checker.Checker,
309 providersAndRequirers []ProviderRequirerInfo,
310 sf *ast.SourceFile,
311) string {
312 if len(providersAndRequirers) == 0 {
313 return ""
314 }
315
316 var providedItems, requiredItems []ProviderRequirerInfo
317 for _, item := range providersAndRequirers {
318 if item.Kind == ProviderRequirerKindProvided {
319 providedItems = append(providedItems, item)
320 } else {
321 requiredItems = append(requiredItems, item)
322 }
323 }
324
325 var textualExplanation []string
326
327 appendInfo := func(item ProviderRequirerInfo) {
328 typeName := getTypeDisplayName(c, item.Type)
329
330 var positions []string
331 for i, displayNode := range item.DisplayNodes {
332 displaySourceFile := getNodeSourceFile(displayNode)
333 nodeText := getNodeText(displayNode, displaySourceFile)
334 nodeText = strings.ReplaceAll(nodeText, "\n", " ")
335 if len(nodeText) > 50 {
336 nodeText = nodeText[:50]
337 }
338 loc := formatLocation(displayNode, sf)
339 // Intentional fix over .repos reference: the .repos version unconditionally
340 // prepends "at " for the first display node, producing a double preposition
341 // "provided at in file.ts at ln X col Y" for cross-file references. This
342 // check skips the "at " prefix when the location already starts with "in ",
343 // yielding the correct "provided in file.ts at ln X col Y".
344 if !strings.HasPrefix(loc, "in ") {
345 if i == 0 {
346 loc = "at " + loc
347 }
348 }
349 positions = append(positions, fmt.Sprintf("%s by `%s`", loc, nodeText))
350 }
351
352 textualExplanation = append(textualExplanation, fmt.Sprintf("- %s %s %s", typeName, item.Kind, strings.Join(positions, ", ")))
353 }
354
355 for _, item := range providedItems {
356 appendInfo(item)
357 }
358 if len(providedItems) > 0 && len(requiredItems) > 0 {
359 textualExplanation = append(textualExplanation, "")
360 }
361 for _, item := range requiredItems {
362 appendInfo(item)
363 }
364

Callers 2

formatLayerHoverFunction · 0.92

Calls 4

getTypeDisplayNameFunction · 0.85
getNodeSourceFileFunction · 0.85
getNodeTextFunction · 0.85
formatLocationFunction · 0.85

Tested by

no test coverage detected