diff options
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 44 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main.rs | 4 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 56 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 21 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/req.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 1 |
7 files changed, 96 insertions, 33 deletions
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index fc10096e5..3c8c240cd 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -12,7 +12,6 @@ failure = "0.1.2" | |||
12 | failure_derive = "0.1.2" | 12 | failure_derive = "0.1.2" |
13 | serde_json = "1.0.24" | 13 | serde_json = "1.0.24" |
14 | serde = "1.0.71" | 14 | serde = "1.0.71" |
15 | serde_derive = "1.0.71" | ||
16 | drop_bomb = "0.1.0" | 15 | drop_bomb = "0.1.0" |
17 | crossbeam-channel = "0.2.4" | 16 | crossbeam-channel = "0.2.4" |
18 | flexi_logger = "0.10.0" | 17 | flexi_logger = "0.10.0" |
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 218ded4ee..051f1f995 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, CompletionItemKind, 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,46 @@ impl Conv for SyntaxKind { | |||
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
48 | impl Conv for CompletionItemKind { | ||
49 | type Output = ::languageserver_types::CompletionItemKind; | ||
50 | |||
51 | fn conv(self) -> <Self as Conv>::Output { | ||
52 | use ::languageserver_types::CompletionItemKind::*; | ||
53 | match self { | ||
54 | CompletionItemKind::Keyword => Keyword, | ||
55 | CompletionItemKind::Snippet => Snippet, | ||
56 | CompletionItemKind::Module => Module, | ||
57 | CompletionItemKind::Function => Function, | ||
58 | CompletionItemKind::Binding => Variable, | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | impl Conv for CompletionItem { | ||
64 | type Output = ::languageserver_types::CompletionItem; | ||
65 | |||
66 | fn conv(self) -> <Self as Conv>::Output { | ||
67 | let mut res = ::languageserver_types::CompletionItem { | ||
68 | label: self.label().to_string(), | ||
69 | filter_text: Some(self.lookup().to_string()), | ||
70 | kind: self.kind().map(|it| it.conv()), | ||
71 | ..Default::default() | ||
72 | }; | ||
73 | match self.insert_text() { | ||
74 | InsertText::PlainText { text } => { | ||
75 | res.insert_text = Some(text); | ||
76 | res.insert_text_format = Some(InsertTextFormat::PlainText); | ||
77 | } | ||
78 | InsertText::Snippet { text } => { | ||
79 | res.insert_text = Some(text); | ||
80 | res.insert_text_format = Some(InsertTextFormat::Snippet); | ||
81 | res.kind = Some(languageserver_types::CompletionItemKind::Keyword); | ||
82 | } | ||
83 | } | ||
84 | res | ||
85 | } | ||
86 | } | ||
87 | |||
48 | impl ConvWith for Position { | 88 | impl ConvWith for Position { |
49 | type Ctx = LineIndex; | 89 | type Ctx = LineIndex; |
50 | type Output = TextUnit; | 90 | type Output = TextUnit; |
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 4497980e5..eae601f91 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use serde_derive::Deserialize; | 1 | use serde::Deserialize; |
2 | use serde::Deserialize as _D; | ||
3 | use flexi_logger::{Duplicate, Logger}; | 2 | use flexi_logger::{Duplicate, Logger}; |
4 | use gen_lsp_server::{run_server, stdio_transport}; | 3 | use gen_lsp_server::{run_server, stdio_transport}; |
4 | |||
5 | use ra_lsp_server::Result; | 5 | use ra_lsp_server::Result; |
6 | 6 | ||
7 | fn main() -> Result<()> { | 7 | fn main() -> Result<()> { |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index afe0fec89..565ec92af 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -2,6 +2,7 @@ mod handlers; | |||
2 | mod subscriptions; | 2 | mod subscriptions; |
3 | 3 | ||
4 | use std::{ | 4 | use std::{ |
5 | fmt, | ||
5 | path::PathBuf, | 6 | path::PathBuf, |
6 | sync::Arc, | 7 | sync::Arc, |
7 | }; | 8 | }; |
@@ -109,6 +110,50 @@ pub fn main_loop( | |||
109 | Ok(()) | 110 | Ok(()) |
110 | } | 111 | } |
111 | 112 | ||
113 | enum Event { | ||
114 | Msg(RawMessage), | ||
115 | Task(Task), | ||
116 | Vfs(VfsTask), | ||
117 | Lib(LibraryData), | ||
118 | } | ||
119 | |||
120 | impl fmt::Debug for Event { | ||
121 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
122 | let debug_verbose_not = |not: &RawNotification, f: &mut fmt::Formatter| { | ||
123 | f.debug_struct("RawNotification") | ||
124 | .field("method", ¬.method) | ||
125 | .finish() | ||
126 | }; | ||
127 | |||
128 | match self { | ||
129 | Event::Msg(RawMessage::Notification(not)) => { | ||
130 | if not.is::<req::DidOpenTextDocument>() || not.is::<req::DidChangeTextDocument>() { | ||
131 | return debug_verbose_not(not, f); | ||
132 | } | ||
133 | } | ||
134 | Event::Task(Task::Notify(not)) => { | ||
135 | if not.is::<req::PublishDecorations>() || not.is::<req::PublishDiagnostics>() { | ||
136 | return debug_verbose_not(not, f); | ||
137 | } | ||
138 | } | ||
139 | Event::Task(Task::Respond(resp)) => { | ||
140 | return f | ||
141 | .debug_struct("RawResponse") | ||
142 | .field("id", &resp.id) | ||
143 | .field("error", &resp.error) | ||
144 | .finish(); | ||
145 | } | ||
146 | _ => (), | ||
147 | } | ||
148 | match self { | ||
149 | Event::Msg(it) => fmt::Debug::fmt(it, f), | ||
150 | Event::Task(it) => fmt::Debug::fmt(it, f), | ||
151 | Event::Vfs(it) => fmt::Debug::fmt(it, f), | ||
152 | Event::Lib(it) => fmt::Debug::fmt(it, f), | ||
153 | } | ||
154 | } | ||
155 | } | ||
156 | |||
112 | fn main_loop_inner( | 157 | fn main_loop_inner( |
113 | internal_mode: bool, | 158 | internal_mode: bool, |
114 | publish_decorations: bool, | 159 | publish_decorations: bool, |
@@ -123,13 +168,6 @@ fn main_loop_inner( | |||
123 | ) -> Result<()> { | 168 | ) -> Result<()> { |
124 | let (libdata_sender, libdata_receiver) = unbounded(); | 169 | let (libdata_sender, libdata_receiver) = unbounded(); |
125 | loop { | 170 | loop { |
126 | #[derive(Debug)] | ||
127 | enum Event { | ||
128 | Msg(RawMessage), | ||
129 | Task(Task), | ||
130 | Vfs(VfsTask), | ||
131 | Lib(LibraryData), | ||
132 | } | ||
133 | log::trace!("selecting"); | 171 | log::trace!("selecting"); |
134 | let event = select! { | 172 | let event = select! { |
135 | recv(msg_receiver, msg) => match msg { | 173 | recv(msg_receiver, msg) => match msg { |
@@ -143,7 +181,8 @@ fn main_loop_inner( | |||
143 | } | 181 | } |
144 | recv(libdata_receiver, data) => Event::Lib(data.unwrap()) | 182 | recv(libdata_receiver, data) => Event::Lib(data.unwrap()) |
145 | }; | 183 | }; |
146 | log::info!("{:?}", event); | 184 | log::info!("loop_turn = {:?}", event); |
185 | let start = std::time::Instant::now(); | ||
147 | let mut state_changed = false; | 186 | let mut state_changed = false; |
148 | match event { | 187 | match event { |
149 | Event::Task(task) => on_task(task, msg_sender, pending_requests), | 188 | Event::Task(task) => on_task(task, msg_sender, pending_requests), |
@@ -206,6 +245,7 @@ fn main_loop_inner( | |||
206 | subs.subscriptions(), | 245 | subs.subscriptions(), |
207 | ) | 246 | ) |
208 | } | 247 | } |
248 | log::info!("loop_turn = {:?}", start.elapsed()); | ||
209 | } | 249 | } |
210 | } | 250 | } |
211 | 251 | ||
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 1751d7fa8..252d1ba3e 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -2,9 +2,9 @@ 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 | }; |
@@ -419,22 +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, | ||
427 | filter_text: item.lookup, | ||
428 | ..Default::default() | ||
429 | }; | ||
430 | if let Some(snip) = item.snippet { | ||
431 | res.insert_text = Some(snip); | ||
432 | res.insert_text_format = Some(InsertTextFormat::Snippet); | ||
433 | res.kind = Some(CompletionItemKind::Keyword); | ||
434 | }; | ||
435 | res | ||
436 | }) | ||
437 | .collect(); | ||
438 | 423 | ||
439 | Ok(Some(req::CompletionResponse::Array(items))) | 424 | Ok(Some(req::CompletionResponse::Array(items))) |
440 | } | 425 | } |
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index 999792ecb..747ab8a8c 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use serde_derive::{Serialize, Deserialize}; | 1 | use serde::{Serialize, Deserialize}; |
2 | use languageserver_types::{Location, Position, Range, TextDocumentIdentifier, Url}; | 2 | use languageserver_types::{Location, Position, Range, TextDocumentIdentifier, Url}; |
3 | use rustc_hash::FxHashMap; | 3 | use rustc_hash::FxHashMap; |
4 | use url_serde; | 4 | use url_serde; |
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 73cccc9dd..c183c25af 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs | |||
@@ -107,7 +107,6 @@ impl ServerWorldState { | |||
107 | let mut libs = Vec::new(); | 107 | let mut libs = Vec::new(); |
108 | let mut change = AnalysisChange::new(); | 108 | let mut change = AnalysisChange::new(); |
109 | for c in changes { | 109 | for c in changes { |
110 | log::info!("vfs change {:?}", c); | ||
111 | match c { | 110 | match c { |
112 | VfsChange::AddRoot { root, files } => { | 111 | VfsChange::AddRoot { root, files } => { |
113 | let root_path = self.vfs.read().root2path(root); | 112 | let root_path = self.vfs.read().root2path(root); |