mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-03 13:23:25 +00:00
Merge pull request #19509 from snprajwal/remove-assistid-none
fix(ide-assists): remove `AssistKind::None`
This commit is contained in:
commit
0d64633d31
6 changed files with 9 additions and 19 deletions
|
|
@ -30,13 +30,13 @@ pub(crate) fn toggle_ignore(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
|
||||||
|
|
||||||
match has_ignore_attribute(&func) {
|
match has_ignore_attribute(&func) {
|
||||||
None => acc.add(
|
None => acc.add(
|
||||||
AssistId::none("toggle_ignore"),
|
AssistId::refactor("toggle_ignore"),
|
||||||
"Ignore this test",
|
"Ignore this test",
|
||||||
attr.syntax().text_range(),
|
attr.syntax().text_range(),
|
||||||
|builder| builder.insert(attr.syntax().text_range().end(), "\n#[ignore]"),
|
|builder| builder.insert(attr.syntax().text_range().end(), "\n#[ignore]"),
|
||||||
),
|
),
|
||||||
Some(ignore_attr) => acc.add(
|
Some(ignore_attr) => acc.add(
|
||||||
AssistId::none("toggle_ignore"),
|
AssistId::refactor("toggle_ignore"),
|
||||||
"Re-enable this test",
|
"Re-enable this test",
|
||||||
ignore_attr.syntax().text_range(),
|
ignore_attr.syntax().text_range(),
|
||||||
|builder| {
|
|builder| {
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,6 @@ pub enum Command {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum AssistKind {
|
pub enum AssistKind {
|
||||||
// FIXME: does the None variant make sense? Probably not.
|
|
||||||
None,
|
|
||||||
|
|
||||||
QuickFix,
|
QuickFix,
|
||||||
Generate,
|
Generate,
|
||||||
Refactor,
|
Refactor,
|
||||||
|
|
@ -61,7 +58,7 @@ impl AssistKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
AssistKind::None | AssistKind::Generate => true,
|
AssistKind::Generate => true,
|
||||||
AssistKind::Refactor => matches!(
|
AssistKind::Refactor => matches!(
|
||||||
other,
|
other,
|
||||||
AssistKind::RefactorExtract
|
AssistKind::RefactorExtract
|
||||||
|
|
@ -74,7 +71,6 @@ impl AssistKind {
|
||||||
|
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
AssistKind::None => "None",
|
|
||||||
AssistKind::QuickFix => "QuickFix",
|
AssistKind::QuickFix => "QuickFix",
|
||||||
AssistKind::Generate => "Generate",
|
AssistKind::Generate => "Generate",
|
||||||
AssistKind::Refactor => "Refactor",
|
AssistKind::Refactor => "Refactor",
|
||||||
|
|
@ -90,7 +86,6 @@ impl FromStr for AssistKind {
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
match s {
|
match s {
|
||||||
"None" => Ok(AssistKind::None),
|
|
||||||
"QuickFix" => Ok(AssistKind::QuickFix),
|
"QuickFix" => Ok(AssistKind::QuickFix),
|
||||||
"Generate" => Ok(AssistKind::Generate),
|
"Generate" => Ok(AssistKind::Generate),
|
||||||
"Refactor" => Ok(AssistKind::Refactor),
|
"Refactor" => Ok(AssistKind::Refactor),
|
||||||
|
|
@ -108,10 +103,6 @@ impl FromStr for AssistKind {
|
||||||
pub struct AssistId(pub &'static str, pub AssistKind, pub Option<usize>);
|
pub struct AssistId(pub &'static str, pub AssistKind, pub Option<usize>);
|
||||||
|
|
||||||
impl AssistId {
|
impl AssistId {
|
||||||
pub fn none(id: &'static str) -> AssistId {
|
|
||||||
AssistId(id, AssistKind::None, None)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn quick_fix(id: &'static str) -> AssistId {
|
pub fn quick_fix(id: &'static str) -> AssistId {
|
||||||
AssistId(id, AssistKind::QuickFix, None)
|
AssistId(id, AssistKind::QuickFix, None)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -753,7 +753,7 @@ impl Analysis {
|
||||||
frange: FileRange,
|
frange: FileRange,
|
||||||
) -> Cancellable<Vec<Assist>> {
|
) -> Cancellable<Vec<Assist>> {
|
||||||
let include_fixes = match &assist_config.allowed {
|
let include_fixes = match &assist_config.allowed {
|
||||||
Some(it) => it.iter().any(|&it| it == AssistKind::None || it == AssistKind::QuickFix),
|
Some(it) => it.iter().any(|&it| it == AssistKind::QuickFix),
|
||||||
None => true,
|
None => true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ pub fn read_dylib_info(obj: &object::File<'_>) -> io::Result<RustCInfo> {
|
||||||
let mut items = ver_str.split_whitespace();
|
let mut items = ver_str.split_whitespace();
|
||||||
let tag = items.next().ok_or_else(|| err!("version format error"))?;
|
let tag = items.next().ok_or_else(|| err!("version format error"))?;
|
||||||
if tag != "rustc" {
|
if tag != "rustc" {
|
||||||
return Err(err!("version format error (No rustc tag)"));
|
return Err(err!("no rustc tag"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let version_part = items.next().ok_or_else(|| err!("no version string"))?;
|
let version_part = items.next().ok_or_else(|| err!("no version string"))?;
|
||||||
|
|
@ -83,7 +83,7 @@ fn read_section<'a>(obj: &object::File<'a>, section_name: &str) -> io::Result<&'
|
||||||
/// A proc macro crate binary's ".rustc" section has following byte layout:
|
/// A proc macro crate binary's ".rustc" section has following byte layout:
|
||||||
/// * [b'r',b'u',b's',b't',0,0,0,5] is the first 8 bytes
|
/// * [b'r',b'u',b's',b't',0,0,0,5] is the first 8 bytes
|
||||||
/// * ff060000 734e6150 is followed, it's the snappy format magic bytes,
|
/// * ff060000 734e6150 is followed, it's the snappy format magic bytes,
|
||||||
/// means bytes from here(including this sequence) are compressed in
|
/// means bytes from here (including this sequence) are compressed in
|
||||||
/// snappy compression format. Version info is inside here, so decompress
|
/// snappy compression format. Version info is inside here, so decompress
|
||||||
/// this.
|
/// this.
|
||||||
///
|
///
|
||||||
|
|
@ -110,7 +110,7 @@ pub fn read_version(obj: &object::File<'_>) -> io::Result<String> {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let version = u32::from_be_bytes([dot_rustc[4], dot_rustc[5], dot_rustc[6], dot_rustc[7]]);
|
let version = u32::from_be_bytes([dot_rustc[4], dot_rustc[5], dot_rustc[6], dot_rustc[7]]);
|
||||||
// Last supported version is:
|
// Last version with breaking changes is:
|
||||||
// https://github.com/rust-lang/rust/commit/b94cfefc860715fb2adf72a6955423d384c69318
|
// https://github.com/rust-lang/rust/commit/b94cfefc860715fb2adf72a6955423d384c69318
|
||||||
let (mut metadata_portion, bytes_before_version) = match version {
|
let (mut metadata_portion, bytes_before_version) = match version {
|
||||||
8 => {
|
8 => {
|
||||||
|
|
@ -118,7 +118,7 @@ pub fn read_version(obj: &object::File<'_>) -> io::Result<String> {
|
||||||
let data_len = u32::from_be_bytes(len_bytes.try_into().unwrap()) as usize;
|
let data_len = u32::from_be_bytes(len_bytes.try_into().unwrap()) as usize;
|
||||||
(&dot_rustc[12..data_len + 12], 13)
|
(&dot_rustc[12..data_len + 12], 13)
|
||||||
}
|
}
|
||||||
9 => {
|
9 | 10 => {
|
||||||
let len_bytes = &dot_rustc[8..16];
|
let len_bytes = &dot_rustc[8..16];
|
||||||
let data_len = u64::from_le_bytes(len_bytes.try_into().unwrap()) as usize;
|
let data_len = u64::from_le_bytes(len_bytes.try_into().unwrap()) as usize;
|
||||||
(&dot_rustc[16..data_len + 12], 17)
|
(&dot_rustc[16..data_len + 12], 17)
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,6 @@ pub(crate) fn file_range_uri(
|
||||||
|
|
||||||
pub(crate) fn assist_kind(kind: lsp_types::CodeActionKind) -> Option<AssistKind> {
|
pub(crate) fn assist_kind(kind: lsp_types::CodeActionKind) -> Option<AssistKind> {
|
||||||
let assist_kind = match &kind {
|
let assist_kind = match &kind {
|
||||||
k if k == &lsp_types::CodeActionKind::EMPTY => AssistKind::None,
|
|
||||||
k if k == &lsp_types::CodeActionKind::QUICKFIX => AssistKind::QuickFix,
|
k if k == &lsp_types::CodeActionKind::QUICKFIX => AssistKind::QuickFix,
|
||||||
k if k == &lsp_types::CodeActionKind::REFACTOR => AssistKind::Refactor,
|
k if k == &lsp_types::CodeActionKind::REFACTOR => AssistKind::Refactor,
|
||||||
k if k == &lsp_types::CodeActionKind::REFACTOR_EXTRACT => AssistKind::RefactorExtract,
|
k if k == &lsp_types::CodeActionKind::REFACTOR_EXTRACT => AssistKind::RefactorExtract,
|
||||||
|
|
|
||||||
|
|
@ -1477,7 +1477,7 @@ pub(crate) fn call_hierarchy_item(
|
||||||
|
|
||||||
pub(crate) fn code_action_kind(kind: AssistKind) -> lsp_types::CodeActionKind {
|
pub(crate) fn code_action_kind(kind: AssistKind) -> lsp_types::CodeActionKind {
|
||||||
match kind {
|
match kind {
|
||||||
AssistKind::None | AssistKind::Generate => lsp_types::CodeActionKind::EMPTY,
|
AssistKind::Generate => lsp_types::CodeActionKind::EMPTY,
|
||||||
AssistKind::QuickFix => lsp_types::CodeActionKind::QUICKFIX,
|
AssistKind::QuickFix => lsp_types::CodeActionKind::QUICKFIX,
|
||||||
AssistKind::Refactor => lsp_types::CodeActionKind::REFACTOR,
|
AssistKind::Refactor => lsp_types::CodeActionKind::REFACTOR,
|
||||||
AssistKind::RefactorExtract => lsp_types::CodeActionKind::REFACTOR_EXTRACT,
|
AssistKind::RefactorExtract => lsp_types::CodeActionKind::REFACTOR_EXTRACT,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue