workspace-symbols function for Emacs

This commit is contained in:
Aleksey Kladov 2018-11-08 18:43:02 +03:00
parent c69ff08dc9
commit 00e80b24e3
4 changed files with 43 additions and 12 deletions

View file

@ -2,10 +2,14 @@
extern crate log; extern crate log;
#[macro_use] #[macro_use]
extern crate failure; extern crate failure;
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate flexi_logger; extern crate flexi_logger;
extern crate gen_lsp_server; extern crate gen_lsp_server;
extern crate ra_lsp_server; extern crate ra_lsp_server;
use serde::Deserialize;
use flexi_logger::{Duplicate, Logger}; use flexi_logger::{Duplicate, Logger};
use gen_lsp_server::{run_server, stdio_transport}; use gen_lsp_server::{run_server, stdio_transport};
use ra_lsp_server::Result; 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<()> { fn main_inner() -> Result<()> {
let (receiver, sender, threads) = stdio_transport(); let (receiver, sender, threads) = stdio_transport();
let cwd = ::std::env::current_dir()?; let cwd = ::std::env::current_dir()?;
@ -41,7 +52,12 @@ fn main_inner() -> Result<()> {
.root_uri .root_uri
.and_then(|it| it.to_file_path().ok()) .and_then(|it| it.to_file_path().ok())
.unwrap_or(cwd); .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..."); info!("shutting down IO...");

View file

@ -48,6 +48,7 @@ enum Task {
pub fn main_loop( pub fn main_loop(
internal_mode: bool, internal_mode: bool,
root: PathBuf, root: PathBuf,
publish_decorations: bool,
msg_receiver: &Receiver<RawMessage>, msg_receiver: &Receiver<RawMessage>,
msg_sender: &Sender<RawMessage>, msg_sender: &Sender<RawMessage>,
) -> Result<()> { ) -> Result<()> {
@ -67,6 +68,7 @@ pub fn main_loop(
let mut subs = Subscriptions::new(); let mut subs = Subscriptions::new();
let main_res = main_loop_inner( let main_res = main_loop_inner(
internal_mode, internal_mode,
publish_decorations,
root, root,
&pool, &pool,
msg_sender, msg_sender,
@ -99,6 +101,7 @@ pub fn main_loop(
fn main_loop_inner( fn main_loop_inner(
internal_mode: bool, internal_mode: bool,
publish_decorations: bool,
ws_root: PathBuf, ws_root: PathBuf,
pool: &ThreadPool, pool: &ThreadPool,
msg_sender: &Sender<RawMessage>, msg_sender: &Sender<RawMessage>,
@ -210,6 +213,7 @@ fn main_loop_inner(
update_file_notifications_on_threadpool( update_file_notifications_on_threadpool(
pool, pool,
state.snapshot(), state.snapshot(),
publish_decorations,
task_sender.clone(), task_sender.clone(),
subs.subscriptions(), subs.subscriptions(),
) )
@ -416,6 +420,7 @@ impl<'a> PoolDispatcher<'a> {
fn update_file_notifications_on_threadpool( fn update_file_notifications_on_threadpool(
pool: &ThreadPool, pool: &ThreadPool,
world: ServerWorld, world: ServerWorld,
publish_decorations: bool,
sender: Sender<Task>, sender: Sender<Task>,
subscriptions: Vec<FileId>, subscriptions: Vec<FileId>,
) { ) {
@ -432,15 +437,17 @@ fn update_file_notifications_on_threadpool(
sender.send(Task::Notify(not)); sender.send(Task::Notify(not));
} }
} }
match handlers::publish_decorations(&world, file_id) { if publish_decorations {
Err(e) => { match handlers::publish_decorations(&world, file_id) {
if !is_canceled(&e) { Err(e) => {
error!("failed to compute decorations: {:?}", e); if !is_canceled(&e) {
error!("failed to compute decorations: {:?}", e);
}
}
Ok(params) => {
let not = RawNotification::new::<req::PublishDecorations>(&params);
sender.send(Task::Notify(not))
} }
}
Ok(params) => {
let not = RawNotification::new::<req::PublishDecorations>(&params);
sender.send(Task::Notify(not))
} }
} }
} }

View file

@ -20,7 +20,10 @@ export class Server {
debug: run debug: run
}; };
const clientOptions: lc.LanguageClientOptions = { const clientOptions: lc.LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'rust' }] documentSelector: [{ scheme: 'file', language: 'rust' }],
initializationOptions: {
publishDecorations: true,
}
}; };
Server.client = new lc.LanguageClient( Server.client = new lc.LanguageClient(

View file

@ -119,5 +119,10 @@
(xref--pop-to-location (get-text-property 0 'xref item)))))) (xref--pop-to-location (get-text-property 0 'xref item))))))
(add-to-list 'eglot-server-programs '(rust-mode . ("ra_lsp_server"))) (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) (provide 'ra)
;;; ra.el ends here ;;; ra.el ends here