MCPcopy Create free account
hub / github.com/microsoft/typescript-go / writeNameLink

Method writeNameLink

internal/ls/hover.go:1058–1079  ·  view source on GitHub ↗
(b *strings.Builder, c *checker.Checker, name *ast.Node, text string, quote bool, isMarkdown bool)

Source from the content-addressed store, hash-verified

1056}
1057
1058func (l *LanguageService) writeNameLink(b *strings.Builder, c *checker.Checker, name *ast.Node, text string, quote bool, isMarkdown bool) {
1059 declarations := getDeclarationsFromLocation(c, name)
1060 if len(declarations) != 0 {
1061 declaration := declarations[0]
1062 file := ast.GetSourceFileOfNode(declaration)
1063 node := core.OrElse(ast.GetNameOfDeclaration(declaration), declaration)
1064 loc := l.getMappedLocation(file.FileName(), createRangeFromNode(node, file))
1065 prefixLen := core.IfElse(strings.HasPrefix(text, "()"), 2, 0)
1066 linkText := trimCommentPrefix(text[prefixLen:])
1067 if linkText == "" {
1068 linkText = getEntityNameString(name) + text[:prefixLen]
1069 }
1070 if isMarkdown {
1071 linkUri := fmt.Sprintf("%s#%d,%d-%d,%d", loc.Uri, loc.Range.Start.Line+1, loc.Range.Start.Character+1, loc.Range.End.Line+1, loc.Range.End.Character+1)
1072 writeMarkdownLink(b, linkText, linkUri, quote)
1073 } else {
1074 writeQuotedString(b, linkText, false)
1075 }
1076 return
1077 }
1078 writeQuotedString(b, getEntityNameString(name)+core.IfElse(len(text) != 0, " ", "")+text, quote && isMarkdown)
1079}
1080
1081func trimCommentPrefix(text string) string {
1082 return strings.TrimLeft(strings.TrimPrefix(strings.TrimLeft(text, " "), "|"), " ")

Callers 2

writeJSDocLinkMethod · 0.95

Calls 13

getMappedLocationMethod · 0.95
GetSourceFileOfNodeFunction · 0.92
OrElseFunction · 0.92
GetNameOfDeclarationFunction · 0.92
IfElseFunction · 0.92
lenFunction · 0.85
createRangeFromNodeFunction · 0.85
trimCommentPrefixFunction · 0.85
getEntityNameStringFunction · 0.85
writeMarkdownLinkFunction · 0.85
writeQuotedStringFunction · 0.85

Tested by

no test coverage detected