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:
bors[bot] 2020-08-11 10:22:57 +00:00 committed by GitHub
commit ef20dfc78d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 14 deletions

View file

@ -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
.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

View file

@ -66,13 +66,13 @@ pub struct GroupLabel(pub String);
#[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 @@ impl Assist {
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

@ -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
// `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) {
check(assist, ra_fixture, ExpectedResult::Target(target));
}

View file

@ -17,7 +17,7 @@ pub struct Hygiene {
// This is what `$crate` expands to
def_crate: Option<CrateId>,
// Indiciate this is a local inner macro
// Indicate this is a local inner macro
local_inner: bool,
}

View file

@ -44,7 +44,8 @@ mod test_db;
/// 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
/// 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)]
pub struct HirFileId(HirFileIdRepr);

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