mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
Merge #5707
5707: Address some FIXMEs for ra_assists r=jonas-schievink a=JmPotato Signed-off-by: JmPotato <ghzpotato@gmail.com> Co-authored-by: JmPotato <ghzpotato@gmail.com>
This commit is contained in:
commit
ef20dfc78d
7 changed files with 30 additions and 14 deletions
|
@ -51,7 +51,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
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_
|
||||||
|
|
||||||
// FIXME: instead of having a separate function here, maybe use
|
// FIXME: instead of having a separate function here, maybe use
|
||||||
// `extract_ranges` and mark the target as `<target> </target>` in the
|
// `extract_ranges` and mark the target as `<target> </target>` in the
|
||||||
// fixuture?
|
// fixture?
|
||||||
pub(crate) fn check_assist_target(assist: Handler, ra_fixture: &str, target: &str) {
|
pub(crate) fn check_assist_target(assist: Handler, ra_fixture: &str, target: &str) {
|
||||||
check(assist, ra_fixture, ExpectedResult::Target(target));
|
check(assist, ra_fixture, ExpectedResult::Target(target));
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub struct Hygiene {
|
||||||
// This is what `$crate` expands to
|
// This is what `$crate` expands to
|
||||||
def_crate: Option<CrateId>,
|
def_crate: Option<CrateId>,
|
||||||
|
|
||||||
// Indiciate this is a local inner macro
|
// Indicate this is a local inner macro
|
||||||
local_inner: bool,
|
local_inner: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,8 @@ mod test_db;
|
||||||
/// containing the call plus the offset of the macro call in the file. Note that
|
/// containing the call plus the offset of the macro call in the file. Note that
|
||||||
/// this is a recursive definition! However, the size_of of `HirFileId` is
|
/// this is a recursive definition! However, the size_of of `HirFileId` is
|
||||||
/// finite (because everything bottoms out at the real `FileId`) and small
|
/// finite (because everything bottoms out at the real `FileId`) and small
|
||||||
/// (`MacroCallId` uses the location interner).
|
/// (`MacroCallId` uses the location interning. You can check details here:
|
||||||
|
/// https://en.wikipedia.org/wiki/String_interning).
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct HirFileId(HirFileIdRepr);
|
pub struct HirFileId(HirFileIdRepr);
|
||||||
|
|
||||||
|
|
|
@ -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 a new issue