Uploaded image for project: 'Swift'
  1. Swift
  2. SR-10807

Implement textDocument/typeDefinition request

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: SourceKit-LSP
    • Labels:

      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.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            benlangmuir Ben Langmuir
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: