aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock4
-rw-r--r--crates/ra_assists/src/handlers/change_visibility.rs16
-rw-r--r--crates/ra_syntax/src/parsing/text_tree_sink.rs5
-rw-r--r--crates/rust-analyzer/Cargo.toml2
-rw-r--r--crates/rust-analyzer/src/caps.rs14
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs2
-rw-r--r--crates/rust-analyzer/src/handlers.rs12
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs6
-rw-r--r--crates/rust-analyzer/src/to_proto.rs15
-rw-r--r--crates/rust-analyzer/test_data/rustc_unused_variable.txt4
-rw-r--r--crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt4
-rw-r--r--crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt4
-rw-r--r--crates/rust-analyzer/test_data/snap_multi_line_fix.txt4
13 files changed, 57 insertions, 35 deletions
diff --git a/Cargo.lock b/Cargo.lock
index e564016d2..292ddb982 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -691,9 +691,9 @@ dependencies = [
691 691
692[[package]] 692[[package]]
693name = "lsp-types" 693name = "lsp-types"
694version = "0.74.2" 694version = "0.75.0"
695source = "registry+https://github.com/rust-lang/crates.io-index" 695source = "registry+https://github.com/rust-lang/crates.io-index"
696checksum = "b360754e89e0e13c114245131382ba921d4ff1efabb918e549422938aaa8d392" 696checksum = "a1b4ab1df4a5538413c707860e13fff9e0c9bc2fa613efc15d78196bc06ae06d"
697dependencies = [ 697dependencies = [
698 "base64", 698 "base64",
699 "bitflags", 699 "bitflags",
diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs
index 703ee2143..4343b423c 100644
--- a/crates/ra_assists/src/handlers/change_visibility.rs
+++ b/crates/ra_assists/src/handlers/change_visibility.rs
@@ -1,7 +1,9 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, NameOwner, VisibilityOwner}, 2 ast::{self, NameOwner, VisibilityOwner},
3 AstNode, 3 AstNode,
4 SyntaxKind::{CONST_DEF, ENUM_DEF, FN_DEF, MODULE, STRUCT_DEF, TRAIT_DEF, VISIBILITY}, 4 SyntaxKind::{
5 CONST_DEF, ENUM_DEF, FN_DEF, MODULE, STATIC_DEF, STRUCT_DEF, TRAIT_DEF, VISIBILITY,
6 },
5 T, 7 T,
6}; 8};
7use test_utils::mark; 9use test_utils::mark;
@@ -28,12 +30,15 @@ pub(crate) fn change_visibility(acc: &mut Assists, ctx: &AssistContext) -> Optio
28 30
29fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 31fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
30 let item_keyword = ctx.token_at_offset().find(|leaf| { 32 let item_keyword = ctx.token_at_offset().find(|leaf| {
31 matches!(leaf.kind(), T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait]) 33 matches!(
34 leaf.kind(),
35 T![const] | T![static] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait]
36 )
32 }); 37 });
33 38
34 let (offset, target) = if let Some(keyword) = item_keyword { 39 let (offset, target) = if let Some(keyword) = item_keyword {
35 let parent = keyword.parent(); 40 let parent = keyword.parent();
36 let def_kws = vec![CONST_DEF, FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF]; 41 let def_kws = vec![CONST_DEF, STATIC_DEF, FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF];
37 // Parent is not a definition, can't add visibility 42 // Parent is not a definition, can't add visibility
38 if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) { 43 if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) {
39 return None; 44 return None;
@@ -152,6 +157,11 @@ mod tests {
152 } 157 }
153 158
154 #[test] 159 #[test]
160 fn change_visibility_static() {
161 check_assist(change_visibility, "<|>static FOO = 3u8;", "pub(crate) static FOO = 3u8;");
162 }
163
164 #[test]
155 fn change_visibility_handles_comment_attrs() { 165 fn change_visibility_handles_comment_attrs() {
156 check_assist( 166 check_assist(
157 change_visibility, 167 change_visibility,
diff --git a/crates/ra_syntax/src/parsing/text_tree_sink.rs b/crates/ra_syntax/src/parsing/text_tree_sink.rs
index 22aed1db1..c6b30a02a 100644
--- a/crates/ra_syntax/src/parsing/text_tree_sink.rs
+++ b/crates/ra_syntax/src/parsing/text_tree_sink.rs
@@ -160,7 +160,10 @@ fn n_attached_trivias<'a>(
160 if let Some((peek_kind, peek_text)) = 160 if let Some((peek_kind, peek_text)) =
161 trivias.peek().map(|(_, pair)| pair) 161 trivias.peek().map(|(_, pair)| pair)
162 { 162 {
163 if *peek_kind == COMMENT && peek_text.starts_with("///") { 163 if *peek_kind == COMMENT
164 && peek_text.starts_with("///")
165 && !peek_text.starts_with("////")
166 {
164 continue; 167 continue;
165 } 168 }
166 } 169 }
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"
20itertools = "0.9.0" 20itertools = "0.9.0"
21jod-thread = "0.1.0" 21jod-thread = "0.1.0"
22log = "0.4.8" 22log = "0.4.8"
23lsp-types = { version = "0.74.0", features = ["proposed"] } 23lsp-types = { version = "0.75.0", features = ["proposed"] }
24parking_lot = "0.11.0" 24parking_lot = "0.11.0"
25pico-args = "0.3.1" 25pico-args = "0.3.1"
26rand = { version = "0.7.3", features = ["small_rng"] } 26rand = { 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 @@
2use std::env; 2use std::env;
3 3
4use lsp_types::{ 4use lsp_types::{
5 CallHierarchyServerCapability, ClientCapabilities, CodeActionOptions, 5 CallHierarchyServerCapability, ClientCapabilities, CodeActionKind, CodeActionOptions,
6 CodeActionProviderCapability, CodeLensOptions, CompletionOptions, 6 CodeActionProviderCapability, CodeLensOptions, CompletionOptions,
7 DocumentOnTypeFormattingOptions, FoldingRangeProviderCapability, 7 DocumentOnTypeFormattingOptions, FoldingRangeProviderCapability,
8 ImplementationProviderCapability, RenameOptions, RenameProviderCapability, SaveOptions, 8 ImplementationProviderCapability, RenameOptions, RenameProviderCapability, SaveOptions,
@@ -106,12 +106,12 @@ fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProvi
106 // Ideally we would base this off of the client capabilities 106 // Ideally we would base this off of the client capabilities
107 // but the client is supposed to fall back gracefully for unknown values. 107 // but the client is supposed to fall back gracefully for unknown values.
108 code_action_kinds: Some(vec![ 108 code_action_kinds: Some(vec![
109 lsp_types::code_action_kind::EMPTY.to_string(), 109 CodeActionKind::EMPTY,
110 lsp_types::code_action_kind::QUICKFIX.to_string(), 110 CodeActionKind::QUICKFIX,
111 lsp_types::code_action_kind::REFACTOR.to_string(), 111 CodeActionKind::REFACTOR,
112 lsp_types::code_action_kind::REFACTOR_EXTRACT.to_string(), 112 CodeActionKind::REFACTOR_EXTRACT,
113 lsp_types::code_action_kind::REFACTOR_INLINE.to_string(), 113 CodeActionKind::REFACTOR_INLINE,
114 lsp_types::code_action_kind::REFACTOR_REWRITE.to_string(), 114 CodeActionKind::REFACTOR_REWRITE,
115 ]), 115 ]),
116 work_done_progress_options: Default::default(), 116 work_done_progress_options: Default::default(),
117 }) 117 })
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(
112 title: rd.message.clone(), 112 title: rd.message.clone(),
113 id: None, 113 id: None,
114 group: None, 114 group: None,
115 kind: Some("quickfix".to_string()), 115 kind: Some(lsp_types::CodeActionKind::QUICKFIX),
116 edit: Some(lsp_ext::SnippetWorkspaceEdit { 116 edit: Some(lsp_ext::SnippetWorkspaceEdit {
117 // FIXME: there's no good reason to use edit_map here.... 117 // FIXME: there's no good reason to use edit_map here....
118 changes: Some(edit_map), 118 changes: Some(edit_map),
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 85758eed6..f2e24178a 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -11,11 +11,11 @@ use lsp_server::ErrorCode;
11use lsp_types::{ 11use lsp_types::{
12 CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem, 12 CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem,
13 CallHierarchyOutgoingCall, CallHierarchyOutgoingCallsParams, CallHierarchyPrepareParams, 13 CallHierarchyOutgoingCall, CallHierarchyOutgoingCallsParams, CallHierarchyPrepareParams,
14 CodeLens, Command, CompletionItem, Diagnostic, DocumentFormattingParams, DocumentHighlight, 14 CodeActionKind, CodeLens, Command, CompletionItem, Diagnostic, DocumentFormattingParams,
15 DocumentSymbol, FoldingRange, FoldingRangeParams, HoverContents, Location, Position, 15 DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeParams, HoverContents, Location,
16 PrepareRenameResponse, Range, RenameParams, SemanticTokensParams, SemanticTokensRangeParams, 16 Position, PrepareRenameResponse, Range, RenameParams, SemanticTokensParams,
17 SemanticTokensRangeResult, SemanticTokensResult, SymbolInformation, TextDocumentIdentifier, 17 SemanticTokensRangeParams, SemanticTokensRangeResult, SemanticTokensResult, SymbolInformation,
18 Url, WorkspaceEdit, 18 TextDocumentIdentifier, Url, WorkspaceEdit,
19}; 19};
20use ra_ide::{ 20use ra_ide::{
21 FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, NavigationTarget, Query, 21 FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, NavigationTarget, Query,
@@ -760,7 +760,7 @@ fn handle_fixes(
760 title, 760 title,
761 id: None, 761 id: None,
762 group: None, 762 group: None,
763 kind: Some(lsp_types::code_action_kind::QUICKFIX.into()), 763 kind: Some(CodeActionKind::QUICKFIX),
764 edit: Some(edit), 764 edit: Some(edit),
765 }; 765 };
766 res.push(action); 766 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 @@
3use std::{collections::HashMap, path::PathBuf}; 3use std::{collections::HashMap, path::PathBuf};
4 4
5use lsp_types::request::Request; 5use lsp_types::request::Request;
6use lsp_types::{notification::Notification, Position, Range, TextDocumentIdentifier}; 6use lsp_types::{
7 notification::Notification, CodeActionKind, Position, Range, TextDocumentIdentifier,
8};
7use serde::{Deserialize, Serialize}; 9use serde::{Deserialize, Serialize};
8 10
9pub enum AnalyzerStatus {} 11pub enum AnalyzerStatus {}
@@ -248,7 +250,7 @@ pub struct CodeAction {
248 #[serde(skip_serializing_if = "Option::is_none")] 250 #[serde(skip_serializing_if = "Option::is_none")]
249 pub group: Option<String>, 251 pub group: Option<String>,
250 #[serde(skip_serializing_if = "Option::is_none")] 252 #[serde(skip_serializing_if = "Option::is_none")]
251 pub kind: Option<String>, 253 pub kind: Option<CodeActionKind>,
252 // We don't handle commands on the client-side 254 // We don't handle commands on the client-side
253 // #[serde(skip_serializing_if = "Option::is_none")] 255 // #[serde(skip_serializing_if = "Option::is_none")]
254 // pub command: Option<lsp_types::Command>, 256 // pub command: Option<lsp_types::Command>,
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(
629 Ok(lsp_types::CallHierarchyItem { name, kind, tags: None, detail, uri, range, selection_range }) 629 Ok(lsp_types::CallHierarchyItem { name, kind, tags: None, detail, uri, range, selection_range })
630} 630}
631 631
632pub(crate) fn code_action_kind(kind: AssistKind) -> String { 632pub(crate) fn code_action_kind(kind: AssistKind) -> lsp_types::CodeActionKind {
633 match kind { 633 match kind {
634 AssistKind::None | AssistKind::Generate => lsp_types::code_action_kind::EMPTY, 634 AssistKind::None | AssistKind::Generate => lsp_types::CodeActionKind::EMPTY,
635 AssistKind::QuickFix => lsp_types::code_action_kind::QUICKFIX, 635 AssistKind::QuickFix => lsp_types::CodeActionKind::QUICKFIX,
636 AssistKind::Refactor => lsp_types::code_action_kind::REFACTOR, 636 AssistKind::Refactor => lsp_types::CodeActionKind::REFACTOR,
637 AssistKind::RefactorExtract => lsp_types::code_action_kind::REFACTOR_EXTRACT, 637 AssistKind::RefactorExtract => lsp_types::CodeActionKind::REFACTOR_EXTRACT,
638 AssistKind::RefactorInline => lsp_types::code_action_kind::REFACTOR_INLINE, 638 AssistKind::RefactorInline => lsp_types::CodeActionKind::REFACTOR_INLINE,
639 AssistKind::RefactorRewrite => lsp_types::code_action_kind::REFACTOR_REWRITE, 639 AssistKind::RefactorRewrite => lsp_types::CodeActionKind::REFACTOR_REWRITE,
640 } 640 }
641 .to_string()
642} 641}
643 642
644pub(crate) fn unresolved_code_action( 643pub(crate) fn unresolved_code_action(
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 @@
37 id: None, 37 id: None,
38 group: None, 38 group: None,
39 kind: Some( 39 kind: Some(
40 "quickfix", 40 CodeActionKind(
41 "quickfix",
42 ),
41 ), 43 ),
42 edit: Some( 44 edit: Some(
43 SnippetWorkspaceEdit { 45 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 @@
37 id: None, 37 id: None,
38 group: None, 38 group: None,
39 kind: Some( 39 kind: Some(
40 "quickfix", 40 CodeActionKind(
41 "quickfix",
42 ),
41 ), 43 ),
42 edit: Some( 44 edit: Some(
43 SnippetWorkspaceEdit { 45 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 @@
37 id: None, 37 id: None,
38 group: None, 38 group: None,
39 kind: Some( 39 kind: Some(
40 "quickfix", 40 CodeActionKind(
41 "quickfix",
42 ),
41 ), 43 ),
42 edit: Some( 44 edit: Some(
43 SnippetWorkspaceEdit { 45 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 @@
52 id: None, 52 id: None,
53 group: None, 53 group: None,
54 kind: Some( 54 kind: Some(
55 "quickfix", 55 CodeActionKind(
56 "quickfix",
57 ),
56 ), 58 ),
57 edit: Some( 59 edit: Some(
58 SnippetWorkspaceEdit { 60 SnippetWorkspaceEdit {