From 00e80b24e3a46b3c4a6411151132fccc539abd5f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 8 Nov 2018 18:43:02 +0300 Subject: workspace-symbols function for Emacs --- crates/ra_lsp_server/src/main.rs | 22 +++++++++++++++++++--- crates/ra_lsp_server/src/main_loop/mod.rs | 23 +++++++++++++++-------- editors/code/src/server.ts | 5 ++++- 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 @@ extern crate log; #[macro_use] extern crate failure; +#[macro_use] +extern crate serde_derive; +extern crate serde; extern crate flexi_logger; extern crate gen_lsp_server; extern crate ra_lsp_server; +use serde::Deserialize; use flexi_logger::{Duplicate, Logger}; use gen_lsp_server::{run_server, stdio_transport}; use ra_lsp_server::Result; @@ -29,6 +33,13 @@ fn main() -> Result<()> { } } } + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +struct InitializationOptions { + publish_decorations: bool, +} + fn main_inner() -> Result<()> { let (receiver, sender, threads) = stdio_transport(); let cwd = ::std::env::current_dir()?; @@ -41,7 +52,12 @@ fn main_inner() -> Result<()> { .root_uri .and_then(|it| it.to_file_path().ok()) .unwrap_or(cwd); - ra_lsp_server::main_loop(false, root, r, s) + let publish_decorations = params + .initialization_options + .and_then(|v| InitializationOptions::deserialize(v).ok()) + .map(|it| it.publish_decorations) + == Some(true); + ra_lsp_server::main_loop(false, root, publish_decorations, r, s) }, )?; info!("shutting down IO..."); @@ -52,14 +68,14 @@ fn main_inner() -> Result<()> { /* (let ((backend (eglot-xref-backend))) - (mapcar + (mapcar (lambda (xref) (let ((loc (xref-item-location xref))) (propertize (concat (when (xref-file-location-p loc) (with-slots (file line column) loc - (format "%s:%s:%s:" + (format "%s:%s:%s:" (propertize (file-relative-name file) 'face 'compilation-info) (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 { pub fn main_loop( internal_mode: bool, root: PathBuf, + publish_decorations: bool, msg_receiver: &Receiver, msg_sender: &Sender, ) -> Result<()> { @@ -67,6 +68,7 @@ pub fn main_loop( let mut subs = Subscriptions::new(); let main_res = main_loop_inner( internal_mode, + publish_decorations, root, &pool, msg_sender, @@ -99,6 +101,7 @@ pub fn main_loop( fn main_loop_inner( internal_mode: bool, + publish_decorations: bool, ws_root: PathBuf, pool: &ThreadPool, msg_sender: &Sender, @@ -210,6 +213,7 @@ fn main_loop_inner( update_file_notifications_on_threadpool( pool, state.snapshot(), + publish_decorations, task_sender.clone(), subs.subscriptions(), ) @@ -416,6 +420,7 @@ impl<'a> PoolDispatcher<'a> { fn update_file_notifications_on_threadpool( pool: &ThreadPool, world: ServerWorld, + publish_decorations: bool, sender: Sender, subscriptions: Vec, ) { @@ -432,15 +437,17 @@ fn update_file_notifications_on_threadpool( sender.send(Task::Notify(not)); } } - match handlers::publish_decorations(&world, file_id) { - Err(e) => { - if !is_canceled(&e) { - error!("failed to compute decorations: {:?}", e); + if publish_decorations { + match handlers::publish_decorations(&world, file_id) { + Err(e) => { + if !is_canceled(&e) { + error!("failed to compute decorations: {:?}", e); + } + } + Ok(params) => { + let not = RawNotification::new::(¶ms); + sender.send(Task::Notify(not)) } - } - Ok(params) => { - let not = RawNotification::new::(¶ms); - sender.send(Task::Notify(not)) } } } 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 { debug: run }; const clientOptions: lc.LanguageClientOptions = { - documentSelector: [{ scheme: 'file', language: 'rust' }] + documentSelector: [{ scheme: 'file', language: 'rust' }], + initializationOptions: { + publishDecorations: true, + } }; 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 @@ (xref--pop-to-location (get-text-property 0 'xref item)))))) (add-to-list 'eglot-server-programs '(rust-mode . ("ra_lsp_server"))) + +; (require 'rust-mode) +; (define-key rust-mode-map (kbd "C-n") 'workspace-symbols) + +(define-key) (provide 'ra) ;;; ra.el ends here -- cgit v1.2.3