aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir_def/src/body/lower.rs4
-rw-r--r--crates/ra_hir_def/src/expr.rs4
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs5
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs6
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs1
-rw-r--r--crates/ra_syntax/src/ast.rs4
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs27
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs2
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs37
-rw-r--r--crates/rust-analyzer/src/caps.rs29
-rw-r--r--crates/rust-analyzer/src/config.rs6
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs28
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/support.rs6
-rw-r--r--docs/dev/architecture.md4
-rw-r--r--docs/dev/guide.md8
-rw-r--r--docs/dev/syntax.md2
-rw-r--r--docs/user/readme.adoc6
-rw-r--r--xtask/src/ast_src.rs5
18 files changed, 92 insertions, 92 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 571603854..f467ed3fe 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -182,10 +182,6 @@ impl ExprCollector<'_> {
182 182
183 self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr) 183 self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr)
184 } 184 }
185 ast::Expr::TryBlockExpr(e) => {
186 let body = self.collect_block_opt(e.body());
187 self.alloc_expr(Expr::TryBlock { body }, syntax_ptr)
188 }
189 ast::Expr::BlockExpr(e) => self.collect_block(e), 185 ast::Expr::BlockExpr(e) => self.collect_block(e),
190 ast::Expr::LoopExpr(e) => { 186 ast::Expr::LoopExpr(e) => {
191 let body = self.collect_block_opt(e.loop_body()); 187 let body = self.collect_block_opt(e.loop_body());
diff --git a/crates/ra_hir_def/src/expr.rs b/crates/ra_hir_def/src/expr.rs
index a0cdad529..aad12e123 100644
--- a/crates/ra_hir_def/src/expr.rs
+++ b/crates/ra_hir_def/src/expr.rs
@@ -101,9 +101,6 @@ pub enum Expr {
101 Try { 101 Try {
102 expr: ExprId, 102 expr: ExprId,
103 }, 103 },
104 TryBlock {
105 body: ExprId,
106 },
107 Cast { 104 Cast {
108 expr: ExprId, 105 expr: ExprId,
109 type_ref: TypeRef, 106 type_ref: TypeRef,
@@ -239,7 +236,6 @@ impl Expr {
239 f(*expr); 236 f(*expr);
240 } 237 }
241 } 238 }
242 Expr::TryBlock { body } => f(*body),
243 Expr::Loop { body } => f(*body), 239 Expr::Loop { body } => f(*body),
244 Expr::While { condition, body } => { 240 Expr::While { condition, body } => {
245 f(*condition); 241 f(*condition);
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index 83f946eee..efc60986b 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -73,11 +73,6 @@ impl<'a> InferenceContext<'a> {
73 self.coerce_merge_branch(&then_ty, &else_ty) 73 self.coerce_merge_branch(&then_ty, &else_ty)
74 } 74 }
75 Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), 75 Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected),
76 Expr::TryBlock { body } => {
77 let _inner = self.infer_expr(*body, expected);
78 // FIXME should be std::result::Result<{inner}, _>
79 Ty::Unknown
80 }
81 Expr::Loop { body } => { 76 Expr::Loop { body } => {
82 self.infer_expr(*body, &Expectation::has_type(Ty::unit())); 77 self.infer_expr(*body, &Expectation::has_type(Ty::unit()));
83 // FIXME handle break with value 78 // FIXME handle break with value
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index 166dfc472..76aa601cb 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -84,7 +84,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
84 T![box] => box_expr(p, None), 84 T![box] => box_expr(p, None),
85 T![for] => for_expr(p, None), 85 T![for] => for_expr(p, None),
86 T![while] => while_expr(p, None), 86 T![while] => while_expr(p, None),
87 T![try] => try_block_expr(p, None), 87 T![try] => try_expr(p, None),
88 LIFETIME if la == T![:] => { 88 LIFETIME if la == T![:] => {
89 let m = p.start(); 89 let m = p.start();
90 label(p); 90 label(p);
@@ -134,7 +134,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
134 } 134 }
135 }; 135 };
136 let blocklike = match done.kind() { 136 let blocklike = match done.kind() {
137 IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_BLOCK_EXPR => { 137 IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_EXPR => {
138 BlockLike::Block 138 BlockLike::Block
139 } 139 }
140 _ => BlockLike::NotBlock, 140 _ => BlockLike::NotBlock,
@@ -532,7 +532,7 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
532// fn foo() { 532// fn foo() {
533// let _ = try {}; 533// let _ = try {};
534// } 534// }
535fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { 535fn try_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
536 assert!(p.at(T![try])); 536 assert!(p.at(T![try]));
537 let m = m.unwrap_or_else(|| p.start()); 537 let m = m.unwrap_or_else(|| p.start());
538 // Special-case `try!` as macro. 538 // Special-case `try!` as macro.
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs
index 524e7d784..ab727ed7e 100644
--- a/crates/ra_parser/src/syntax_kind/generated.rs
+++ b/crates/ra_parser/src/syntax_kind/generated.rs
@@ -191,7 +191,6 @@ pub enum SyntaxKind {
191 RECORD_LIT, 191 RECORD_LIT,
192 RECORD_FIELD_LIST, 192 RECORD_FIELD_LIST,
193 RECORD_FIELD, 193 RECORD_FIELD,
194 TRY_BLOCK_EXPR,
195 BOX_EXPR, 194 BOX_EXPR,
196 CALL_EXPR, 195 CALL_EXPR,
197 INDEX_EXPR, 196 INDEX_EXPR,
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index a716e525b..521ca8ab8 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -16,7 +16,9 @@ use crate::{
16}; 16};
17 17
18pub use self::{ 18pub use self::{
19 expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp}, 19 expr_extensions::{
20 ArrayExprKind, BinOp, BlockModifier, ElseBranch, LiteralKind, PrefixOp, RangeOp,
21 },
20 extensions::{ 22 extensions::{
21 AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents, 23 AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents,
22 StructKind, TypeBoundKind, VisibilityKind, 24 StructKind, TypeBoundKind, VisibilityKind,
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index ecf74fd36..352c0d2c5 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -16,7 +16,7 @@ impl ast::Expr {
16 | ast::Expr::WhileExpr(_) 16 | ast::Expr::WhileExpr(_)
17 | ast::Expr::BlockExpr(_) 17 | ast::Expr::BlockExpr(_)
18 | ast::Expr::MatchExpr(_) 18 | ast::Expr::MatchExpr(_)
19 | ast::Expr::TryBlockExpr(_) => true, 19 | ast::Expr::TryExpr(_) => true,
20 _ => false, 20 _ => false,
21 } 21 }
22 } 22 }
@@ -359,7 +359,22 @@ impl ast::Literal {
359 } 359 }
360} 360}
361 361
362pub enum BlockModifier {
363 Async(SyntaxToken),
364 Unsafe(SyntaxToken),
365}
366
362impl ast::BlockExpr { 367impl ast::BlockExpr {
368 pub fn modifier(&self) -> Option<BlockModifier> {
369 if let Some(token) = self.async_token() {
370 return Some(BlockModifier::Async(token));
371 }
372 if let Some(token) = self.unsafe_token() {
373 return Some(BlockModifier::Unsafe(token));
374 }
375 None
376 }
377
363 /// false if the block is an intrinsic part of the syntax and can't be 378 /// false if the block is an intrinsic part of the syntax and can't be
364 /// replaced with arbitrary expression. 379 /// replaced with arbitrary expression.
365 /// 380 ///
@@ -368,15 +383,15 @@ impl ast::BlockExpr {
368 /// const FOO: () = { stand_alone }; 383 /// const FOO: () = { stand_alone };
369 /// ``` 384 /// ```
370 pub fn is_standalone(&self) -> bool { 385 pub fn is_standalone(&self) -> bool {
371 if self.unsafe_token().is_some() || self.async_token().is_some() { 386 if self.modifier().is_some() {
372 return false; 387 return false;
373 } 388 }
374 let kind = match self.syntax().parent() { 389 let parent = match self.syntax().parent() {
390 Some(it) => it,
375 None => return true, 391 None => return true,
376 Some(it) => it.kind(),
377 }; 392 };
378 match kind { 393 match parent.kind() {
379 FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | TRY_BLOCK_EXPR => false, 394 FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR => false,
380 _ => true, 395 _ => true,
381 } 396 }
382 } 397 }
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs
index f2ea5088e..45e3dd2d3 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -407,7 +407,7 @@ impl ast::Visibility {
407 } else if self.super_token().is_some() { 407 } else if self.super_token().is_some() {
408 VisibilityKind::PubSuper 408 VisibilityKind::PubSuper
409 } else if self.self_token().is_some() { 409 } else if self.self_token().is_some() {
410 VisibilityKind::PubSuper 410 VisibilityKind::PubSelf
411 } else { 411 } else {
412 VisibilityKind::Pub 412 VisibilityKind::Pub
413 } 413 }
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 2096f12f1..3f16592b6 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -476,16 +476,6 @@ impl LoopExpr {
476} 476}
477 477
478#[derive(Debug, Clone, PartialEq, Eq, Hash)] 478#[derive(Debug, Clone, PartialEq, Eq, Hash)]
479pub struct TryBlockExpr {
480 pub(crate) syntax: SyntaxNode,
481}
482impl ast::AttrsOwner for TryBlockExpr {}
483impl TryBlockExpr {
484 pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) }
485 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
486}
487
488#[derive(Debug, Clone, PartialEq, Eq, Hash)]
489pub struct ForExpr { 479pub struct ForExpr {
490 pub(crate) syntax: SyntaxNode, 480 pub(crate) syntax: SyntaxNode,
491} 481}
@@ -1477,7 +1467,6 @@ pub enum Expr {
1477 FieldExpr(FieldExpr), 1467 FieldExpr(FieldExpr),
1478 AwaitExpr(AwaitExpr), 1468 AwaitExpr(AwaitExpr),
1479 TryExpr(TryExpr), 1469 TryExpr(TryExpr),
1480 TryBlockExpr(TryBlockExpr),
1481 CastExpr(CastExpr), 1470 CastExpr(CastExpr),
1482 RefExpr(RefExpr), 1471 RefExpr(RefExpr),
1483 PrefixExpr(PrefixExpr), 1472 PrefixExpr(PrefixExpr),
@@ -1960,17 +1949,6 @@ impl AstNode for LoopExpr {
1960 } 1949 }
1961 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1950 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1962} 1951}
1963impl AstNode for TryBlockExpr {
1964 fn can_cast(kind: SyntaxKind) -> bool { kind == TRY_BLOCK_EXPR }
1965 fn cast(syntax: SyntaxNode) -> Option<Self> {
1966 if Self::can_cast(syntax.kind()) {
1967 Some(Self { syntax })
1968 } else {
1969 None
1970 }
1971 }
1972 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1973}
1974impl AstNode for ForExpr { 1952impl AstNode for ForExpr {
1975 fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR } 1953 fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR }
1976 fn cast(syntax: SyntaxNode) -> Option<Self> { 1954 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3312,9 +3290,6 @@ impl From<AwaitExpr> for Expr {
3312impl From<TryExpr> for Expr { 3290impl From<TryExpr> for Expr {
3313 fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) } 3291 fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) }
3314} 3292}
3315impl From<TryBlockExpr> for Expr {
3316 fn from(node: TryBlockExpr) -> Expr { Expr::TryBlockExpr(node) }
3317}
3318impl From<CastExpr> for Expr { 3293impl From<CastExpr> for Expr {
3319 fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } 3294 fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) }
3320} 3295}
@@ -3345,9 +3320,8 @@ impl AstNode for Expr {
3345 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR 3320 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
3346 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL 3321 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
3347 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR 3322 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR
3348 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR 3323 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | CAST_EXPR | REF_EXPR
3349 | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL 3324 | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL | BOX_EXPR => true,
3350 | BOX_EXPR => true,
3351 _ => false, 3325 _ => false,
3352 } 3326 }
3353 } 3327 }
@@ -3375,7 +3349,6 @@ impl AstNode for Expr {
3375 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }), 3349 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
3376 AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }), 3350 AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }),
3377 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }), 3351 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }),
3378 TRY_BLOCK_EXPR => Expr::TryBlockExpr(TryBlockExpr { syntax }),
3379 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }), 3352 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
3380 REF_EXPR => Expr::RefExpr(RefExpr { syntax }), 3353 REF_EXPR => Expr::RefExpr(RefExpr { syntax }),
3381 PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }), 3354 PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }),
@@ -3412,7 +3385,6 @@ impl AstNode for Expr {
3412 Expr::FieldExpr(it) => &it.syntax, 3385 Expr::FieldExpr(it) => &it.syntax,
3413 Expr::AwaitExpr(it) => &it.syntax, 3386 Expr::AwaitExpr(it) => &it.syntax,
3414 Expr::TryExpr(it) => &it.syntax, 3387 Expr::TryExpr(it) => &it.syntax,
3415 Expr::TryBlockExpr(it) => &it.syntax,
3416 Expr::CastExpr(it) => &it.syntax, 3388 Expr::CastExpr(it) => &it.syntax,
3417 Expr::RefExpr(it) => &it.syntax, 3389 Expr::RefExpr(it) => &it.syntax,
3418 Expr::PrefixExpr(it) => &it.syntax, 3390 Expr::PrefixExpr(it) => &it.syntax,
@@ -3893,11 +3865,6 @@ impl std::fmt::Display for LoopExpr {
3893 std::fmt::Display::fmt(self.syntax(), f) 3865 std::fmt::Display::fmt(self.syntax(), f)
3894 } 3866 }
3895} 3867}
3896impl std::fmt::Display for TryBlockExpr {
3897 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3898 std::fmt::Display::fmt(self.syntax(), f)
3899 }
3900}
3901impl std::fmt::Display for ForExpr { 3868impl std::fmt::Display for ForExpr {
3902 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 3869 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3903 std::fmt::Display::fmt(self.syntax(), f) 3870 std::fmt::Display::fmt(self.syntax(), f)
diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs
index e22ab8402..c0d320926 100644
--- a/crates/rust-analyzer/src/caps.rs
+++ b/crates/rust-analyzer/src/caps.rs
@@ -3,13 +3,13 @@
3use crate::semantic_tokens; 3use crate::semantic_tokens;
4 4
5use lsp_types::{ 5use lsp_types::{
6 CallHierarchyServerCapability, CodeActionProviderCapability, CodeLensOptions, 6 CallHierarchyServerCapability, CodeActionOptions, CodeActionProviderCapability,
7 CompletionOptions, DocumentOnTypeFormattingOptions, FoldingRangeProviderCapability, 7 CodeLensOptions, CompletionOptions, DocumentOnTypeFormattingOptions,
8 ImplementationProviderCapability, RenameOptions, RenameProviderCapability, SaveOptions, 8 FoldingRangeProviderCapability, ImplementationProviderCapability, RenameOptions,
9 SelectionRangeProviderCapability, SemanticTokensDocumentProvider, SemanticTokensLegend, 9 RenameProviderCapability, SaveOptions, SelectionRangeProviderCapability,
10 SemanticTokensOptions, ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability, 10 SemanticTokensDocumentProvider, SemanticTokensLegend, SemanticTokensOptions,
11 TextDocumentSyncKind, TextDocumentSyncOptions, TypeDefinitionProviderCapability, 11 ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind,
12 WorkDoneProgressOptions, 12 TextDocumentSyncOptions, TypeDefinitionProviderCapability, WorkDoneProgressOptions,
13}; 13};
14 14
15pub fn server_capabilities() -> ServerCapabilities { 15pub fn server_capabilities() -> ServerCapabilities {
@@ -40,7 +40,20 @@ pub fn server_capabilities() -> ServerCapabilities {
40 document_highlight_provider: Some(true), 40 document_highlight_provider: Some(true),
41 document_symbol_provider: Some(true), 41 document_symbol_provider: Some(true),
42 workspace_symbol_provider: Some(true), 42 workspace_symbol_provider: Some(true),
43 code_action_provider: Some(CodeActionProviderCapability::Simple(true)), 43 code_action_provider: Some(CodeActionProviderCapability::Options(CodeActionOptions {
44 // Advertise support for all built-in CodeActionKinds
45 code_action_kinds: Some(vec![
46 String::new(),
47 lsp_types::code_action_kind::QUICKFIX.to_string(),
48 lsp_types::code_action_kind::REFACTOR.to_string(),
49 lsp_types::code_action_kind::REFACTOR_EXTRACT.to_string(),
50 lsp_types::code_action_kind::REFACTOR_INLINE.to_string(),
51 lsp_types::code_action_kind::REFACTOR_REWRITE.to_string(),
52 lsp_types::code_action_kind::SOURCE.to_string(),
53 lsp_types::code_action_kind::SOURCE_ORGANIZE_IMPORTS.to_string(),
54 ]),
55 work_done_progress_options: Default::default(),
56 })),
44 code_lens_provider: Some(CodeLensOptions { resolve_provider: Some(true) }), 57 code_lens_provider: Some(CodeLensOptions { resolve_provider: Some(true) }),
45 document_formatting_provider: Some(true), 58 document_formatting_provider: Some(true),
46 document_range_formatting_provider: None, 59 document_range_formatting_provider: None,
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 74a63e32a..177da94cc 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -70,6 +70,7 @@ pub struct ClientCapsConfig {
70 pub location_link: bool, 70 pub location_link: bool,
71 pub line_folding_only: bool, 71 pub line_folding_only: bool,
72 pub hierarchical_symbols: bool, 72 pub hierarchical_symbols: bool,
73 pub code_action_literals: bool,
73} 74}
74 75
75impl Default for Config { 76impl Default for Config {
@@ -221,6 +222,11 @@ impl Config {
221 { 222 {
222 self.client_caps.hierarchical_symbols = value 223 self.client_caps.hierarchical_symbols = value
223 } 224 }
225 if let Some(value) =
226 caps.code_action.as_ref().and_then(|it| Some(it.code_action_literal_support.is_some()))
227 {
228 self.client_caps.code_action_literals = value;
229 }
224 self.completion.allow_snippets(false); 230 self.completion.allow_snippets(false);
225 if let Some(completion) = &caps.completion { 231 if let Some(completion) = &caps.completion {
226 if let Some(completion_item) = &completion.completion_item { 232 if let Some(completion_item) = &completion.completion_item {
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index 8db2dfa0c..0f623949e 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -19,8 +19,7 @@ use lsp_types::{
19 TextEdit, Url, WorkspaceEdit, 19 TextEdit, Url, WorkspaceEdit,
20}; 20};
21use ra_ide::{ 21use ra_ide::{
22 Assist, AssistId, FileId, FilePosition, FileRange, Query, RangeInfo, Runnable, RunnableKind, 22 Assist, FileId, FilePosition, FileRange, Query, RangeInfo, Runnable, RunnableKind, SearchScope,
23 SearchScope,
24}; 23};
25use ra_prof::profile; 24use ra_prof::profile;
26use ra_syntax::{AstNode, SyntaxKind, TextRange, TextSize}; 25use ra_syntax::{AstNode, SyntaxKind, TextRange, TextSize};
@@ -702,15 +701,9 @@ fn create_single_code_action(assist: Assist, world: &WorldSnapshot) -> Result<Co
702 arguments: Some(vec![arg]), 701 arguments: Some(vec![arg]),
703 }; 702 };
704 703
705 let kind = match assist.id {
706 AssistId("introduce_variable") => Some("refactor.extract.variable".to_string()),
707 AssistId("add_custom_impl") => Some("refactor.rewrite.add_custom_impl".to_string()),
708 _ => None,
709 };
710
711 Ok(CodeAction { 704 Ok(CodeAction {
712 title, 705 title,
713 kind, 706 kind: Some(String::new()),
714 diagnostics: None, 707 diagnostics: None,
715 edit: None, 708 edit: None,
716 command: Some(command), 709 command: Some(command),
@@ -812,6 +805,23 @@ pub fn handle_code_action(
812 } 805 }
813 } 806 }
814 807
808 // If the client only supports commands then filter the list
809 // and remove and actions that depend on edits.
810 if !world.config.client_caps.code_action_literals {
811 // FIXME: use drain_filter once it hits stable.
812 res = res
813 .into_iter()
814 .filter_map(|it| match it {
815 cmd @ lsp_types::CodeActionOrCommand::Command(_) => Some(cmd),
816 lsp_types::CodeActionOrCommand::CodeAction(action) => match action.command {
817 Some(cmd) if action.edit.is_none() => {
818 Some(lsp_types::CodeActionOrCommand::Command(cmd))
819 }
820 _ => None,
821 },
822 })
823 .collect();
824 }
815 Ok(Some(res)) 825 Ok(Some(res))
816} 826}
817 827
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs
index e4fe3411a..8d47ee4f6 100644
--- a/crates/rust-analyzer/tests/heavy_tests/support.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/support.rs
@@ -77,7 +77,11 @@ impl<'a> Project<'a> {
77 let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect(); 77 let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect();
78 78
79 let mut config = Config { 79 let mut config = Config {
80 client_caps: ClientCapsConfig { location_link: true, ..Default::default() }, 80 client_caps: ClientCapsConfig {
81 location_link: true,
82 code_action_literals: true,
83 ..Default::default()
84 },
81 with_sysroot: self.with_sysroot, 85 with_sysroot: self.with_sysroot,
82 ..Config::default() 86 ..Config::default()
83 }; 87 };
diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md
index 3a337c574..cee916c09 100644
--- a/docs/dev/architecture.md
+++ b/docs/dev/architecture.md
@@ -46,7 +46,7 @@ can be quickly updated for small modifications.
46 46
47Some of the components of this repository are generated through automatic 47Some of the components of this repository are generated through automatic
48processes. `cargo xtask codegen` runs all generation tasks. Generated code is 48processes. `cargo xtask codegen` runs all generation tasks. Generated code is
49commited to the git repository. 49committed to the git repository.
50 50
51In particular, `cargo xtask codegen` generates: 51In particular, `cargo xtask codegen` generates:
52 52
@@ -114,7 +114,7 @@ is responsible for guessing a HIR for a particular source position.
114Underneath, HIR works on top of salsa, using a `HirDatabase` trait. 114Underneath, HIR works on top of salsa, using a `HirDatabase` trait.
115 115
116`ra_hir_xxx` crates have a strong ECS flavor, in that they work with raw ids and 116`ra_hir_xxx` crates have a strong ECS flavor, in that they work with raw ids and
117directly query the databse. 117directly query the database.
118 118
119The top-level `ra_hir` façade crate wraps ids into a more OO-flavored API. 119The top-level `ra_hir` façade crate wraps ids into a more OO-flavored API.
120 120
diff --git a/docs/dev/guide.md b/docs/dev/guide.md
index abbe4c154..c3252f1f6 100644
--- a/docs/dev/guide.md
+++ b/docs/dev/guide.md
@@ -26,7 +26,7 @@ properties hold:
26 26
27## IDE API 27## IDE API
28 28
29To see the bigger picture of how the IDE features works, let's take a look at the [`AnalysisHost`] and 29To see the bigger picture of how the IDE features work, let's take a look at the [`AnalysisHost`] and
30[`Analysis`] pair of types. `AnalysisHost` has three methods: 30[`Analysis`] pair of types. `AnalysisHost` has three methods:
31 31
32* `default()` for creating an empty analysis instance 32* `default()` for creating an empty analysis instance
@@ -131,7 +131,7 @@ mapping between `SourceRoot` IDs (which are assigned by the client) and actual
131analyzer. 131analyzer.
132 132
133Note that `mod`, `#[path]` and `include!()` can only reference files from the 133Note that `mod`, `#[path]` and `include!()` can only reference files from the
134same source root. It is of course is possible to explicitly add extra files to 134same source root. It is of course possible to explicitly add extra files to
135the source root, even `/dev/random`. 135the source root, even `/dev/random`.
136 136
137## Language Server Protocol 137## Language Server Protocol
@@ -192,7 +192,7 @@ task will be canceled as soon as the main loop calls `apply_change` on the
192[`schedule`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/main_loop.rs#L426-L455 192[`schedule`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/main_loop.rs#L426-L455
193[The task]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/main_loop/handlers.rs#L205-L223 193[The task]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/main_loop/handlers.rs#L205-L223
194 194
195This concludes the overview of the analyzer's programing *interface*. Next, lets 195This concludes the overview of the analyzer's programing *interface*. Next, let's
196dig into the implementation! 196dig into the implementation!
197 197
198## Salsa 198## Salsa
@@ -480,7 +480,7 @@ throughout the analyzer:
480## Source Map pattern 480## Source Map pattern
481 481
482Due to an obscure edge case in completion, IDE needs to know the syntax node of 482Due to an obscure edge case in completion, IDE needs to know the syntax node of
483an use statement which imported the given completion candidate. We can't just 483a use statement which imported the given completion candidate. We can't just
484store the syntax node as a part of name resolution: this will break 484store the syntax node as a part of name resolution: this will break
485incrementality, due to the fact that syntax changes after every file 485incrementality, due to the fact that syntax changes after every file
486modification. 486modification.
diff --git a/docs/dev/syntax.md b/docs/dev/syntax.md
index 4dd1de659..33973ffec 100644
--- a/docs/dev/syntax.md
+++ b/docs/dev/syntax.md
@@ -35,7 +35,7 @@ The syntax tree consists of three layers:
35* AST 35* AST
36 36
37Of these, only GreenNodes store the actual data, the other two layers are (non-trivial) views into green tree. 37Of these, only GreenNodes store the actual data, the other two layers are (non-trivial) views into green tree.
38Red-green terminology comes from Roslyn ([link](https://docs.microsoft.com/en-ie/archive/blogs/ericlippert/persistence-facades-and-roslyns-red-green-trees)) and gives the name to the `rowan` library. Green and syntax nodes are defined in rowan, ast is defined in rust-analyzer. 38Red-green terminology comes from Roslyn ([link](https://ericlippert.com/2012/06/08/red-green-trees/)) and gives the name to the `rowan` library. Green and syntax nodes are defined in rowan, ast is defined in rust-analyzer.
39 39
40Syntax trees are a semi-transient data structure. 40Syntax trees are a semi-transient data structure.
41In general, frontend does not keep syntax trees for all files in memory. 41In general, frontend does not keep syntax trees for all files in memory.
diff --git a/docs/user/readme.adoc b/docs/user/readme.adoc
index 54342026b..4cb1e23e8 100644
--- a/docs/user/readme.adoc
+++ b/docs/user/readme.adoc
@@ -111,7 +111,7 @@ Here are some useful self-diagnostic commands:
111=== rust-analyzer Language Server Binary 111=== rust-analyzer Language Server Binary
112 112
113Other editors generally require the `rust-analyzer` binary to be in `$PATH`. 113Other editors generally require the `rust-analyzer` binary to be in `$PATH`.
114You can download the pre-built binary from the https://github.com/rust-analyzer/rust-analyzer/releases[releases] page. Typically, you then need to rename the binary for your platform, e.g. `rust-analyzer-mac` if you're on Mac OS, to `rust-analzyer` and make it executable in addition to moving it into a directory in your `$PATH`. 114You can download the pre-built binary from the https://github.com/rust-analyzer/rust-analyzer/releases[releases] page. Typically, you then need to rename the binary for your platform, e.g. `rust-analyzer-mac` if you're on Mac OS, to `rust-analyzer` and make it executable in addition to moving it into a directory in your `$PATH`.
115 115
116On Linux to install the `rust-analyzer` binary into `~/.local/bin`, this commands could be used 116On Linux to install the `rust-analyzer` binary into `~/.local/bin`, this commands could be used
117 117
@@ -246,9 +246,9 @@ You also need the `LSP` package. To install it:
246 * Type `Install Package Control`, press enter 246 * Type `Install Package Control`, press enter
2472. In the command palette, run `Package control: Install package`, and in the list that pops up, type `LSP` and press enter. 2472. In the command palette, run `Package control: Install package`, and in the list that pops up, type `LSP` and press enter.
248 248
249Finally, with your Rust project open, in the command palette, run `LSP: Enable Language Server In Project` or `LSP: Enable Language Server Globally`, then select `rust-analyzer` in the list that pops up to enable the rust-analyzer LSP. The latter means that rust-analzyer is enabled by default in Rust projects. 249Finally, with your Rust project open, in the command palette, run `LSP: Enable Language Server In Project` or `LSP: Enable Language Server Globally`, then select `rust-analyzer` in the list that pops up to enable the rust-analyzer LSP. The latter means that rust-analyzer is enabled by default in Rust projects.
250 250
251If it worked, you should see "rust-analzyer, Line X, Column Y" on the left side of the bottom bar, and after waiting a bit, functionality like tooltips on hovering over variables should become available. 251If it worked, you should see "rust-analyzer, Line X, Column Y" on the left side of the bottom bar, and after waiting a bit, functionality like tooltips on hovering over variables should become available.
252 252
253If you get an error saying `No such file or directory: 'rust-analyzer'`, see the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>> section on installing the language server binary. 253If you get an error saying `No such file or directory: 'rust-analyzer'`, see the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>> section on installing the language server binary.
254 254
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs
index 1abb62f6f..703fb9be9 100644
--- a/xtask/src/ast_src.rs
+++ b/xtask/src/ast_src.rs
@@ -162,7 +162,6 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
162 "RECORD_LIT", 162 "RECORD_LIT",
163 "RECORD_FIELD_LIST", 163 "RECORD_FIELD_LIST",
164 "RECORD_FIELD", 164 "RECORD_FIELD",
165 "TRY_BLOCK_EXPR",
166 "BOX_EXPR", 165 "BOX_EXPR",
167 // postfix 166 // postfix
168 "CALL_EXPR", 167 "CALL_EXPR",
@@ -440,7 +439,6 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
440 } 439 }
441 struct IfExpr: AttrsOwner { T![if], Condition } 440 struct IfExpr: AttrsOwner { T![if], Condition }
442 struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] } 441 struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] }
443 struct TryBlockExpr: AttrsOwner { T![try], body: BlockExpr }
444 struct ForExpr: AttrsOwner, LoopBodyOwner { 442 struct ForExpr: AttrsOwner, LoopBodyOwner {
445 T![for], 443 T![for],
446 Pat, 444 Pat,
@@ -451,7 +449,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
451 struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] } 449 struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] }
452 struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr } 450 struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr }
453 struct Label { T![lifetime] } 451 struct Label { T![lifetime] }
454 struct BlockExpr: AttrsOwner { Label, T![unsafe], T![async], Block } 452 struct BlockExpr: AttrsOwner { Label, T![unsafe], T![async], Block }
455 struct ReturnExpr: AttrsOwner { Expr } 453 struct ReturnExpr: AttrsOwner { Expr }
456 struct CallExpr: ArgListOwner { Expr } 454 struct CallExpr: ArgListOwner { Expr }
457 struct MethodCallExpr: AttrsOwner, ArgListOwner { 455 struct MethodCallExpr: AttrsOwner, ArgListOwner {
@@ -722,7 +720,6 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
722 FieldExpr, 720 FieldExpr,
723 AwaitExpr, 721 AwaitExpr,
724 TryExpr, 722 TryExpr,
725 TryBlockExpr,
726 CastExpr, 723 CastExpr,
727 RefExpr, 724 RefExpr,
728 PrefixExpr, 725 PrefixExpr,