mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Address some FIXMEs
Signed-off-by: JmPotato <ghzpotato@gmail.com>
This commit is contained in:
parent
b050937c10
commit
dc6e1e0dac
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -912,6 +912,7 @@ dependencies = [
|
|||||||
"ra_db",
|
"ra_db",
|
||||||
"ra_fmt",
|
"ra_fmt",
|
||||||
"ra_hir",
|
"ra_hir",
|
||||||
|
"ra_hir_expand",
|
||||||
"ra_ide_db",
|
"ra_ide_db",
|
||||||
"ra_prof",
|
"ra_prof",
|
||||||
"ra_syntax",
|
"ra_syntax",
|
||||||
|
@ -22,4 +22,5 @@ ra_prof = { path = "../ra_prof" }
|
|||||||
ra_db = { path = "../ra_db" }
|
ra_db = { path = "../ra_db" }
|
||||||
ra_ide_db = { path = "../ra_ide_db" }
|
ra_ide_db = { path = "../ra_ide_db" }
|
||||||
hir = { path = "../ra_hir", package = "ra_hir" }
|
hir = { path = "../ra_hir", package = "ra_hir" }
|
||||||
|
hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" }
|
||||||
test_utils = { path = "../test_utils" }
|
test_utils = { path = "../test_utils" }
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use hir::{HirDisplay, PathResolution, SemanticsScope};
|
use hir::{HirDisplay, PathResolution, SemanticsScope};
|
||||||
|
use hir_expand::hygiene::Hygiene;
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
algo::SyntaxRewriter,
|
algo::SyntaxRewriter,
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
@ -51,7 +52,7 @@ impl<'a> SubstituteTypeParams<'a> {
|
|||||||
// this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky
|
// this is a trait impl, so we need to skip the first type parameter -- this is a bit hacky
|
||||||
.skip(1)
|
.skip(1)
|
||||||
// The actual list of trait type parameters may be longer than the one
|
// 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
|
// 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
|
// 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
|
// a default type. If they do, go for that type from `hir` to `ast` so
|
||||||
@ -110,9 +111,7 @@ impl<'a> SubstituteTypeParams<'a> {
|
|||||||
ast::Type::PathType(path_type) => path_type.path()?,
|
ast::Type::PathType(path_type) => path_type.path()?,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
// FIXME: use `hir::Path::from_src` instead.
|
let path = hir::Path::from_src(path, &Hygiene::new_unhygienic())?;
|
||||||
#[allow(deprecated)]
|
|
||||||
let path = hir::Path::from_ast(path)?;
|
|
||||||
let resolution = self.source_scope.resolve_hir_path(&path)?;
|
let resolution = self.source_scope.resolve_hir_path(&path)?;
|
||||||
match resolution {
|
match resolution {
|
||||||
hir::PathResolution::TypeParam(tp) => Some(self.substs.get(&tp)?.syntax().clone()),
|
hir::PathResolution::TypeParam(tp) => Some(self.substs.get(&tp)?.syntax().clone()),
|
||||||
@ -152,10 +151,8 @@ impl<'a> QualifyPaths<'a> {
|
|||||||
// don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway
|
// don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
// FIXME: use `hir::Path::from_src` instead.
|
let hir_path = hir::Path::from_src(p.clone(), &Hygiene::new_unhygienic())?;
|
||||||
#[allow(deprecated)]
|
let resolution = self.source_scope.resolve_hir_path(&hir_path)?;
|
||||||
let hir_path = hir::Path::from_ast(p.clone());
|
|
||||||
let resolution = self.source_scope.resolve_hir_path(&hir_path?)?;
|
|
||||||
match resolution {
|
match resolution {
|
||||||
PathResolution::Def(def) => {
|
PathResolution::Def(def) => {
|
||||||
let found_path = from.find_use_path(self.source_scope.db.upcast(), def)?;
|
let found_path = from.find_use_path(self.source_scope.db.upcast(), def)?;
|
||||||
|
@ -66,13 +66,13 @@ pub struct GroupLabel(pub String);
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Assist {
|
pub struct Assist {
|
||||||
pub id: AssistId,
|
id: AssistId,
|
||||||
/// Short description of the assist, as shown in the UI.
|
/// Short description of the assist, as shown in the UI.
|
||||||
pub label: String,
|
label: String,
|
||||||
pub group: Option<GroupLabel>,
|
group: Option<GroupLabel>,
|
||||||
/// Target ranges are used to sort assists: the smaller the target range,
|
/// Target ranges are used to sort assists: the smaller the target range,
|
||||||
/// the more specific assist is, and so it should be sorted first.
|
/// the more specific assist is, and so it should be sorted first.
|
||||||
pub target: TextRange,
|
target: TextRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -120,10 +120,25 @@ impl Assist {
|
|||||||
group: Option<GroupLabel>,
|
group: Option<GroupLabel>,
|
||||||
target: TextRange,
|
target: TextRange,
|
||||||
) -> Assist {
|
) -> Assist {
|
||||||
// FIXME: make fields private, so that this invariant can't be broken
|
|
||||||
assert!(label.starts_with(|c: char| c.is_uppercase()));
|
assert!(label.starts_with(|c: char| c.is_uppercase()));
|
||||||
Assist { id, label, group, target }
|
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 {
|
mod handlers {
|
||||||
|
@ -864,7 +864,7 @@ pub(crate) fn handle_resolve_code_action(
|
|||||||
let (id_string, index) = split_once(¶ms.id, ':').unwrap();
|
let (id_string, index) = split_once(¶ms.id, ':').unwrap();
|
||||||
let index = index.parse::<usize>().unwrap();
|
let index = index.parse::<usize>().unwrap();
|
||||||
let assist = &assists[index];
|
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)
|
Ok(to_proto::resolved_code_action(&snap, assist.clone())?.edit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -704,10 +704,10 @@ pub(crate) fn unresolved_code_action(
|
|||||||
index: usize,
|
index: usize,
|
||||||
) -> Result<lsp_ext::CodeAction> {
|
) -> Result<lsp_ext::CodeAction> {
|
||||||
let res = lsp_ext::CodeAction {
|
let res = lsp_ext::CodeAction {
|
||||||
title: assist.label,
|
title: assist.label(),
|
||||||
id: Some(format!("{}:{}", assist.id.0.to_owned(), index.to_string())),
|
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),
|
group: assist.group().filter(|_| snap.config.client_caps.code_action_group).map(|gr| gr.0),
|
||||||
kind: Some(code_action_kind(assist.id.1)),
|
kind: Some(code_action_kind(assist.id().1)),
|
||||||
edit: None,
|
edit: None,
|
||||||
is_preferred: None,
|
is_preferred: None,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user