diff options
| author | DropDemBits <r3usrlnd@gmail.com> | 2023-07-12 03:14:09 -0400 |
|---|---|---|
| committer | DropDemBits <r3usrlnd@gmail.com> | 2023-07-12 03:14:09 -0400 |
| commit | a1877df5a5166c0b4a129a68df75c76691692ee3 (patch) | |
| tree | 5ed81f08899099d93790b0e62ede9e2f1588991b | |
| parent | a3a02d01f389a5e49e57ab3a37224e4d31c71b6b (diff) | |
| download | rust-a1877df5a5166c0b4a129a68df75c76691692ee3.tar.gz rust-a1877df5a5166c0b4a129a68df75c76691692ee3.zip | |
Passthrough `is_snippet` for non-structured snippets
Structured snippets precisely track which text edits need to be marked as snippet text edits, but the cases where structured snippets aren't used but snippets are still present are for simple single text-edit changes, so it's perfectly fine to mark all one of them as being a snippet text edit
| -rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 6624e6c082a..3848ec004a0 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -887,12 +887,8 @@ fn outside_workspace_annotation_id() -> String { fn merge_text_and_snippet_edits( line_index: &LineIndex, edit: TextEdit, - snippet_edit: Option<SnippetEdit>, + snippet_edit: SnippetEdit, ) -> Vec<SnippetTextEdit> { - let Some(snippet_edit) = snippet_edit else { - return edit.into_iter().map(|it| snippet_text_edit(&line_index, false, it)).collect(); - }; - let mut edits: Vec<SnippetTextEdit> = vec![]; let mut snippets = snippet_edit.into_edit_ranges().into_iter().peekable(); let mut text_edits = edit.into_iter(); @@ -1009,13 +1005,18 @@ fn merge_text_and_snippet_edits( pub(crate) fn snippet_text_document_edit( snap: &GlobalStateSnapshot, + is_snippet: bool, file_id: FileId, edit: TextEdit, snippet_edit: Option<SnippetEdit>, ) -> Cancellable<lsp_ext::SnippetTextDocumentEdit> { let text_document = optional_versioned_text_document_identifier(snap, file_id); let line_index = snap.file_line_index(file_id)?; - let mut edits = merge_text_and_snippet_edits(&line_index, edit, snippet_edit); + let mut edits = if let Some(snippet_edit) = snippet_edit { + merge_text_and_snippet_edits(&line_index, edit, snippet_edit) + } else { + edit.into_iter().map(|it| snippet_text_edit(&line_index, is_snippet, it)).collect() + }; if snap.analysis.is_library_file(file_id)? && snap.config.change_annotation_support() { for edit in &mut edits { @@ -1098,9 +1099,10 @@ pub(crate) fn snippet_workspace_edit( for (file_id, (edit, snippet_edit)) in source_change.source_file_edits { let edit = snippet_text_document_edit( snap, + source_change.is_snippet, file_id, edit, - snippet_edit.filter(|_| source_change.is_snippet), + snippet_edit, )?; document_changes.push(lsp_ext::SnippetDocumentChangeOperation::Edit(edit)); } |
