RLovelett / langserver-swift

A Swift implementation of the open Language Server Protocol.
Apache License 2.0
177 stars 16 forks source link

Implement textDocument/references request and response for the language server #4

Open RLovelett opened 7 years ago

RLovelett commented 7 years ago

SourceKit

textdocument-references.txt

chrismwendt commented 6 years ago

I'm working on this right now. @RLovelett How did you generate that output? Did you run a sourcekitten command?

RLovelett commented 6 years ago

This is actually output from Xcode itself showing the communication between Xcode and SourceKit (not to be confused with sourcekitten).

To get this output I launched Xcode from my terminal and set the appropriate SOURCEKIT_LOGGING environment variable. I believe this one was SOURCEKIT_LOGGING=3 but I'm not 100% sure, might have been 2. More reading about SOURCEKIT_LOGGING.

So the full command that I used looked something like this:

$ export SOURCEKIT_LOGGING=3
$ /Applications/Xcode.app/Contents/MacOS/Xcode 2>&1 | tee /Users/ryan/Desktop/sourcekit.log

Then I just read through the logs until I found what I was looking for.

The the best SourceKit tools are not bundled with Swift and are only available if you build from source. They are complete-test, sourcekitd-repl, and sourcekitd-test.

Good luck and happy coding!

chrismwendt commented 6 years ago

Thanks for showing how to get the logs 🙇

symbol-occurrences is not recognized by sourcekitd-test:

{
  key.request: source.request.workspace.symbol-occurrences,
  key.symbol: {
    key.indexer.arg.symbol.name: "cursor(forText:)",
    key.indexer.arg.symbol.kind: "Xcode.SourceCodeSymbolKind.InstanceMethod",
    key.indexer.arg.symbol.language: "Xcode.SourceCodeLanguage.Swift",
    key.indexer.arg.symbol.resolution: "s:22LanguageServerProtocol0B0C6cursorAA5HoverVAA26TextDocumentPositionParamsV03forF0_tKF"
  },
  key.indexer.arg.indexer-token: 1
}

I get error response (Request Invalid): missing 'key.sourcefile' or 'key.sourcetext', and when I add that:

{
  key.request: source.request.workspace.symbol-occurrences,
  key.sourcefile: "/Users/chrismwendt/langserver-swift/Sources/LanguageServerProtocol/Types/Server.swift",
  key.symbol: {
    key.indexer.arg.symbol.name: "cursor(forText:)",
    key.indexer.arg.symbol.kind: "Xcode.SourceCodeSymbolKind.InstanceMethod",
    key.indexer.arg.symbol.language: "Xcode.SourceCodeLanguage.Swift",
    key.indexer.arg.symbol.resolution: "s:22LanguageServerProtocol0B0C6cursorAA5HoverVAA26TextDocumentPositionParamsV03forF0_tKF"
  },
  key.indexer.arg.indexer-token: 1
}

I get error response (Request Invalid): unknown request: source.request.workspace.symbol-occurrences.

The phrase symbol-occurrences doesn't exist anywhere in the Swift source code https://github.com/apple/swift/search?utf8=%E2%9C%93&q=symbol-ccurrences&type= (I also tried grepping locally). It's so rare that only a few repositories on all of GitHub contain it - and only 1 (yes, a single repository!) contains it in code added in https://github.com/rockbruno/swiftshield/commit/2a9057c5d4395810c6e3339473234122b26fb7aa#diff-1c6eecbb05d27f9e21cec2258e9fcef4R181 It's a GitHubWhack 🙀

Do you know if Xcode ships with these additional features that the open-source SourceKit doesn't ship with?

I'll be digging into the source code of SourceKit to see if there's an alternative to symbol-occurrences.

RLovelett commented 6 years ago

Do you know if Xcode ships with these additional features that the open-source SourceKit doesn't ship with?

I do not but it would not shock me at all if they did.

Are you getting symbol-occurrences in the current release of Xcode? It's entirely possible that they used to have that and have since deprecated it. I don't know if GitHub searches/indexes every commit or just the latest of the default branch (I'm 90% sure it does not search branches at all).

chrismwendt commented 6 years ago

I'm on Xcode 9.4 (9F1027a) which appears to be the latest

I also did a git log -S symbol-occurrences in apple/swift and didn't find it, so it looks like it never existed in that repository.

GitHub indexes all master-branch commit messages (not diffs), and the file contents of the tip of master (not any older commits, and no other branches).

I'll see about talking to some folks at Apple about this next week if I can, and I'll report back.