-
Notifications
You must be signed in to change notification settings - Fork 277
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
[completion] Filter completions on the server side #298
Merged
benlangmuir
merged 16 commits into
swiftlang:master
from
benlangmuir:completion-server-side-filtering1
Jul 29, 2020
Merged
[completion] Filter completions on the server side #298
benlangmuir
merged 16 commits into
swiftlang:master
from
benlangmuir:completion-server-side-filtering1
Jul 29, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* The interesting keys to split out are "code-completion options", not any key that is used by completion. * Sort the main key list * Fix the name of the doc_brief key
Similar to cursor info, there is enough code here it makes sense to separate it out.
Work in progress: add a basic implementation for keeping track of the current completion session, and use the sourcekitd complete.open/update/close requests.
With this change, tests pass whether we default to server-side or client-side filtering. Also duplicate a few interesting tests to run both ways. A future commit will beef up the test coverage for server-side filtering specifically.
By default, print 1-based line/column numbers using the defacto standard line:column format. In debug print, continue to use the 0-based values to match the constructor.
Since it is being used in the LSP protocol layer, give it a name that clarifies that it is SourceKit-specific.
@swift-ci please test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement server-side code-completion filtering and limit the number of completion items to 200 results by default. This radically improves the performance of code-completion when there are a large number of results by avoiding the cost of serialization of lower priority results. We take advantage of LSP's
isIncomplete
flag to inform the editor that as the user types more characters it should re-query SourceKit-LSP for completions in case there are results that were previously filtered out that are now relevant to the new filter text.I verified that server-side filtering is working in VSCode, Sublime Text, and vim (with coc.nvim). If any editors do not support
isIncomplete
yet, it is possible to disable server-side filtering.Configuration
initializationOptions
to SourceKit-LSP during theinitialize
request:textDocument/completion
request using the new parametersourcekitlspOptions
. This is intended mostly as a tool for experimentation and debugging.Note: In the initial implementation, setting
maxResults
to unlimited (0 or nil) will have worse performance than if you disabled server-side filtering. We should be able to close that gap, but for now I don't recommend using large values for maxResults.Implementation
When using server-side filtering, we keep track of a code-completion "session" for a given source file and completion location.
In the above example, the completion session will be for the location after "." at the start of the identifier, and the completion location (usually the cursor location) determines what the "filter text" for the completion will be, in this case "barB".
Once we open a session, any subsequent completion requests that have the same location and use
triggerKind == triggerFromIncompleteCompletions
will efficiently re-filter the existing completions. If the new completion location is not compatible with the session, we return an error rather than recompute completions so that editors can rely ontriggerFromIncompleteCompletions
always being really fast. Currently, any other trigger kind (manual or trigger character) will open a new completion session, although we could improve that in the future to reuse the session if no other changes have been made to the document.The underlying filtering uses sourcekitd's
complete.open
,complete.update
andcomplete.close
requests.