Address some FIXMEs

Signed-off-by: JmPotato <ghzpotato@gmail.com>
This commit is contained in:
JmPotato 2020-08-11 10:55:26 +08:00
parent b050937c10
commit dc6e1e0dac
6 changed files with 32 additions and 18 deletions

1
Cargo.lock generated
View File

@ -912,6 +912,7 @@ dependencies = [
"ra_db",
"ra_fmt",
"ra_hir",
"ra_hir_expand",
"ra_ide_db",
"ra_prof",
"ra_syntax",

View 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" }

View 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)?;

View 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 {

View 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)
}

View 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,
};