"ra_db",
"ra_fmt",
"ra_hir",
+ "ra_hir_expand",
"ra_ide_db",
"ra_prof",
"ra_syntax",
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" }
use rustc_hash::FxHashMap;
use hir::{HirDisplay, PathResolution, SemanticsScope};
+use hir_expand::hygiene::Hygiene;
use ra_syntax::{
algo::SyntaxRewriter,
ast::{self, AstNode},
// 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
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()),
// 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)?;
#[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)]
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 {
let (id_string, index) = split_once(¶ms.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: 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,
};