aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2021-05-03 16:16:35 +0100
committerKirill Bulatov <[email protected]>2021-05-03 16:16:35 +0100
commit28293d370ffc4270bb6244579166f0df18962951 (patch)
treefe1261ad5d053b5f1a60b98456c2f3ecca7452e3 /crates
parent1679a376f30c5ad8971c0f855074a3f489fee5fa (diff)
Add docs and use better naming
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/lib.rs4
-rw-r--r--crates/ide_assists/src/lib.rs25
-rw-r--r--crates/rust-analyzer/src/handlers.rs4
3 files changed, 25 insertions, 8 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index 6a88236e3..8e5b72044 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -87,7 +87,9 @@ pub use crate::{
87 }, 87 },
88}; 88};
89pub use hir::{Documentation, Semantics}; 89pub use hir::{Documentation, Semantics};
90pub use ide_assists::{Assist, AssistConfig, AssistId, AssistKind, AssistResolveStrategy}; 90pub use ide_assists::{
91 Assist, AssistConfig, AssistId, AssistKind, AssistResolveStrategy, SingleResolve,
92};
91pub use ide_completion::{ 93pub use ide_completion::{
92 CompletionConfig, CompletionItem, CompletionItemKind, CompletionRelevance, ImportEdit, 94 CompletionConfig, CompletionItem, CompletionItemKind, CompletionRelevance, ImportEdit,
93 InsertTextFormat, 95 InsertTextFormat,
diff --git a/crates/ide_assists/src/lib.rs b/crates/ide_assists/src/lib.rs
index 01addffe9..5a0047f03 100644
--- a/crates/ide_assists/src/lib.rs
+++ b/crates/ide_assists/src/lib.rs
@@ -94,12 +94,27 @@ impl FromStr for AssistKind {
94#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 94#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
95pub struct AssistId(pub &'static str, pub AssistKind); 95pub struct AssistId(pub &'static str, pub AssistKind);
96 96
97// TODO kb docs 97/// A way to control how many asssist to resolve during the assist resolution.
98#[derive(Debug, Clone)] 98/// When an assist is resolved, its edits are calculated that might be costly to always do by default.
99#[derive(Debug)]
99pub enum AssistResolveStrategy { 100pub enum AssistResolveStrategy {
101 /// No assists should be resolved.
100 None, 102 None,
103 /// All assists should be resolved.
101 All, 104 All,
102 Single(String, AssistKind), 105 /// Only a certain assists should be resolved.
106 Single(SingleResolve),
107}
108
109/// Hold the [`AssistId`] data of a certain assist to resolve.
110/// The original id object cannot be used due to a `'static` lifetime
111/// and the requirement to construct this struct dynamically during the resolve handling.
112#[derive(Debug)]
113pub struct SingleResolve {
114 /// The id of the assist.
115 pub assist_id: String,
116 // The kind of the assist.
117 pub assist_kind: AssistKind,
103} 118}
104 119
105impl AssistResolveStrategy { 120impl AssistResolveStrategy {
@@ -107,8 +122,8 @@ impl AssistResolveStrategy {
107 match self { 122 match self {
108 AssistResolveStrategy::None => false, 123 AssistResolveStrategy::None => false,
109 AssistResolveStrategy::All => true, 124 AssistResolveStrategy::All => true,
110 AssistResolveStrategy::Single(id_to_resolve, kind) => { 125 AssistResolveStrategy::Single(single_resolve) => {
111 id_to_resolve == id.0 && kind == &id.1 126 single_resolve.assist_id == id.0 && single_resolve.assist_kind == id.1
112 } 127 }
113 } 128 }
114 } 129 }
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index cd6bbf303..304951b7d 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -10,7 +10,7 @@ use std::{
10use ide::{ 10use ide::{
11 AnnotationConfig, AssistKind, AssistResolveStrategy, FileId, FilePosition, FileRange, 11 AnnotationConfig, AssistKind, AssistResolveStrategy, FileId, FilePosition, FileRange,
12 HoverAction, HoverGotoTypeData, Query, RangeInfo, Runnable, RunnableKind, SearchScope, 12 HoverAction, HoverGotoTypeData, Query, RangeInfo, Runnable, RunnableKind, SearchScope,
13 SourceChange, TextEdit, 13 SingleResolve, SourceChange, TextEdit,
14}; 14};
15use ide_db::SymbolKind; 15use ide_db::SymbolKind;
16use itertools::Itertools; 16use itertools::Itertools;
@@ -1072,7 +1072,7 @@ pub(crate) fn handle_code_action_resolve(
1072 let assists = snap.analysis.assists_with_fixes( 1072 let assists = snap.analysis.assists_with_fixes(
1073 &assists_config, 1073 &assists_config,
1074 &snap.config.diagnostics(), 1074 &snap.config.diagnostics(),
1075 AssistResolveStrategy::Single(params.id.clone(), assist_kind), 1075 AssistResolveStrategy::Single(SingleResolve { assist_id: params.id.clone(), assist_kind }),
1076 frange, 1076 frange,
1077 )?; 1077 )?;
1078 1078