diff options
-rw-r--r-- | crates/gen_lsp_server/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/msg.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/function/scope.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 28 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 29 |
5 files changed, 33 insertions, 30 deletions
diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml index 5f90d39d6..9776a82e3 100644 --- a/crates/gen_lsp_server/Cargo.toml +++ b/crates/gen_lsp_server/Cargo.toml | |||
@@ -12,5 +12,5 @@ languageserver-types = "0.53.0" | |||
12 | log = "0.4.3" | 12 | log = "0.4.3" |
13 | failure = "0.1.2" | 13 | failure = "0.1.2" |
14 | serde_json = "1.0.24" | 14 | serde_json = "1.0.24" |
15 | serde = "1.0.71" | 15 | serde = { version = "1.0.71", features = ["derive"] } |
16 | crossbeam-channel = "0.2.4" | 16 | crossbeam-channel = "0.2.4" |
diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs index ef6358cb1..af901d0d2 100644 --- a/crates/gen_lsp_server/src/msg.rs +++ b/crates/gen_lsp_server/src/msg.rs | |||
@@ -7,7 +7,7 @@ use failure::{bail, format_err}; | |||
7 | 7 | ||
8 | use crate::Result; | 8 | use crate::Result; |
9 | 9 | ||
10 | #[derive(Debug, Serialize, Deserialize, Clone)] | 10 | #[derive(Serialize, Deserialize, Debug, Clone)] |
11 | #[serde(untagged)] | 11 | #[serde(untagged)] |
12 | pub enum RawMessage { | 12 | pub enum RawMessage { |
13 | Request(RawRequest), | 13 | Request(RawRequest), |
diff --git a/crates/ra_hir/src/function/scope.rs b/crates/ra_hir/src/function/scope.rs index 9f1aa1ef2..d12f1781e 100644 --- a/crates/ra_hir/src/function/scope.rs +++ b/crates/ra_hir/src/function/scope.rs | |||
@@ -95,7 +95,7 @@ impl FnScopes { | |||
95 | r1.start().cmp(&r2.start()) | 95 | r1.start().cmp(&r2.start()) |
96 | } | 96 | } |
97 | }) | 97 | }) |
98 | .map(|(ptr, scope)| *scope) | 98 | .map(|(_ptr, scope)| *scope) |
99 | .unwrap_or(original_scope) | 99 | .unwrap_or(original_scope) |
100 | } | 100 | } |
101 | 101 | ||
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 218ded4ee..973e0915e 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -1,8 +1,8 @@ | |||
1 | use languageserver_types::{ | 1 | use languageserver_types::{ |
2 | self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, | 2 | self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, |
3 | TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, | 3 | TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, InsertTextFormat, |
4 | }; | 4 | }; |
5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition}; | 5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition, CompletionItem, InsertText}; |
6 | use ra_editor::{LineCol, LineIndex}; | 6 | use ra_editor::{LineCol, LineIndex}; |
7 | use ra_text_edit::{AtomTextEdit, TextEdit}; | 7 | use ra_text_edit::{AtomTextEdit, TextEdit}; |
8 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; | 8 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; |
@@ -45,6 +45,30 @@ impl Conv for SyntaxKind { | |||
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
48 | impl Conv for CompletionItem { | ||
49 | type Output = ::languageserver_types::CompletionItem; | ||
50 | |||
51 | fn conv(self) -> <Self as Conv>::Output { | ||
52 | let mut res = ::languageserver_types::CompletionItem { | ||
53 | label: self.label().to_string(), | ||
54 | filter_text: Some(self.lookup().to_string()), | ||
55 | ..Default::default() | ||
56 | }; | ||
57 | match self.insert_text() { | ||
58 | InsertText::PlainText { text } => { | ||
59 | res.insert_text = Some(text); | ||
60 | res.insert_text_format = Some(InsertTextFormat::PlainText); | ||
61 | } | ||
62 | InsertText::Snippet { text } => { | ||
63 | res.insert_text = Some(text); | ||
64 | res.insert_text_format = Some(InsertTextFormat::Snippet); | ||
65 | res.kind = Some(languageserver_types::CompletionItemKind::Keyword); | ||
66 | } | ||
67 | } | ||
68 | res | ||
69 | } | ||
70 | } | ||
71 | |||
48 | impl ConvWith for Position { | 72 | impl ConvWith for Position { |
49 | type Ctx = LineIndex; | 73 | type Ctx = LineIndex; |
50 | type Output = TextUnit; | 74 | type Output = TextUnit; |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 2dfeb061a..252d1ba3e 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -2,13 +2,13 @@ use std::collections::HashMap; | |||
2 | 2 | ||
3 | use gen_lsp_server::ErrorCode; | 3 | use gen_lsp_server::ErrorCode; |
4 | use languageserver_types::{ | 4 | use languageserver_types::{ |
5 | CodeActionResponse, Command, CompletionItem, CompletionItemKind, Diagnostic, | 5 | CodeActionResponse, Command, Diagnostic, |
6 | DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind, | 6 | DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind, |
7 | FoldingRangeParams, InsertTextFormat, Location, MarkupContent, MarkupKind, MarkedString, Position, | 7 | FoldingRangeParams, Location, MarkupContent, MarkupKind, MarkedString, Position, |
8 | PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, | 8 | PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, |
9 | WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents, | 9 | WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents, |
10 | }; | 10 | }; |
11 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition, InsertText}; | 11 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; |
12 | use ra_syntax::{TextUnit, text_utils::intersect}; | 12 | use ra_syntax::{TextUnit, text_utils::intersect}; |
13 | use ra_text_edit::text_utils::contains_offset_nonstrict; | 13 | use ra_text_edit::text_utils::contains_offset_nonstrict; |
14 | use rustc_hash::FxHashMap; | 14 | use rustc_hash::FxHashMap; |
@@ -419,28 +419,7 @@ pub fn handle_completion( | |||
419 | None => return Ok(None), | 419 | None => return Ok(None), |
420 | Some(items) => items, | 420 | Some(items) => items, |
421 | }; | 421 | }; |
422 | let items = items | 422 | let items = items.into_iter().map(|item| item.conv()).collect(); |
423 | .into_iter() | ||
424 | .map(|item| { | ||
425 | let mut res = CompletionItem { | ||
426 | label: item.label().to_string(), | ||
427 | filter_text: Some(item.lookup().to_string()), | ||
428 | ..Default::default() | ||
429 | }; | ||
430 | match item.insert_text() { | ||
431 | InsertText::PlainText { text } => { | ||
432 | res.insert_text = Some(text); | ||
433 | res.insert_text_format = Some(InsertTextFormat::PlainText); | ||
434 | } | ||
435 | InsertText::Snippet { text } => { | ||
436 | res.insert_text = Some(text); | ||
437 | res.insert_text_format = Some(InsertTextFormat::Snippet); | ||
438 | res.kind = Some(CompletionItemKind::Keyword); | ||
439 | } | ||
440 | } | ||
441 | res | ||
442 | }) | ||
443 | .collect(); | ||
444 | 423 | ||
445 | Ok(Some(req::CompletionResponse::Array(items))) | 424 | Ok(Some(req::CompletionResponse::Array(items))) |
446 | } | 425 | } |