mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
workspace-symbols function for Emacs
This commit is contained in:
parent
c69ff08dc9
commit
00e80b24e3
4 changed files with 43 additions and 12 deletions
|
@ -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)
|
||||
|
|
|
@ -48,6 +48,7 @@ enum Task {
|
|||
pub fn main_loop(
|
||||
internal_mode: bool,
|
||||
root: PathBuf,
|
||||
publish_decorations: bool,
|
||||
msg_receiver: &Receiver<RawMessage>,
|
||||
msg_sender: &Sender<RawMessage>,
|
||||
) -> 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<RawMessage>,
|
||||
|
@ -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<Task>,
|
||||
subscriptions: Vec<FileId>,
|
||||
) {
|
||||
|
@ -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::<req::PublishDecorations>(¶ms);
|
||||
sender.send(Task::Notify(not))
|
||||
}
|
||||
}
|
||||
Ok(params) => {
|
||||
let not = RawNotification::new::<req::PublishDecorations>(¶ms);
|
||||
sender.send(Task::Notify(not))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue