-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code completion items are duplicated and in alphabetical order #783
Comments
I've never seen duplicates before. Do you know where those symbols |
Ok the |
Here is an issue about the sorting swiftlang/sourcekit-lsp#1234. |
It looks like they're coming from header files in the macOS SDK, such as these: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Headers/MacErrors.h |
OK I got slightly further with this now. The duplicate entries are due to Vapor exporting all the symbols from Foundation and SourceKit-LSP not expecting this. You will find this in the Vapor codebase @_exported import Foundation I've added another issue to the SourceKit-LSP swiftlang/swift#74076 |
Describe the bug
I'm seeing two issues with code completion. Apologies if this should have been two separate tickets, but the solution I have for both is in the same part of code.
Completion items are getting sorted in alphabetical order. However, if you turn on verbose logging for sourcekit-lsp and look at what comes back from
textDocument/completion
, you can see that the ordering of completion items is not alphabetical, and the top results are likely to match with contextual information such as a function return type, and thus be more useful. The problem is that this extension doesn't have a handler defined for completion items, and it seems that VS Code's default behavior here is to sort on thelabel
field of the CompletionItem. This field is populated with symbol's text itself, so that's just alphabetical order.There are a lot of duplicate completion items. If you turn on verbose logging, you can see these duplicates in the sourcekit-lsp logs coming back for
textDocument/completion
. Each duplicate entry is an identical object in terms of content, but the order of keys is often different. The duplicates could be a bug in sourcekit-lsp, but I thought that reporting it here would be a good place to start, in case it was due to a bug in how this extension is using sourcekit-lsp.To Reproduce
These two issues should be reproducible from any project by just triggering code completion. However, I'm able to reproduce it every time by doing this:
vapor new repro-bug -y
and select postgres.t
in TodoController.swift on line 23:But here's the completion list order from
textDocument/completion
in the logs:Environment
Possible Solution
I've worked out a solution for the sorting issue, and a band-aid for the duplicates, via a completion item provider in the middleware section of clientOptions.
https://github.com/swift-server/vscode-swift/blob/main/src/sourcekit-lsp/LanguageClientManager.ts#L438
The above seems to have fixed the problems in my local, but this is the first time I've worked on VS Code extensions, for Swift or any language, so I'm pretty unfamiliar with all of this. Will it work as a solution?
The text was updated successfully, but these errors were encountered: