diff options
Diffstat (limited to 'crates/server/src')
-rw-r--r-- | crates/server/src/conv.rs | 8 | ||||
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 21 | ||||
-rw-r--r-- | crates/server/src/main_loop/mod.rs | 4 | ||||
-rw-r--r-- | crates/server/src/req.rs | 17 |
4 files changed, 48 insertions, 2 deletions
diff --git a/crates/server/src/conv.rs b/crates/server/src/conv.rs index bbe512ece..b3709ccaf 100644 --- a/crates/server/src/conv.rs +++ b/crates/server/src/conv.rs | |||
@@ -117,6 +117,14 @@ impl ConvWith for AtomEdit { | |||
117 | } | 117 | } |
118 | } | 118 | } |
119 | 119 | ||
120 | impl<T: ConvWith> ConvWith for Option<T> { | ||
121 | type Ctx = <T as ConvWith>::Ctx; | ||
122 | type Output = Option<<T as ConvWith>::Output>; | ||
123 | fn conv_with(self, ctx: &Self::Ctx) -> Self::Output { | ||
124 | self.map(|x| ConvWith::conv_with(x, ctx)) | ||
125 | } | ||
126 | } | ||
127 | |||
120 | impl<'a> TryConvWith for &'a Url { | 128 | impl<'a> TryConvWith for &'a Url { |
121 | type Ctx = PathMap; | 129 | type Ctx = PathMap; |
122 | type Output = FileId; | 130 | type Output = FileId; |
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index 078abfbfa..d7b78b4fa 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs | |||
@@ -3,7 +3,7 @@ use std::collections::HashMap; | |||
3 | use languageserver_types::{ | 3 | use languageserver_types::{ |
4 | Diagnostic, DiagnosticSeverity, Url, DocumentSymbol, | 4 | Diagnostic, DiagnosticSeverity, Url, DocumentSymbol, |
5 | Command, TextDocumentIdentifier, WorkspaceEdit, | 5 | Command, TextDocumentIdentifier, WorkspaceEdit, |
6 | SymbolInformation, | 6 | SymbolInformation, Position, |
7 | }; | 7 | }; |
8 | use libanalysis::{World, Query}; | 8 | use libanalysis::{World, Query}; |
9 | use libeditor; | 9 | use libeditor; |
@@ -42,6 +42,25 @@ pub fn handle_extend_selection( | |||
42 | Ok(req::ExtendSelectionResult { selections }) | 42 | Ok(req::ExtendSelectionResult { selections }) |
43 | } | 43 | } |
44 | 44 | ||
45 | pub fn handle_find_matching_brace( | ||
46 | world: World, | ||
47 | path_map: PathMap, | ||
48 | params: req::FindMatchingBraceParams, | ||
49 | ) -> Result<Vec<Position>> { | ||
50 | let file_id = params.text_document.try_conv_with(&path_map)?; | ||
51 | let file = world.file_syntax(file_id)?; | ||
52 | let line_index = world.file_line_index(file_id)?; | ||
53 | let res = params.offsets | ||
54 | .into_iter() | ||
55 | .map_conv_with(&line_index) | ||
56 | .map(|offset| { | ||
57 | libeditor::matching_brace(&file, offset).unwrap_or(offset) | ||
58 | }) | ||
59 | .map_conv_with(&line_index) | ||
60 | .collect(); | ||
61 | Ok(res) | ||
62 | } | ||
63 | |||
45 | pub fn handle_document_symbol( | 64 | pub fn handle_document_symbol( |
46 | world: World, | 65 | world: World, |
47 | path_map: PathMap, | 66 | path_map: PathMap, |
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index 2a31297be..4d5dfb437 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs | |||
@@ -26,6 +26,7 @@ use { | |||
26 | handle_execute_command, | 26 | handle_execute_command, |
27 | handle_workspace_symbol, | 27 | handle_workspace_symbol, |
28 | handle_goto_definition, | 28 | handle_goto_definition, |
29 | handle_find_matching_brace, | ||
29 | }, | 30 | }, |
30 | }; | 31 | }; |
31 | 32 | ||
@@ -148,6 +149,9 @@ fn on_request( | |||
148 | handle_request_on_threadpool::<req::ExtendSelection>( | 149 | handle_request_on_threadpool::<req::ExtendSelection>( |
149 | &mut req, pool, path_map, world, sender, handle_extend_selection, | 150 | &mut req, pool, path_map, world, sender, handle_extend_selection, |
150 | )?; | 151 | )?; |
152 | handle_request_on_threadpool::<req::FindMatchingBrace>( | ||
153 | &mut req, pool, path_map, world, sender, handle_find_matching_brace, | ||
154 | )?; | ||
151 | handle_request_on_threadpool::<req::DocumentSymbolRequest>( | 155 | handle_request_on_threadpool::<req::DocumentSymbolRequest>( |
152 | &mut req, pool, path_map, world, sender, handle_document_symbol, | 156 | &mut req, pool, path_map, world, sender, handle_document_symbol, |
153 | )?; | 157 | )?; |
diff --git a/crates/server/src/req.rs b/crates/server/src/req.rs index 17ef10e43..c3efc7489 100644 --- a/crates/server/src/req.rs +++ b/crates/server/src/req.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use serde::{ser::Serialize, de::DeserializeOwned}; | 1 | use serde::{ser::Serialize, de::DeserializeOwned}; |
2 | use languageserver_types::{TextDocumentIdentifier, Range, Url}; | 2 | use languageserver_types::{TextDocumentIdentifier, Range, Url, Position}; |
3 | use url_serde; | 3 | use url_serde; |
4 | 4 | ||
5 | pub use languageserver_types::{ | 5 | pub use languageserver_types::{ |
@@ -65,6 +65,21 @@ pub struct ExtendSelectionResult { | |||
65 | pub selections: Vec<Range>, | 65 | pub selections: Vec<Range>, |
66 | } | 66 | } |
67 | 67 | ||
68 | pub enum FindMatchingBrace {} | ||
69 | |||
70 | impl Request for FindMatchingBrace { | ||
71 | type Params = FindMatchingBraceParams; | ||
72 | type Result = Vec<Position>; | ||
73 | const METHOD: &'static str = "m/findMatchingBrace"; | ||
74 | } | ||
75 | |||
76 | #[derive(Deserialize, Debug)] | ||
77 | #[serde(rename_all = "camelCase")] | ||
78 | pub struct FindMatchingBraceParams { | ||
79 | pub text_document: TextDocumentIdentifier, | ||
80 | pub offsets: Vec<Position>, | ||
81 | } | ||
82 | |||
68 | pub enum PublishDecorations {} | 83 | pub enum PublishDecorations {} |
69 | 84 | ||
70 | impl Notification for PublishDecorations { | 85 | impl Notification for PublishDecorations { |