sourcekit-lsp icon indicating copy to clipboard operation
sourcekit-lsp copied to clipboard

[SR-10807] Implement textDocument/typeDefinition request

Open benlangmuir opened this issue 6 years ago • 0 comments

Previous ID SR-10807
Radar None
Original Reporter @benlangmuir
Type New Feature

Additional Detail from JIRA
Votes 0
Component/s SourceKit-LSP
Labels New Feature, StarterBug
Assignee None
Priority Medium

md5: 48898578051a40902ab5b8e1104d1a38

Issue Description:

Implement the textDocument/typeDefinition request, which given a source location finds the type of the symbol at that position and then returns the location of that type's definition.

https://microsoft.github.io/language-server-protocol/specification#textDocument_typeDefinition

To implement this, you can look at how the existing jump to defintiion request works (textDocument/definition), ~~but instead of using the key.usr field to get the declaration's USR, you can use the key.typeusr field.~~

Edit: it turns out typeusr is not suitable for this (https://forums.swift.org/t/usr-vs-typeusr-in-sourcekit/27759). It looks like to implement this we'll need to add a new field to sourcekitd's cursor_info. We want the USR of the type decl when that is available. For example,

var a =1 // a-> Int
var b = [1] // b -> Array
var c = (1, 2) // c -> nil
func test<T>(d: [T]) {} // d-> Array

So for a bound generic type like `Dictionary<Foo, Bar>`, we want to get the Dictionary decl's USR. When the type is non-nominal, such as a tuple or function type, we can just return null.

rdar://95597953

benlangmuir avatar May 30 '19 22:05 benlangmuir