]> git.lizzy.rs Git - rust.git/blobdiff - crates/rust-analyzer/src/to_proto.rs
Merge branch 'master' into compute-lazy-assits
[rust.git] / crates / rust-analyzer / src / to_proto.rs
index 0915a7fcb786c5bcc26d760f85032bd4c6f09c80..1da4d80eceab0cabae2a4c55040c08849abf92f0 100644 (file)
@@ -3,8 +3,8 @@
 use ra_ide::{
     Assist, CompletionItem, CompletionItemKind, Documentation, FileSystemEdit, Fold, FoldKind,
     FunctionSignature, Highlight, HighlightModifier, HighlightTag, HighlightedRange, Indel,
-    InlayHint, InlayKind, InsertTextFormat, LineIndex, NavigationTarget, ReferenceAccess, Runnable,
-    RunnableKind, Severity, SourceChange, SourceFileEdit, TextEdit,
+    InlayHint, InlayKind, InsertTextFormat, LineIndex, NavigationTarget, ReferenceAccess,
+    ResolvedAssist, Runnable, RunnableKind, Severity, SourceChange, SourceFileEdit, TextEdit,
 };
 use ra_syntax::{SyntaxKind, TextRange, TextSize};
 use ra_vfs::LineEndings;
@@ -623,20 +623,36 @@ fn main() <fold>{
     }
 }
 
-pub(crate) fn code_action(
+pub(crate) fn unresolved_code_action(
     snap: &GlobalStateSnapshot,
     assist: Assist,
+    index: usize,
 ) -> Result<lsp_ext::CodeAction> {
     let res = lsp_ext::CodeAction {
         title: assist.label,
-        group: if snap.config.client_caps.code_action_group { assist.group_label } else { None },
+        id: Some(format!("{}:{}", assist.id.0.to_owned(), index.to_string())),
+        group: assist.group.filter(|_| snap.config.client_caps.code_action_group).map(|gr| gr.0),
         kind: Some(String::new()),
-        edit: Some(snippet_workspace_edit(snap, assist.source_change)?),
+        edit: None,
         command: None,
     };
     Ok(res)
 }
 
+pub(crate) fn resolved_code_action(
+    snap: &GlobalStateSnapshot,
+    assist: ResolvedAssist,
+) -> Result<lsp_ext::CodeAction> {
+    let change = assist.source_change;
+    unresolved_code_action(snap, assist.assist, 0).and_then(|it| {
+        Ok(lsp_ext::CodeAction {
+            id: None,
+            edit: Some(snippet_workspace_edit(snap, change)?),
+            ..it
+        })
+    })
+}
+
 pub(crate) fn runnable(
     snap: &GlobalStateSnapshot,
     file_id: FileId,