]> git.lizzy.rs Git - rust.git/commitdiff
Address some FIXMEs
authorJmPotato <ghzpotato@gmail.com>
Tue, 11 Aug 2020 02:55:26 +0000 (10:55 +0800)
committerJmPotato <ghzpotato@gmail.com>
Tue, 11 Aug 2020 02:55:26 +0000 (10:55 +0800)
Signed-off-by: JmPotato <ghzpotato@gmail.com>
Cargo.lock
crates/ra_assists/Cargo.toml
crates/ra_assists/src/ast_transform.rs
crates/ra_assists/src/lib.rs
crates/rust-analyzer/src/handlers.rs
crates/rust-analyzer/src/to_proto.rs

index a094ec4f7aef0331a1ef11064b8c0764214adabf..936e863f52f8799eee732962e4815efe49608923 100644 (file)
@@ -912,6 +912,7 @@ dependencies = [
  "ra_db",
  "ra_fmt",
  "ra_hir",
+ "ra_hir_expand",
  "ra_ide_db",
  "ra_prof",
  "ra_syntax",
index bd2905f080af30b0e6c1a2ca1302bd2b2b1fbb28..a436e861d7ec7a15258b4b7cef36868c025f4275 100644 (file)
@@ -22,4 +22,5 @@ ra_prof = { path = "../ra_prof" }
 ra_db = { path = "../ra_db" }
 ra_ide_db = { path = "../ra_ide_db" }
 hir = { path = "../ra_hir", package = "ra_hir" }
+hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" }
 test_utils = { path = "../test_utils" }
index 15ec75c956a50827b982a86a5832ec338ff1680b..02c4a4baeb0c7d27d7045bd7b49f2e06c42058c7 100644 (file)
@@ -2,6 +2,7 @@
 use rustc_hash::FxHashMap;
 
 use hir::{HirDisplay, PathResolution, SemanticsScope};
+use hir_expand::hygiene::Hygiene;
 use ra_syntax::{
     algo::SyntaxRewriter,
     ast::{self, AstNode},
@@ -51,7 +52,7 @@ pub fn for_trait_impl(
             // this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky
             .skip(1)
             // The actual list of trait type parameters may be longer than the one
-            // used in the `impl` block due to trailing default type parametrs.
+            // used in the `impl` block due to trailing default type parameters.
             // For that case we extend the `substs` with an empty iterator so we
             // can still hit those trailing values and check if they actually have
             // a default type. If they do, go for that type from `hir` to `ast` so
@@ -110,9 +111,7 @@ fn get_substitution_inner(
             ast::Type::PathType(path_type) => path_type.path()?,
             _ => return None,
         };
-        // FIXME: use `hir::Path::from_src` instead.
-        #[allow(deprecated)]
-        let path = hir::Path::from_ast(path)?;
+        let path = hir::Path::from_src(path, &Hygiene::new_unhygienic())?;
         let resolution = self.source_scope.resolve_hir_path(&path)?;
         match resolution {
             hir::PathResolution::TypeParam(tp) => Some(self.substs.get(&tp)?.syntax().clone()),
@@ -152,10 +151,8 @@ fn get_substitution_inner(
             // don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway
             return None;
         }
-        // FIXME: use `hir::Path::from_src` instead.
-        #[allow(deprecated)]
-        let hir_path = hir::Path::from_ast(p.clone());
-        let resolution = self.source_scope.resolve_hir_path(&hir_path?)?;
+        let hir_path = hir::Path::from_src(p.clone(), &Hygiene::new_unhygienic())?;
+        let resolution = self.source_scope.resolve_hir_path(&hir_path)?;
         match resolution {
             PathResolution::Def(def) => {
                 let found_path = from.find_use_path(self.source_scope.db.upcast(), def)?;
index 507646cc802899573e1b8a1807b43b5fb4ea0fb1..890996a68d9bd347f2da0c092c287c1d418b13e5 100644 (file)
@@ -66,13 +66,13 @@ pub fn contains(self, other: AssistKind) -> bool {
 
 #[derive(Debug, Clone)]
 pub struct Assist {
-    pub id: AssistId,
+    id: AssistId,
     /// Short description of the assist, as shown in the UI.
-    pub label: String,
-    pub group: Option<GroupLabel>,
+    label: String,
+    group: Option<GroupLabel>,
     /// Target ranges are used to sort assists: the smaller the target range,
     /// the more specific assist is, and so it should be sorted first.
-    pub target: TextRange,
+    target: TextRange,
 }
 
 #[derive(Debug, Clone)]
@@ -120,10 +120,25 @@ pub(crate) fn new(
         group: Option<GroupLabel>,
         target: TextRange,
     ) -> Assist {
-        // FIXME: make fields private, so that this invariant can't be broken
         assert!(label.starts_with(|c: char| c.is_uppercase()));
         Assist { id, label, group, target }
     }
+
+    pub fn id(&self) -> AssistId {
+        self.id
+    }
+
+    pub fn label(&self) -> String {
+        self.label.clone()
+    }
+
+    pub fn group(&self) -> Option<GroupLabel> {
+        self.group.clone()
+    }
+
+    pub fn target(&self) -> TextRange {
+        self.target
+    }
 }
 
 mod handlers {
index 895af1dd78e5fab3d6ad9417c4cdcaa55799ff2d..c2afcf192dedbc0c3040b0d41fc6700e70f27435 100644 (file)
@@ -864,7 +864,7 @@ pub(crate) fn handle_resolve_code_action(
     let (id_string, index) = split_once(&params.id, ':').unwrap();
     let index = index.parse::<usize>().unwrap();
     let assist = &assists[index];
-    assert!(assist.assist.id.0 == id_string);
+    assert!(assist.assist.id().0 == id_string);
     Ok(to_proto::resolved_code_action(&snap, assist.clone())?.edit)
 }
 
index 27460db78cc28c8344dc9e2e07cac767a0ff6f50..62fda8a1f20cffd0e23a65726d2bcc36cc2f2dcb 100644 (file)
@@ -704,10 +704,10 @@ pub(crate) fn unresolved_code_action(
     index: usize,
 ) -> Result<lsp_ext::CodeAction> {
     let res = lsp_ext::CodeAction {
-        title: assist.label,
-        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(code_action_kind(assist.id.1)),
+        title: assist.label(),
+        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(code_action_kind(assist.id().1)),
         edit: None,
         is_preferred: None,
     };