( ctx context.Context, documentURI lsproto.DocumentUri, position lsproto.Position, )
| 98 | } |
| 99 | |
| 100 | func (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 | |
| 137 | func getDeclarationNameForKeyword(node *ast.Node) *ast.Node { |
| 138 | if node.Kind >= ast.KindFirstKeyword && node.Kind <= ast.KindLastKeyword { |
no test coverage detected