aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--crates/ra_assists/Cargo.toml1
-rw-r--r--crates/ra_assists/src/ast_transform.rs13
-rw-r--r--crates/ra_assists/src/lib.rs25
-rw-r--r--crates/rust-analyzer/src/handlers.rs2
-rw-r--r--crates/rust-analyzer/src/to_proto.rs8
6 files changed, 32 insertions, 18 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a094ec4f7..936e863f5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -912,6 +912,7 @@ dependencies = [
912 "ra_db", 912 "ra_db",
913 "ra_fmt", 913 "ra_fmt",
914 "ra_hir", 914 "ra_hir",
915 "ra_hir_expand",
915 "ra_ide_db", 916 "ra_ide_db",
916 "ra_prof", 917 "ra_prof",
917 "ra_syntax", 918 "ra_syntax",
diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml
index bd2905f08..a436e861d 100644
--- a/crates/ra_assists/Cargo.toml
+++ b/crates/ra_assists/Cargo.toml
@@ -22,4 +22,5 @@ ra_prof = { path = "../ra_prof" }
22ra_db = { path = "../ra_db" } 22ra_db = { path = "../ra_db" }
23ra_ide_db = { path = "../ra_ide_db" } 23ra_ide_db = { path = "../ra_ide_db" }
24hir = { path = "../ra_hir", package = "ra_hir" } 24hir = { path = "../ra_hir", package = "ra_hir" }
25hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" }
25test_utils = { path = "../test_utils" } 26test_utils = { path = "../test_utils" }
diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs
index 15ec75c95..02c4a4bae 100644
--- a/crates/ra_assists/src/ast_transform.rs
+++ b/crates/ra_assists/src/ast_transform.rs
@@ -2,6 +2,7 @@
2use rustc_hash::FxHashMap; 2use rustc_hash::FxHashMap;
3 3
4use hir::{HirDisplay, PathResolution, SemanticsScope}; 4use hir::{HirDisplay, PathResolution, SemanticsScope};
5use hir_expand::hygiene::Hygiene;
5use ra_syntax::{ 6use ra_syntax::{
6 algo::SyntaxRewriter, 7 algo::SyntaxRewriter,
7 ast::{self, AstNode}, 8 ast::{self, AstNode},
@@ -51,7 +52,7 @@ impl<'a> SubstituteTypeParams<'a> {
51 // this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky 52 // this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky
52 .skip(1) 53 .skip(1)
53 // The actual list of trait type parameters may be longer than the one 54 // The actual list of trait type parameters may be longer than the one
54 // used in the `impl` block due to trailing default type parametrs. 55 // used in the `impl` block due to trailing default type parameters.
55 // For that case we extend the `substs` with an empty iterator so we 56 // For that case we extend the `substs` with an empty iterator so we
56 // can still hit those trailing values and check if they actually have 57 // can still hit those trailing values and check if they actually have
57 // a default type. If they do, go for that type from `hir` to `ast` so 58 // a default type. If they do, go for that type from `hir` to `ast` so
@@ -110,9 +111,7 @@ impl<'a> SubstituteTypeParams<'a> {
110 ast::Type::PathType(path_type) => path_type.path()?, 111 ast::Type::PathType(path_type) => path_type.path()?,
111 _ => return None, 112 _ => return None,
112 }; 113 };
113 // FIXME: use `hir::Path::from_src` instead. 114 let path = hir::Path::from_src(path, &Hygiene::new_unhygienic())?;
114 #[allow(deprecated)]
115 let path = hir::Path::from_ast(path)?;
116 let resolution = self.source_scope.resolve_hir_path(&path)?; 115 let resolution = self.source_scope.resolve_hir_path(&path)?;
117 match resolution { 116 match resolution {
118 hir::PathResolution::TypeParam(tp) => Some(self.substs.get(&tp)?.syntax().clone()), 117 hir::PathResolution::TypeParam(tp) => Some(self.substs.get(&tp)?.syntax().clone()),
@@ -152,10 +151,8 @@ impl<'a> QualifyPaths<'a> {
152 // don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway 151 // don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway
153 return None; 152 return None;
154 } 153 }
155 // FIXME: use `hir::Path::from_src` instead. 154 let hir_path = hir::Path::from_src(p.clone(), &Hygiene::new_unhygienic())?;
156 #[allow(deprecated)] 155 let resolution = self.source_scope.resolve_hir_path(&hir_path)?;
157 let hir_path = hir::Path::from_ast(p.clone());
158 let resolution = self.source_scope.resolve_hir_path(&hir_path?)?;
159 match resolution { 156 match resolution {
160 PathResolution::Def(def) => { 157 PathResolution::Def(def) => {
161 let found_path = from.find_use_path(self.source_scope.db.upcast(), def)?; 158 let found_path = from.find_use_path(self.source_scope.db.upcast(), def)?;
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index 507646cc8..890996a68 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -66,13 +66,13 @@ pub struct GroupLabel(pub String);
66 66
67#[derive(Debug, Clone)] 67#[derive(Debug, Clone)]
68pub struct Assist { 68pub struct Assist {
69 pub id: AssistId, 69 id: AssistId,
70 /// Short description of the assist, as shown in the UI. 70 /// Short description of the assist, as shown in the UI.
71 pub label: String, 71 label: String,
72 pub group: Option<GroupLabel>, 72 group: Option<GroupLabel>,
73 /// Target ranges are used to sort assists: the smaller the target range, 73 /// Target ranges are used to sort assists: the smaller the target range,
74 /// the more specific assist is, and so it should be sorted first. 74 /// the more specific assist is, and so it should be sorted first.
75 pub target: TextRange, 75 target: TextRange,
76} 76}
77 77
78#[derive(Debug, Clone)] 78#[derive(Debug, Clone)]
@@ -120,10 +120,25 @@ impl Assist {
120 group: Option<GroupLabel>, 120 group: Option<GroupLabel>,
121 target: TextRange, 121 target: TextRange,
122 ) -> Assist { 122 ) -> Assist {
123 // FIXME: make fields private, so that this invariant can't be broken
124 assert!(label.starts_with(|c: char| c.is_uppercase())); 123 assert!(label.starts_with(|c: char| c.is_uppercase()));
125 Assist { id, label, group, target } 124 Assist { id, label, group, target }
126 } 125 }
126
127 pub fn id(&self) -> AssistId {
128 self.id
129 }
130
131 pub fn label(&self) -> String {
132 self.label.clone()
133 }
134
135 pub fn group(&self) -> Option<GroupLabel> {
136 self.group.clone()
137 }
138
139 pub fn target(&self) -> TextRange {
140 self.target
141 }
127} 142}
128 143
129mod handlers { 144mod handlers {
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 895af1dd7..c2afcf192 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -864,7 +864,7 @@ pub(crate) fn handle_resolve_code_action(
864 let (id_string, index) = split_once(&params.id, ':').unwrap(); 864 let (id_string, index) = split_once(&params.id, ':').unwrap();
865 let index = index.parse::<usize>().unwrap(); 865 let index = index.parse::<usize>().unwrap();
866 let assist = &assists[index]; 866 let assist = &assists[index];
867 assert!(assist.assist.id.0 == id_string); 867 assert!(assist.assist.id().0 == id_string);
868 Ok(to_proto::resolved_code_action(&snap, assist.clone())?.edit) 868 Ok(to_proto::resolved_code_action(&snap, assist.clone())?.edit)
869} 869}
870 870
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 27460db78..62fda8a1f 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -704,10 +704,10 @@ pub(crate) fn unresolved_code_action(
704 index: usize, 704 index: usize,
705) -> Result<lsp_ext::CodeAction> { 705) -> Result<lsp_ext::CodeAction> {
706 let res = lsp_ext::CodeAction { 706 let res = lsp_ext::CodeAction {
707 title: assist.label, 707 title: assist.label(),
708 id: Some(format!("{}:{}", assist.id.0.to_owned(), index.to_string())), 708 id: Some(format!("{}:{}", assist.id().0.to_owned(), index.to_string())),
709 group: assist.group.filter(|_| snap.config.client_caps.code_action_group).map(|gr| gr.0), 709 group: assist.group().filter(|_| snap.config.client_caps.code_action_group).map(|gr| gr.0),
710 kind: Some(code_action_kind(assist.id.1)), 710 kind: Some(code_action_kind(assist.id().1)),
711 edit: None, 711 edit: None,
712 is_preferred: None, 712 is_preferred: None,
713 }; 713 };