Skip to content
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

Use CompletionTextEdit::InsertAndReplace if supported by the client #8410

Merged
merged 1 commit into from Apr 10, 2021

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Apr 7, 2021

Fixes #8404, Fixes #3130

@matklad
Copy link
Member

matklad commented Apr 7, 2021

completed will replace the entire identifier which might be unwanted(

i think LSP now allows specifying both “append” and “replace” behavior in a single completion. Some times the user wants one, and sometimes the other. I haven’t looked into this closely yet.

@Veykril
Copy link
Member Author

Veykril commented Apr 7, 2021

Looks like it, CompletionClientCapabilities has a insertReplaceSupport capability which seems to be what you mean, will take a look at that.

@Veykril Veykril changed the title Don't overwrite identifiers when completing lifetimes Use CompletionTextEdit::InsertAndReplace if supported by the client Apr 8, 2021
@Veykril
Copy link
Member Author

Veykril commented Apr 8, 2021

Seems to work like a charm.

For context from the lsp docs:

/**
	 * An edit which is applied to a document when selecting this completion.
	 * When an edit is provided the value of `insertText` is ignored.
	 *
	 * *Note:* The range of the edit must be a single line range and it must
	 * contain the position at which completion has been requested.
	 *
	 * Most editors support two different operations when accepting a completion
	 * item. One is to insert a completion text and the other is to replace an
	 * existing text with a completion text. Since this can usually not be
	 * predetermined by a server it can report both ranges. Clients need to
	 * signal support for `InsertReplaceEdit`s via the
	 * `textDocument.completion.insertReplaceSupport` client capability
	 * property.
	 *
	 * *Note 1:* The text edit's range as well as both ranges from an insert
	 * replace edit must be a [single line] and they must contain the position
	 * at which completion has been requested.
	 * *Note 2:* If an `InsertReplaceEdit` is returned the edit's insert range
	 * must be a prefix of the edit's replace range, that means it must be
	 * contained and starting at the same position.
	 *
	 * @since 3.16.0 additional type `InsertReplaceEdit`
	 */
	textEdit?: TextEdit | InsertReplaceEdit;

@Veykril Veykril force-pushed the lt-comp branch 3 times, most recently from 1b84e98 to 593446f Compare April 8, 2021 00:47
@lnicola
Copy link
Member

lnicola commented Apr 8, 2021

Does this also close #3130?

@Veykril
Copy link
Member Author

Veykril commented Apr 8, 2021

That would also close that issue yes

@Veykril
Copy link
Member Author

Veykril commented Apr 10, 2021

bors r+
changelog feature Support InsertReplaceSupport capability
Not entirely sure if this counts as feature or something else

@bors
Copy link
Contributor

bors bot commented Apr 10, 2021

@bors bors bot merged commit 0fac165 into rust-lang:master Apr 10, 2021
@Veykril Veykril deleted the lt-comp branch April 10, 2021 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lifetime autocompletion consumes type [Code] Insert/replace completion behavior
3 participants