aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/Cargo.toml1
-rw-r--r--crates/ra_lsp_server/src/caps.rs5
-rw-r--r--crates/ra_lsp_server/src/conv.rs6
-rw-r--r--crates/ra_lsp_server/src/lib.rs6
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs42
-rw-r--r--crates/ra_lsp_server/src/main_loop/mod.rs7
-rw-r--r--crates/ra_lsp_server/src/project_model.rs2
-rw-r--r--crates/ra_lsp_server/src/req.rs1
-rw-r--r--crates/ra_lsp_server/src/server_world.rs3
-rw-r--r--crates/ra_lsp_server/src/thread_watcher.rs2
-rw-r--r--crates/ra_lsp_server/src/vfs.rs2
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/main.rs2
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs2
13 files changed, 62 insertions, 19 deletions
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml
index 1fe6b2ebe..2b3257117 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/ra_lsp_server/Cargo.toml
@@ -1,4 +1,5 @@
1[package] 1[package]
2edition = "2018"
2name = "ra_lsp_server" 3name = "ra_lsp_server"
3version = "0.1.0" 4version = "0.1.0"
4authors = ["Aleksey Kladov <[email protected]>"] 5authors = ["Aleksey Kladov <[email protected]>"]
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs
index 3c628f29c..5598ec75f 100644
--- a/crates/ra_lsp_server/src/caps.rs
+++ b/crates/ra_lsp_server/src/caps.rs
@@ -7,6 +7,7 @@ use languageserver_types::{
7 TextDocumentSyncKind, 7 TextDocumentSyncKind,
8 ExecuteCommandOptions, 8 ExecuteCommandOptions,
9 CompletionOptions, 9 CompletionOptions,
10 SignatureHelpOptions,
10 DocumentOnTypeFormattingOptions, 11 DocumentOnTypeFormattingOptions,
11}; 12};
12 13
@@ -26,7 +27,9 @@ pub fn server_capabilities() -> ServerCapabilities {
26 resolve_provider: None, 27 resolve_provider: None,
27 trigger_characters: None, 28 trigger_characters: None,
28 }), 29 }),
29 signature_help_provider: None, 30 signature_help_provider: Some(SignatureHelpOptions {
31 trigger_characters: Some(vec!["(".to_string(), ",".to_string()])
32 }),
30 definition_provider: Some(true), 33 definition_provider: Some(true),
31 type_definition_provider: None, 34 type_definition_provider: None,
32 implementation_provider: None, 35 implementation_provider: None,
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 08a656569..a75b160c5 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -7,7 +7,7 @@ use ra_editor::{LineIndex, LineCol, Edit, AtomEdit};
7use ra_syntax::{SyntaxKind, TextUnit, TextRange}; 7use ra_syntax::{SyntaxKind, TextUnit, TextRange};
8use ra_analysis::{FileId, SourceChange, SourceFileEdit, FileSystemEdit}; 8use ra_analysis::{FileId, SourceChange, SourceFileEdit, FileSystemEdit};
9 9
10use { 10use crate::{
11 Result, 11 Result,
12 server_world::ServerWorld, 12 server_world::ServerWorld,
13 req, 13 req,
@@ -299,7 +299,7 @@ pub fn to_location(
299 Ok(loc) 299 Ok(loc)
300} 300}
301 301
302pub trait MapConvWith<'a>: Sized { 302pub trait MapConvWith<'a>: Sized + 'a {
303 type Ctx; 303 type Ctx;
304 type Output; 304 type Output;
305 305
@@ -309,7 +309,7 @@ pub trait MapConvWith<'a>: Sized {
309} 309}
310 310
311impl<'a, I> MapConvWith<'a> for I 311impl<'a, I> MapConvWith<'a> for I
312 where I: Iterator, 312 where I: Iterator + 'a,
313 I::Item: ConvWith 313 I::Item: ConvWith
314{ 314{
315 type Ctx = <I::Item as ConvWith>::Ctx; 315 type Ctx = <I::Item as ConvWith>::Ctx;
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs
index 60652d55e..7224b1476 100644
--- a/crates/ra_lsp_server/src/lib.rs
+++ b/crates/ra_lsp_server/src/lib.rs
@@ -34,5 +34,7 @@ mod project_model;
34pub mod thread_watcher; 34pub mod thread_watcher;
35 35
36pub type Result<T> = ::std::result::Result<T, ::failure::Error>; 36pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
37pub use caps::server_capabilities; 37pub use crate::{
38pub use main_loop::main_loop; 38 main_loop::main_loop,
39 caps::server_capabilities,
40};
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index ab8be15e9..5acb39b60 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -13,7 +13,7 @@ use ra_syntax::{
13 text_utils::contains_offset_nonstrict 13 text_utils::contains_offset_nonstrict
14}; 14};
15 15
16use ::{ 16use crate::{
17 req::{self, Decoration}, Result, 17 req::{self, Decoration}, Result,
18 conv::{Conv, ConvWith, TryConvWith, MapConvWith, to_location}, 18 conv::{Conv, ConvWith, TryConvWith, MapConvWith, to_location},
19 server_world::ServerWorld, 19 server_world::ServerWorld,
@@ -411,6 +411,42 @@ pub fn handle_folding_range(
411 Ok(res) 411 Ok(res)
412} 412}
413 413
414pub fn handle_signature_help(
415 world: ServerWorld,
416 params: req::TextDocumentPositionParams,
417 token: JobToken,
418) -> Result<Option<req::SignatureHelp>> {
419 use languageserver_types::{ParameterInformation, SignatureInformation};
420
421 let file_id = params.text_document.try_conv_with(&world)?;
422 let line_index = world.analysis().file_line_index(file_id);
423 let offset = params.position.conv_with(&line_index);
424
425 if let Some((descriptor, active_param)) = world.analysis().resolve_callable(file_id, offset, &token) {
426 let parameters : Vec<ParameterInformation> =
427 descriptor.params.iter().map(|param|
428 ParameterInformation {
429 label: param.clone(),
430 documentation: None
431 }
432 ).collect();
433
434 let sig_info = SignatureInformation {
435 label: descriptor.label,
436 documentation: None,
437 parameters: Some(parameters)
438 };
439
440 Ok(Some(req::SignatureHelp {
441 signatures: vec![sig_info],
442 active_signature: Some(0),
443 active_parameter: active_param.map(|a| a as u64)
444 }))
445 } else {
446 Ok(None)
447 }
448}
449
414pub fn handle_code_action( 450pub fn handle_code_action(
415 world: ServerWorld, 451 world: ServerWorld,
416 params: req::CodeActionParams, 452 params: req::CodeActionParams,
@@ -442,7 +478,7 @@ pub fn handle_code_action(
442} 478}
443 479
444pub fn publish_diagnostics( 480pub fn publish_diagnostics(
445 world: ServerWorld, 481 world: &ServerWorld,
446 file_id: FileId, 482 file_id: FileId,
447) -> Result<req::PublishDiagnosticsParams> { 483) -> Result<req::PublishDiagnosticsParams> {
448 let uri = world.file_id_to_uri(file_id)?; 484 let uri = world.file_id_to_uri(file_id)?;
@@ -461,7 +497,7 @@ pub fn publish_diagnostics(
461} 497}
462 498
463pub fn publish_decorations( 499pub fn publish_decorations(
464 world: ServerWorld, 500 world: &ServerWorld,
465 file_id: FileId, 501 file_id: FileId,
466) -> Result<req::PublishDecorationsParams> { 502) -> Result<req::PublishDecorationsParams> {
467 let uri = world.file_id_to_uri(file_id)?; 503 let uri = world.file_id_to_uri(file_id)?;
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs
index 402615e42..cf2477cb5 100644
--- a/crates/ra_lsp_server/src/main_loop/mod.rs
+++ b/crates/ra_lsp_server/src/main_loop/mod.rs
@@ -16,7 +16,7 @@ use gen_lsp_server::{
16}; 16};
17use rustc_hash::FxHashMap; 17use rustc_hash::FxHashMap;
18 18
19use { 19use crate::{
20 req, 20 req,
21 Result, 21 Result,
22 vfs::{self, FileEvent}, 22 vfs::{self, FileEvent},
@@ -255,6 +255,7 @@ fn on_request(
255 .on::<req::Completion>(handlers::handle_completion)? 255 .on::<req::Completion>(handlers::handle_completion)?
256 .on::<req::CodeActionRequest>(handlers::handle_code_action)? 256 .on::<req::CodeActionRequest>(handlers::handle_code_action)?
257 .on::<req::FoldingRangeRequest>(handlers::handle_folding_range)? 257 .on::<req::FoldingRangeRequest>(handlers::handle_folding_range)?
258 .on::<req::SignatureHelpRequest>(handlers::handle_signature_help)?
258 .finish(); 259 .finish();
259 match req { 260 match req {
260 Ok((id, handle)) => { 261 Ok((id, handle)) => {
@@ -390,7 +391,7 @@ fn update_file_notifications_on_threadpool(
390) { 391) {
391 pool.spawn(move || { 392 pool.spawn(move || {
392 for file_id in subscriptions { 393 for file_id in subscriptions {
393 match handlers::publish_diagnostics(world.clone(), file_id) { 394 match handlers::publish_diagnostics(&world, file_id) {
394 Err(e) => { 395 Err(e) => {
395 error!("failed to compute diagnostics: {:?}", e) 396 error!("failed to compute diagnostics: {:?}", e)
396 } 397 }
@@ -399,7 +400,7 @@ fn update_file_notifications_on_threadpool(
399 sender.send(Task::Notify(not)); 400 sender.send(Task::Notify(not));
400 } 401 }
401 } 402 }
402 match handlers::publish_decorations(world.clone(), file_id) { 403 match handlers::publish_decorations(&world, file_id) {
403 Err(e) => { 404 Err(e) => {
404 error!("failed to compute decorations: {:?}", e) 405 error!("failed to compute decorations: {:?}", e)
405 } 406 }
diff --git a/crates/ra_lsp_server/src/project_model.rs b/crates/ra_lsp_server/src/project_model.rs
index 43e4fd654..c144d9596 100644
--- a/crates/ra_lsp_server/src/project_model.rs
+++ b/crates/ra_lsp_server/src/project_model.rs
@@ -5,7 +5,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
5use cargo_metadata::{metadata_run, CargoOpt}; 5use cargo_metadata::{metadata_run, CargoOpt};
6use ra_syntax::SmolStr; 6use ra_syntax::SmolStr;
7 7
8use { 8use crate::{
9 Result, 9 Result,
10 thread_watcher::{Worker, ThreadWatcher}, 10 thread_watcher::{Worker, ThreadWatcher},
11}; 11};
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs
index f80957589..1630edf7f 100644
--- a/crates/ra_lsp_server/src/req.rs
+++ b/crates/ra_lsp_server/src/req.rs
@@ -14,6 +14,7 @@ pub use languageserver_types::{
14 CompletionParams, CompletionResponse, 14 CompletionParams, CompletionResponse,
15 DocumentOnTypeFormattingParams, 15 DocumentOnTypeFormattingParams,
16 TextDocumentEdit, 16 TextDocumentEdit,
17 SignatureHelp, Hover
17}; 18};
18 19
19pub enum SyntaxTree {} 20pub enum SyntaxTree {}
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs
index c4cdf83d4..9b3013ae8 100644
--- a/crates/ra_lsp_server/src/server_world.rs
+++ b/crates/ra_lsp_server/src/server_world.rs
@@ -8,7 +8,7 @@ use rustc_hash::FxHashMap;
8use languageserver_types::Url; 8use languageserver_types::Url;
9use ra_analysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId, LibraryData, FileResolver}; 9use ra_analysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId, LibraryData, FileResolver};
10 10
11use { 11use crate::{
12 Result, 12 Result,
13 path_map::{PathMap, Root}, 13 path_map::{PathMap, Root},
14 vfs::{FileEvent, FileEventKind}, 14 vfs::{FileEvent, FileEventKind},
@@ -23,7 +23,6 @@ pub struct ServerWorldState {
23 pub mem_map: FxHashMap<FileId, Option<String>>, 23 pub mem_map: FxHashMap<FileId, Option<String>>,
24} 24}
25 25
26#[derive(Clone)]
27pub struct ServerWorld { 26pub struct ServerWorld {
28 pub workspaces: Arc<Vec<CargoWorkspace>>, 27 pub workspaces: Arc<Vec<CargoWorkspace>>,
29 pub analysis: Analysis, 28 pub analysis: Analysis,
diff --git a/crates/ra_lsp_server/src/thread_watcher.rs b/crates/ra_lsp_server/src/thread_watcher.rs
index 86a3a91e0..3257effcb 100644
--- a/crates/ra_lsp_server/src/thread_watcher.rs
+++ b/crates/ra_lsp_server/src/thread_watcher.rs
@@ -1,7 +1,7 @@
1use std::thread; 1use std::thread;
2use crossbeam_channel::{bounded, unbounded, Sender, Receiver}; 2use crossbeam_channel::{bounded, unbounded, Sender, Receiver};
3use drop_bomb::DropBomb; 3use drop_bomb::DropBomb;
4use Result; 4use crate::Result;
5 5
6pub struct Worker<I, O> { 6pub struct Worker<I, O> {
7 pub inp: Sender<I>, 7 pub inp: Sender<I>,
diff --git a/crates/ra_lsp_server/src/vfs.rs b/crates/ra_lsp_server/src/vfs.rs
index a1c1783f2..d8f9b1aac 100644
--- a/crates/ra_lsp_server/src/vfs.rs
+++ b/crates/ra_lsp_server/src/vfs.rs
@@ -5,7 +5,7 @@ use std::{
5 5
6use walkdir::WalkDir; 6use walkdir::WalkDir;
7 7
8use { 8use crate::{
9 thread_watcher::{Worker, ThreadWatcher}, 9 thread_watcher::{Worker, ThreadWatcher},
10}; 10};
11 11
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs
index dced45f55..7265b5999 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/main.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs
@@ -12,7 +12,7 @@ mod support;
12 12
13use ra_lsp_server::req::{Runnables, RunnablesParams}; 13use ra_lsp_server::req::{Runnables, RunnablesParams};
14 14
15use support::project; 15use crate::support::project;
16 16
17 17
18const LOG: &'static str = ""; 18const LOG: &'static str = "";
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs
index 8fe2aa816..d1339f62f 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/support.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs
@@ -25,7 +25,7 @@ use ra_lsp_server::{main_loop, req, thread_watcher::{ThreadWatcher, Worker}};
25 25
26pub fn project(fixture: &str) -> Server { 26pub fn project(fixture: &str) -> Server {
27 static INIT: Once = Once::new(); 27 static INIT: Once = Once::new();
28 INIT.call_once(|| Logger::with_env_or_str(::LOG).start().unwrap()); 28 INIT.call_once(|| Logger::with_env_or_str(crate::LOG).start().unwrap());
29 29
30 let tmp_dir = TempDir::new("test-project") 30 let tmp_dir = TempDir::new("test-project")
31 .unwrap(); 31 .unwrap();