From 007812dcaee26298f7b8580d5b0c60469047f2c9 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sat, 11 Jul 2020 17:29:45 -0400 Subject: Update lsp-types to account for new CodeActionKind structure --- Cargo.lock | 4 ++-- crates/rust-analyzer/Cargo.toml | 2 +- crates/rust-analyzer/src/caps.rs | 14 +++++++------- crates/rust-analyzer/src/diagnostics/to_proto.rs | 2 +- crates/rust-analyzer/src/handlers.rs | 12 ++++++------ crates/rust-analyzer/src/lsp_ext.rs | 6 ++++-- crates/rust-analyzer/src/to_proto.rs | 15 +++++++-------- 7 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e564016d2..292ddb982 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -691,9 +691,9 @@ dependencies = [ [[package]] name = "lsp-types" -version = "0.74.2" +version = "0.75.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b360754e89e0e13c114245131382ba921d4ff1efabb918e549422938aaa8d392" +checksum = "a1b4ab1df4a5538413c707860e13fff9e0c9bc2fa613efc15d78196bc06ae06d" dependencies = [ "base64", "bitflags", diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index dc8dbbe77..676a04269 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -20,7 +20,7 @@ globset = "0.4.4" itertools = "0.9.0" jod-thread = "0.1.0" log = "0.4.8" -lsp-types = { version = "0.74.0", features = ["proposed"] } +lsp-types = { version = "0.75.0", features = ["proposed"] } parking_lot = "0.11.0" pico-args = "0.3.1" rand = { version = "0.7.3", features = ["small_rng"] } diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs index 070ad5e68..f999c730a 100644 --- a/crates/rust-analyzer/src/caps.rs +++ b/crates/rust-analyzer/src/caps.rs @@ -2,7 +2,7 @@ use std::env; use lsp_types::{ - CallHierarchyServerCapability, ClientCapabilities, CodeActionOptions, + CallHierarchyServerCapability, ClientCapabilities, CodeActionKind, CodeActionOptions, CodeActionProviderCapability, CodeLensOptions, CompletionOptions, DocumentOnTypeFormattingOptions, FoldingRangeProviderCapability, ImplementationProviderCapability, RenameOptions, RenameProviderCapability, SaveOptions, @@ -106,12 +106,12 @@ fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProvi // Ideally we would base this off of the client capabilities // but the client is supposed to fall back gracefully for unknown values. code_action_kinds: Some(vec![ - lsp_types::code_action_kind::EMPTY.to_string(), - lsp_types::code_action_kind::QUICKFIX.to_string(), - lsp_types::code_action_kind::REFACTOR.to_string(), - lsp_types::code_action_kind::REFACTOR_EXTRACT.to_string(), - lsp_types::code_action_kind::REFACTOR_INLINE.to_string(), - lsp_types::code_action_kind::REFACTOR_REWRITE.to_string(), + CodeActionKind::EMPTY, + CodeActionKind::QUICKFIX, + CodeActionKind::REFACTOR, + CodeActionKind::REFACTOR_EXTRACT, + CodeActionKind::REFACTOR_INLINE, + CodeActionKind::REFACTOR_REWRITE, ]), work_done_progress_options: Default::default(), }) diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index 1b1e670c1..7be3ef984 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs @@ -112,7 +112,7 @@ fn map_rust_child_diagnostic( title: rd.message.clone(), id: None, group: None, - kind: Some("quickfix".to_string()), + kind: Some(lsp_types::CodeActionKind::QUICKFIX), edit: Some(lsp_ext::SnippetWorkspaceEdit { // FIXME: there's no good reason to use edit_map here.... changes: Some(edit_map), diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index d39dceae0..8a06ff4b6 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -11,11 +11,11 @@ use lsp_server::ErrorCode; use lsp_types::{ CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem, CallHierarchyOutgoingCall, CallHierarchyOutgoingCallsParams, CallHierarchyPrepareParams, - CodeLens, Command, CompletionItem, Diagnostic, DocumentFormattingParams, DocumentHighlight, - DocumentSymbol, FoldingRange, FoldingRangeParams, HoverContents, Location, Position, - PrepareRenameResponse, Range, RenameParams, SemanticTokensParams, SemanticTokensRangeParams, - SemanticTokensRangeResult, SemanticTokensResult, SymbolInformation, TextDocumentIdentifier, - Url, WorkspaceEdit, + CodeActionKind, CodeLens, Command, CompletionItem, Diagnostic, DocumentFormattingParams, + DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeParams, HoverContents, Location, + Position, PrepareRenameResponse, Range, RenameParams, SemanticTokensParams, + SemanticTokensRangeParams, SemanticTokensRangeResult, SemanticTokensResult, SymbolInformation, + TextDocumentIdentifier, Url, WorkspaceEdit, }; use ra_ide::{ FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, NavigationTarget, Query, @@ -760,7 +760,7 @@ fn handle_fixes( title, id: None, group: None, - kind: Some(lsp_types::code_action_kind::QUICKFIX.into()), + kind: Some(CodeActionKind::QUICKFIX), edit: Some(edit), }; res.push(action); diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index a3e12c046..e216966a9 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -3,7 +3,9 @@ use std::{collections::HashMap, path::PathBuf}; use lsp_types::request::Request; -use lsp_types::{notification::Notification, Position, Range, TextDocumentIdentifier}; +use lsp_types::{ + notification::Notification, CodeActionKind, Position, Range, TextDocumentIdentifier, +}; use serde::{Deserialize, Serialize}; pub enum AnalyzerStatus {} @@ -248,7 +250,7 @@ pub struct CodeAction { #[serde(skip_serializing_if = "Option::is_none")] pub group: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub kind: Option, + pub kind: Option, // We don't handle commands on the client-side // #[serde(skip_serializing_if = "Option::is_none")] // pub command: Option, diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index f6d2f4fc4..3585202a4 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -629,16 +629,15 @@ pub(crate) fn call_hierarchy_item( Ok(lsp_types::CallHierarchyItem { name, kind, tags: None, detail, uri, range, selection_range }) } -pub(crate) fn code_action_kind(kind: AssistKind) -> String { +pub(crate) fn code_action_kind(kind: AssistKind) -> lsp_types::CodeActionKind { match kind { - AssistKind::None | AssistKind::Generate => lsp_types::code_action_kind::EMPTY, - AssistKind::QuickFix => lsp_types::code_action_kind::QUICKFIX, - AssistKind::Refactor => lsp_types::code_action_kind::REFACTOR, - AssistKind::RefactorExtract => lsp_types::code_action_kind::REFACTOR_EXTRACT, - AssistKind::RefactorInline => lsp_types::code_action_kind::REFACTOR_INLINE, - AssistKind::RefactorRewrite => lsp_types::code_action_kind::REFACTOR_REWRITE, + AssistKind::None | AssistKind::Generate => lsp_types::CodeActionKind::EMPTY, + AssistKind::QuickFix => lsp_types::CodeActionKind::QUICKFIX, + AssistKind::Refactor => lsp_types::CodeActionKind::REFACTOR, + AssistKind::RefactorExtract => lsp_types::CodeActionKind::REFACTOR_EXTRACT, + AssistKind::RefactorInline => lsp_types::CodeActionKind::REFACTOR_INLINE, + AssistKind::RefactorRewrite => lsp_types::CodeActionKind::REFACTOR_REWRITE, } - .to_string() } pub(crate) fn unresolved_code_action( -- cgit v1.2.3 From 8c81465d5b43cb17162d5cd00e9e45ae02b47cd7 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sat, 11 Jul 2020 18:23:08 -0400 Subject: Update tests --- crates/rust-analyzer/test_data/rustc_unused_variable.txt | 4 +++- crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt | 4 +++- crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt | 4 +++- crates/rust-analyzer/test_data/snap_multi_line_fix.txt | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/rust-analyzer/test_data/rustc_unused_variable.txt b/crates/rust-analyzer/test_data/rustc_unused_variable.txt index 92aea088b..084632757 100644 --- a/crates/rust-analyzer/test_data/rustc_unused_variable.txt +++ b/crates/rust-analyzer/test_data/rustc_unused_variable.txt @@ -37,7 +37,9 @@ id: None, group: None, kind: Some( - "quickfix", + CodeActionKind( + "quickfix", + ), ), edit: Some( SnippetWorkspaceEdit { diff --git a/crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt b/crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt index 80cf0d8a5..d637923c5 100644 --- a/crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt +++ b/crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt @@ -37,7 +37,9 @@ id: None, group: None, kind: Some( - "quickfix", + CodeActionKind( + "quickfix", + ), ), edit: Some( SnippetWorkspaceEdit { diff --git a/crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt b/crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt index afe3cb6d8..6b48f16ed 100644 --- a/crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt +++ b/crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt @@ -37,7 +37,9 @@ id: None, group: None, kind: Some( - "quickfix", + CodeActionKind( + "quickfix", + ), ), edit: Some( SnippetWorkspaceEdit { diff --git a/crates/rust-analyzer/test_data/snap_multi_line_fix.txt b/crates/rust-analyzer/test_data/snap_multi_line_fix.txt index 7814d3543..2c4cbea16 100644 --- a/crates/rust-analyzer/test_data/snap_multi_line_fix.txt +++ b/crates/rust-analyzer/test_data/snap_multi_line_fix.txt @@ -52,7 +52,9 @@ id: None, group: None, kind: Some( - "quickfix", + CodeActionKind( + "quickfix", + ), ), edit: Some( SnippetWorkspaceEdit { -- cgit v1.2.3