aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_assists/src')
-rw-r--r--crates/ide_assists/src/lib.rs39
1 files changed, 36 insertions, 3 deletions
diff --git a/crates/ide_assists/src/lib.rs b/crates/ide_assists/src/lib.rs
index 397d2a3d0..01addffe9 100644
--- a/crates/ide_assists/src/lib.rs
+++ b/crates/ide_assists/src/lib.rs
@@ -17,6 +17,8 @@ mod tests;
17pub mod utils; 17pub mod utils;
18pub mod ast_transform; 18pub mod ast_transform;
19 19
20use std::str::FromStr;
21
20use hir::Semantics; 22use hir::Semantics;
21use ide_db::base_db::FileRange; 23use ide_db::base_db::FileRange;
22use ide_db::{label::Label, source_change::SourceChange, RootDatabase}; 24use ide_db::{label::Label, source_change::SourceChange, RootDatabase};
@@ -56,6 +58,35 @@ impl AssistKind {
56 _ => return false, 58 _ => return false,
57 } 59 }
58 } 60 }
61
62 pub fn name(&self) -> &str {
63 match self {
64 AssistKind::None => "None",
65 AssistKind::QuickFix => "QuickFix",
66 AssistKind::Generate => "Generate",
67 AssistKind::Refactor => "Refactor",
68 AssistKind::RefactorExtract => "RefactorExtract",
69 AssistKind::RefactorInline => "RefactorInline",
70 AssistKind::RefactorRewrite => "RefactorRewrite",
71 }
72 }
73}
74
75impl FromStr for AssistKind {
76 type Err = String;
77
78 fn from_str(s: &str) -> Result<Self, Self::Err> {
79 match s {
80 "None" => Ok(AssistKind::None),
81 "QuickFix" => Ok(AssistKind::QuickFix),
82 "Generate" => Ok(AssistKind::Generate),
83 "Refactor" => Ok(AssistKind::Refactor),
84 "RefactorExtract" => Ok(AssistKind::RefactorExtract),
85 "RefactorInline" => Ok(AssistKind::RefactorInline),
86 "RefactorRewrite" => Ok(AssistKind::RefactorRewrite),
87 unknown => Err(format!("Unknown AssistKind: '{}'", unknown)),
88 }
89 }
59} 90}
60 91
61/// Unique identifier of the assist, should not be shown to the user 92/// Unique identifier of the assist, should not be shown to the user
@@ -64,11 +95,11 @@ impl AssistKind {
64pub struct AssistId(pub &'static str, pub AssistKind); 95pub struct AssistId(pub &'static str, pub AssistKind);
65 96
66// TODO kb docs 97// TODO kb docs
67#[derive(Debug, Clone, Copy)] 98#[derive(Debug, Clone)]
68pub enum AssistResolveStrategy { 99pub enum AssistResolveStrategy {
69 None, 100 None,
70 All, 101 All,
71 Single(AssistId), 102 Single(String, AssistKind),
72} 103}
73 104
74impl AssistResolveStrategy { 105impl AssistResolveStrategy {
@@ -76,7 +107,9 @@ impl AssistResolveStrategy {
76 match self { 107 match self {
77 AssistResolveStrategy::None => false, 108 AssistResolveStrategy::None => false,
78 AssistResolveStrategy::All => true, 109 AssistResolveStrategy::All => true,
79 AssistResolveStrategy::Single(id_to_resolve) => id_to_resolve == id, 110 AssistResolveStrategy::Single(id_to_resolve, kind) => {
111 id_to_resolve == id.0 && kind == &id.1
112 }
80 } 113 }
81 } 114 }
82} 115}