diff options
author | Aleksey Kladov <[email protected]> | 2018-11-08 15:43:02 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-11-08 15:43:02 +0000 |
commit | 00e80b24e3a46b3c4a6411151132fccc539abd5f (patch) | |
tree | 76fb0982fa8da3a915c7c226892681b30a044a86 | |
parent | c69ff08dc9074ed92c11e9fb6bf267288aa3fa25 (diff) |
workspace-symbols function for Emacs
-rw-r--r-- | crates/ra_lsp_server/src/main.rs | 22 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/mod.rs | 23 | ||||
-rw-r--r-- | editors/code/src/server.ts | 5 | ||||
-rw-r--r-- | editors/emacs/ra.el | 5 |
4 files changed, 43 insertions, 12 deletions
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 4d555d488..26bcddd8e 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -2,10 +2,14 @@ | |||
2 | extern crate log; | 2 | extern crate log; |
3 | #[macro_use] | 3 | #[macro_use] |
4 | extern crate failure; | 4 | extern crate failure; |
5 | #[macro_use] | ||
6 | extern crate serde_derive; | ||
7 | extern crate serde; | ||
5 | extern crate flexi_logger; | 8 | extern crate flexi_logger; |
6 | extern crate gen_lsp_server; | 9 | extern crate gen_lsp_server; |
7 | extern crate ra_lsp_server; | 10 | extern crate ra_lsp_server; |
8 | 11 | ||
12 | use serde::Deserialize; | ||
9 | use flexi_logger::{Duplicate, Logger}; | 13 | use flexi_logger::{Duplicate, Logger}; |
10 | use gen_lsp_server::{run_server, stdio_transport}; | 14 | use gen_lsp_server::{run_server, stdio_transport}; |
11 | use ra_lsp_server::Result; | 15 | use ra_lsp_server::Result; |
@@ -29,6 +33,13 @@ fn main() -> Result<()> { | |||
29 | } | 33 | } |
30 | } | 34 | } |
31 | } | 35 | } |
36 | |||
37 | #[derive(Deserialize)] | ||
38 | #[serde(rename_all = "camelCase")] | ||
39 | struct InitializationOptions { | ||
40 | publish_decorations: bool, | ||
41 | } | ||
42 | |||
32 | fn main_inner() -> Result<()> { | 43 | fn main_inner() -> Result<()> { |
33 | let (receiver, sender, threads) = stdio_transport(); | 44 | let (receiver, sender, threads) = stdio_transport(); |
34 | let cwd = ::std::env::current_dir()?; | 45 | let cwd = ::std::env::current_dir()?; |
@@ -41,7 +52,12 @@ fn main_inner() -> Result<()> { | |||
41 | .root_uri | 52 | .root_uri |
42 | .and_then(|it| it.to_file_path().ok()) | 53 | .and_then(|it| it.to_file_path().ok()) |
43 | .unwrap_or(cwd); | 54 | .unwrap_or(cwd); |
44 | ra_lsp_server::main_loop(false, root, r, s) | 55 | let publish_decorations = params |
56 | .initialization_options | ||
57 | .and_then(|v| InitializationOptions::deserialize(v).ok()) | ||
58 | .map(|it| it.publish_decorations) | ||
59 | == Some(true); | ||
60 | ra_lsp_server::main_loop(false, root, publish_decorations, r, s) | ||
45 | }, | 61 | }, |
46 | )?; | 62 | )?; |
47 | info!("shutting down IO..."); | 63 | info!("shutting down IO..."); |
@@ -52,14 +68,14 @@ fn main_inner() -> Result<()> { | |||
52 | 68 | ||
53 | /* | 69 | /* |
54 | (let ((backend (eglot-xref-backend))) | 70 | (let ((backend (eglot-xref-backend))) |
55 | (mapcar | 71 | (mapcar |
56 | (lambda (xref) | 72 | (lambda (xref) |
57 | (let ((loc (xref-item-location xref))) | 73 | (let ((loc (xref-item-location xref))) |
58 | (propertize | 74 | (propertize |
59 | (concat | 75 | (concat |
60 | (when (xref-file-location-p loc) | 76 | (when (xref-file-location-p loc) |
61 | (with-slots (file line column) loc | 77 | (with-slots (file line column) loc |
62 | (format "%s:%s:%s:" | 78 | (format "%s:%s:%s:" |
63 | (propertize (file-relative-name file) | 79 | (propertize (file-relative-name file) |
64 | 'face 'compilation-info) | 80 | 'face 'compilation-info) |
65 | (propertize (format "%s" line) | 81 | (propertize (format "%s" line) |
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index db878e0aa..78d93741a 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs | |||
@@ -48,6 +48,7 @@ enum Task { | |||
48 | pub fn main_loop( | 48 | pub fn main_loop( |
49 | internal_mode: bool, | 49 | internal_mode: bool, |
50 | root: PathBuf, | 50 | root: PathBuf, |
51 | publish_decorations: bool, | ||
51 | msg_receiver: &Receiver<RawMessage>, | 52 | msg_receiver: &Receiver<RawMessage>, |
52 | msg_sender: &Sender<RawMessage>, | 53 | msg_sender: &Sender<RawMessage>, |
53 | ) -> Result<()> { | 54 | ) -> Result<()> { |
@@ -67,6 +68,7 @@ pub fn main_loop( | |||
67 | let mut subs = Subscriptions::new(); | 68 | let mut subs = Subscriptions::new(); |
68 | let main_res = main_loop_inner( | 69 | let main_res = main_loop_inner( |
69 | internal_mode, | 70 | internal_mode, |
71 | publish_decorations, | ||
70 | root, | 72 | root, |
71 | &pool, | 73 | &pool, |
72 | msg_sender, | 74 | msg_sender, |
@@ -99,6 +101,7 @@ pub fn main_loop( | |||
99 | 101 | ||
100 | fn main_loop_inner( | 102 | fn main_loop_inner( |
101 | internal_mode: bool, | 103 | internal_mode: bool, |
104 | publish_decorations: bool, | ||
102 | ws_root: PathBuf, | 105 | ws_root: PathBuf, |
103 | pool: &ThreadPool, | 106 | pool: &ThreadPool, |
104 | msg_sender: &Sender<RawMessage>, | 107 | msg_sender: &Sender<RawMessage>, |
@@ -210,6 +213,7 @@ fn main_loop_inner( | |||
210 | update_file_notifications_on_threadpool( | 213 | update_file_notifications_on_threadpool( |
211 | pool, | 214 | pool, |
212 | state.snapshot(), | 215 | state.snapshot(), |
216 | publish_decorations, | ||
213 | task_sender.clone(), | 217 | task_sender.clone(), |
214 | subs.subscriptions(), | 218 | subs.subscriptions(), |
215 | ) | 219 | ) |
@@ -416,6 +420,7 @@ impl<'a> PoolDispatcher<'a> { | |||
416 | fn update_file_notifications_on_threadpool( | 420 | fn update_file_notifications_on_threadpool( |
417 | pool: &ThreadPool, | 421 | pool: &ThreadPool, |
418 | world: ServerWorld, | 422 | world: ServerWorld, |
423 | publish_decorations: bool, | ||
419 | sender: Sender<Task>, | 424 | sender: Sender<Task>, |
420 | subscriptions: Vec<FileId>, | 425 | subscriptions: Vec<FileId>, |
421 | ) { | 426 | ) { |
@@ -432,15 +437,17 @@ fn update_file_notifications_on_threadpool( | |||
432 | sender.send(Task::Notify(not)); | 437 | sender.send(Task::Notify(not)); |
433 | } | 438 | } |
434 | } | 439 | } |
435 | match handlers::publish_decorations(&world, file_id) { | 440 | if publish_decorations { |
436 | Err(e) => { | 441 | match handlers::publish_decorations(&world, file_id) { |
437 | if !is_canceled(&e) { | 442 | Err(e) => { |
438 | error!("failed to compute decorations: {:?}", e); | 443 | if !is_canceled(&e) { |
444 | error!("failed to compute decorations: {:?}", e); | ||
445 | } | ||
446 | } | ||
447 | Ok(params) => { | ||
448 | let not = RawNotification::new::<req::PublishDecorations>(¶ms); | ||
449 | sender.send(Task::Notify(not)) | ||
439 | } | 450 | } |
440 | } | ||
441 | Ok(params) => { | ||
442 | let not = RawNotification::new::<req::PublishDecorations>(¶ms); | ||
443 | sender.send(Task::Notify(not)) | ||
444 | } | 451 | } |
445 | } | 452 | } |
446 | } | 453 | } |
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts index a7a22fa6f..75e273f37 100644 --- a/editors/code/src/server.ts +++ b/editors/code/src/server.ts | |||
@@ -20,7 +20,10 @@ export class Server { | |||
20 | debug: run | 20 | debug: run |
21 | }; | 21 | }; |
22 | const clientOptions: lc.LanguageClientOptions = { | 22 | const clientOptions: lc.LanguageClientOptions = { |
23 | documentSelector: [{ scheme: 'file', language: 'rust' }] | 23 | documentSelector: [{ scheme: 'file', language: 'rust' }], |
24 | initializationOptions: { | ||
25 | publishDecorations: true, | ||
26 | } | ||
24 | }; | 27 | }; |
25 | 28 | ||
26 | Server.client = new lc.LanguageClient( | 29 | Server.client = new lc.LanguageClient( |
diff --git a/editors/emacs/ra.el b/editors/emacs/ra.el index a0b17f3af..fb73451c1 100644 --- a/editors/emacs/ra.el +++ b/editors/emacs/ra.el | |||
@@ -119,5 +119,10 @@ | |||
119 | (xref--pop-to-location (get-text-property 0 'xref item)))))) | 119 | (xref--pop-to-location (get-text-property 0 'xref item)))))) |
120 | 120 | ||
121 | (add-to-list 'eglot-server-programs '(rust-mode . ("ra_lsp_server"))) | 121 | (add-to-list 'eglot-server-programs '(rust-mode . ("ra_lsp_server"))) |
122 | |||
123 | ; (require 'rust-mode) | ||
124 | ; (define-key rust-mode-map (kbd "C-n") 'workspace-symbols) | ||
125 | |||
126 | (define-key) | ||
122 | (provide 'ra) | 127 | (provide 'ra) |
123 | ;;; ra.el ends here | 128 | ;;; ra.el ends here |