aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-09-25 12:43:48 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-09-25 12:43:48 +0100
commit7eb047a105ee42b5dbd8f5cf7d956ca7bdfd551a (patch)
tree7edf00b8f1e7416b364127c31dafe02df1685587 /crates/ra_lsp_server/src
parentc2ab6ad73d2a7cd9a54dd8ee9f96dab25ec89600 (diff)
parent4d52d004d58ff8d0479220d22bd0adfcfd7ffa9f (diff)
Merge #79
79: Implement Folding Ranges r=matklad a=kjeremy Implements folding ranges for comments and imports. Bumps LSP to 3.13 Co-authored-by: Jeremy A. Kolb <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r--crates/ra_lsp_server/src/caps.rs6
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs44
-rw-r--r--crates/ra_lsp_server/src/main_loop/mod.rs1
3 files changed, 44 insertions, 7 deletions
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs
index 7456aea8a..3c628f29c 100644
--- a/crates/ra_lsp_server/src/caps.rs
+++ b/crates/ra_lsp_server/src/caps.rs
@@ -1,5 +1,7 @@
1use languageserver_types::{ 1use languageserver_types::{
2 ServerCapabilities, 2 ServerCapabilities,
3 CodeActionProviderCapability,
4 FoldingRangeProviderCapability,
3 TextDocumentSyncCapability, 5 TextDocumentSyncCapability,
4 TextDocumentSyncOptions, 6 TextDocumentSyncOptions,
5 TextDocumentSyncKind, 7 TextDocumentSyncKind,
@@ -32,7 +34,7 @@ pub fn server_capabilities() -> ServerCapabilities {
32 document_highlight_provider: None, 34 document_highlight_provider: None,
33 document_symbol_provider: Some(true), 35 document_symbol_provider: Some(true),
34 workspace_symbol_provider: Some(true), 36 workspace_symbol_provider: Some(true),
35 code_action_provider: Some(true), 37 code_action_provider: Some(CodeActionProviderCapability::Simple(true)),
36 code_lens_provider: None, 38 code_lens_provider: None,
37 document_formatting_provider: None, 39 document_formatting_provider: None,
38 document_range_formatting_provider: None, 40 document_range_formatting_provider: None,
@@ -40,10 +42,12 @@ pub fn server_capabilities() -> ServerCapabilities {
40 first_trigger_character: "=".to_string(), 42 first_trigger_character: "=".to_string(),
41 more_trigger_character: None, 43 more_trigger_character: None,
42 }), 44 }),
45 folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)),
43 rename_provider: None, 46 rename_provider: None,
44 color_provider: None, 47 color_provider: None,
45 execute_command_provider: Some(ExecuteCommandOptions { 48 execute_command_provider: Some(ExecuteCommandOptions {
46 commands: vec!["apply_code_action".to_string()], 49 commands: vec!["apply_code_action".to_string()],
47 }), 50 }),
51 workspace: None,
48 } 52 }
49} 53}
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index b2ebc9cdc..51061543c 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -1,15 +1,16 @@
1use std::collections::HashMap; 1use std::collections::{HashMap};
2 2
3use languageserver_types::{ 3use languageserver_types::{
4 Diagnostic, DiagnosticSeverity, DocumentSymbol, 4 Diagnostic, DiagnosticSeverity, DocumentSymbol,
5 Command, TextDocumentIdentifier, 5 CodeActionResponse, Command, TextDocumentIdentifier,
6 SymbolInformation, Position, Location, TextEdit, 6 SymbolInformation, Position, Location, TextEdit,
7 CompletionItem, InsertTextFormat, CompletionItemKind, 7 CompletionItem, InsertTextFormat, CompletionItemKind,
8 FoldingRange, FoldingRangeParams, FoldingRangeKind
8}; 9};
9use serde_json::to_value; 10use serde_json::to_value;
10use ra_analysis::{Query, FileId, RunnableKind, JobToken}; 11use ra_analysis::{Query, FileId, RunnableKind, JobToken, FoldKind};
11use ra_syntax::{ 12use ra_syntax::{
12 text_utils::contains_offset_nonstrict, 13 text_utils::contains_offset_nonstrict
13}; 14};
14 15
15use ::{ 16use ::{
@@ -177,6 +178,7 @@ pub fn handle_workspace_symbol(
177 world, &line_index 178 world, &line_index
178 )?, 179 )?,
179 container_name: None, 180 container_name: None,
181 deprecated: None,
180 }; 182 };
181 res.push(info); 183 res.push(info);
182 }; 184 };
@@ -365,11 +367,41 @@ pub fn handle_completion(
365 Ok(Some(req::CompletionResponse::Array(items))) 367 Ok(Some(req::CompletionResponse::Array(items)))
366} 368}
367 369
370pub fn handle_folding_range(
371 world: ServerWorld,
372 params: FoldingRangeParams,
373 _token: JobToken,
374) -> Result<Option<Vec<FoldingRange>>> {
375 let file_id = params.text_document.try_conv_with(&world)?;
376 let line_index = world.analysis().file_line_index(file_id);
377
378 let res = Some(world.analysis()
379 .folding_ranges(file_id)
380 .into_iter()
381 .map(|fold| {
382 let kind = match fold.kind {
383 FoldKind::Comment => FoldingRangeKind::Comment,
384 FoldKind::Imports => FoldingRangeKind::Imports
385 };
386 let range = fold.range.conv_with(&line_index);
387 FoldingRange {
388 start_line: range.start.line,
389 start_character: Some(range.start.character),
390 end_line: range.end.line,
391 end_character: Some(range.start.character),
392 kind: Some(kind)
393 }
394 })
395 .collect());
396
397 Ok(res)
398}
399
368pub fn handle_code_action( 400pub fn handle_code_action(
369 world: ServerWorld, 401 world: ServerWorld,
370 params: req::CodeActionParams, 402 params: req::CodeActionParams,
371 _token: JobToken, 403 _token: JobToken,
372) -> Result<Option<Vec<Command>>> { 404) -> Result<Option<CodeActionResponse>> {
373 let file_id = params.text_document.try_conv_with(&world)?; 405 let file_id = params.text_document.try_conv_with(&world)?;
374 let line_index = world.analysis().file_line_index(file_id); 406 let line_index = world.analysis().file_line_index(file_id);
375 let range = params.range.conv_with(&line_index); 407 let range = params.range.conv_with(&line_index);
@@ -392,7 +424,7 @@ pub fn handle_code_action(
392 res.push(cmd); 424 res.push(cmd);
393 } 425 }
394 426
395 Ok(Some(res)) 427 Ok(Some(CodeActionResponse::Commands(res)))
396} 428}
397 429
398pub fn publish_diagnostics( 430pub fn publish_diagnostics(
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs
index 2b2279e97..abc58b70e 100644
--- a/crates/ra_lsp_server/src/main_loop/mod.rs
+++ b/crates/ra_lsp_server/src/main_loop/mod.rs
@@ -253,6 +253,7 @@ fn on_request(
253 .on::<req::DecorationsRequest>(handlers::handle_decorations)? 253 .on::<req::DecorationsRequest>(handlers::handle_decorations)?
254 .on::<req::Completion>(handlers::handle_completion)? 254 .on::<req::Completion>(handlers::handle_completion)?
255 .on::<req::CodeActionRequest>(handlers::handle_code_action)? 255 .on::<req::CodeActionRequest>(handlers::handle_code_action)?
256 .on::<req::FoldingRangeRequest>(handlers::handle_folding_range)?
256 .finish(); 257 .finish();
257 match req { 258 match req {
258 Ok((id, handle)) => { 259 Ok((id, handle)) => {