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

Method ProvideTypeDefinition

internal/ls/definition.go:100–135  ·  view source on GitHub ↗
(
	ctx context.Context,
	documentURI lsproto.DocumentUri,
	position lsproto.Position,
)

Source from the content-addressed store, hash-verified

98}
99
100func (l *LanguageService) ProvideTypeDefinition(
101 ctx context.Context,
102 documentURI lsproto.DocumentUri,
103 position lsproto.Position,
104) (lsproto.TypeDefinitionResponse, error) {
105 caps := lsproto.GetClientCapabilities(ctx)
106 clientSupportsLink := caps.TextDocument.TypeDefinition.LinkSupport
107
108 program, file := l.getProgramAndFile(documentURI)
109 node := astnav.GetTouchingPropertyName(file, int(l.converters.LineAndCharacterToPosition(file, position)))
110 if node.Kind == ast.KindSourceFile {
111 return lsproto.LocationOrLocationsOrDefinitionLinksOrNull{}, nil
112 }
113 originSelectionRange := l.createLspRangeFromNode(node, file)
114
115 c, done := program.GetTypeCheckerForFile(ctx, file)
116 defer done()
117
118 node = getDeclarationNameForKeyword(node)
119
120 if symbol := c.GetSymbolAtLocation(node); symbol != nil {
121 symbolType := getTypeOfSymbolAtLocation(c, symbol, node)
122 declarations := getDeclarationsFromType(symbolType)
123 if typeArgument := c.GetFirstTypeArgumentFromKnownType(symbolType); typeArgument != nil {
124 declarations = core.Concatenate(getDeclarationsFromType(typeArgument), declarations)
125 }
126 if len(declarations) != 0 {
127 return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, declarations, nil /*reference*/), nil
128 }
129 if symbol.Flags&ast.SymbolFlagsValue == 0 && symbol.Flags&ast.SymbolFlagsType != 0 {
130 return l.createDefinitionLocations(originSelectionRange, clientSupportsLink, symbol.Declarations, nil /*reference*/), nil
131 }
132 }
133
134 return lsproto.LocationOrLocationsOrDefinitionLinksOrNull{}, nil
135}
136
137func getDeclarationNameForKeyword(node *ast.Node) *ast.Node {
138 if node.Kind >= ast.KindFirstKeyword && node.Kind <= ast.KindLastKeyword {

Callers 1

handleTypeDefinitionMethod · 0.80

Calls 15

getProgramAndFileMethod · 0.95
GetClientCapabilitiesFunction · 0.92
GetTouchingPropertyNameFunction · 0.92
ConcatenateFunction · 0.92
getDeclarationsFromTypeFunction · 0.85
lenFunction · 0.85
GetTypeCheckerForFileMethod · 0.80

Tested by

no test coverage detected