From b5021411a84822cb3f1e3aeffad9550dd15bdeb6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 16 Sep 2018 12:54:24 +0300 Subject: rename all things --- crates/server/src/main_loop/handlers.rs | 436 --------------------------- crates/server/src/main_loop/mod.rs | 419 ------------------------- crates/server/src/main_loop/subscriptions.rs | 21 -- 3 files changed, 876 deletions(-) delete mode 100644 crates/server/src/main_loop/handlers.rs delete mode 100644 crates/server/src/main_loop/mod.rs delete mode 100644 crates/server/src/main_loop/subscriptions.rs (limited to 'crates/server/src/main_loop') diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs deleted file mode 100644 index 3e02227d5..000000000 --- a/crates/server/src/main_loop/handlers.rs +++ /dev/null @@ -1,436 +0,0 @@ -use std::collections::HashMap; - -use languageserver_types::{ - Diagnostic, DiagnosticSeverity, DocumentSymbol, - Command, TextDocumentIdentifier, - SymbolInformation, Position, Location, TextEdit, - CompletionItem, InsertTextFormat, CompletionItemKind, -}; -use serde_json::to_value; -use libanalysis::{Query, FileId, RunnableKind, JobToken}; -use libsyntax2::{ - text_utils::contains_offset_nonstrict, -}; - -use ::{ - req::{self, Decoration}, Result, - conv::{Conv, ConvWith, TryConvWith, MapConvWith, to_location}, - server_world::ServerWorld, - project_model::TargetKind, -}; - -pub fn handle_syntax_tree( - world: ServerWorld, - params: req::SyntaxTreeParams, - _token: JobToken, -) -> Result { - let id = params.text_document.try_conv_with(&world)?; - let res = world.analysis().syntax_tree(id); - Ok(res) -} - -pub fn handle_extend_selection( - world: ServerWorld, - params: req::ExtendSelectionParams, - _token: JobToken, -) -> Result { - let file_id = params.text_document.try_conv_with(&world)?; - let file = world.analysis().file_syntax(file_id); - let line_index = world.analysis().file_line_index(file_id); - let selections = params.selections.into_iter() - .map_conv_with(&line_index) - .map(|r| world.analysis().extend_selection(&file, r)) - .map_conv_with(&line_index) - .collect(); - Ok(req::ExtendSelectionResult { selections }) -} - -pub fn handle_find_matching_brace( - world: ServerWorld, - params: req::FindMatchingBraceParams, - _token: JobToken, -) -> Result> { - let file_id = params.text_document.try_conv_with(&world)?; - let file = world.analysis().file_syntax(file_id); - let line_index = world.analysis().file_line_index(file_id); - let res = params.offsets - .into_iter() - .map_conv_with(&line_index) - .map(|offset| { - world.analysis().matching_brace(&file, offset).unwrap_or(offset) - }) - .map_conv_with(&line_index) - .collect(); - Ok(res) -} - -pub fn handle_join_lines( - world: ServerWorld, - params: req::JoinLinesParams, - _token: JobToken, -) -> Result { - let file_id = params.text_document.try_conv_with(&world)?; - let line_index = world.analysis().file_line_index(file_id); - let range = params.range.conv_with(&line_index); - world.analysis().join_lines(file_id, range) - .try_conv_with(&world) -} - -pub fn handle_on_type_formatting( - world: ServerWorld, - params: req::DocumentOnTypeFormattingParams, - _token: JobToken, -) -> Result>> { - if params.ch != "=" { - return Ok(None); - } - - let file_id = params.text_document.try_conv_with(&world)?; - let line_index = world.analysis().file_line_index(file_id); - let offset = params.position.conv_with(&line_index); - let edits = match world.analysis().on_eq_typed(file_id, offset) { - None => return Ok(None), - Some(mut action) => action.source_file_edits.pop().unwrap().edits, - }; - let edits = edits.into_iter().map_conv_with(&line_index).collect(); - Ok(Some(edits)) -} - -pub fn handle_document_symbol( - world: ServerWorld, - params: req::DocumentSymbolParams, - _token: JobToken, -) -> Result> { - let file_id = params.text_document.try_conv_with(&world)?; - let line_index = world.analysis().file_line_index(file_id); - - let mut parents: Vec<(DocumentSymbol, Option)> = Vec::new(); - - for symbol in world.analysis().file_structure(file_id) { - let doc_symbol = DocumentSymbol { - name: symbol.label, - detail: Some("".to_string()), - kind: symbol.kind.conv(), - deprecated: None, - range: symbol.node_range.conv_with(&line_index), - selection_range: symbol.navigation_range.conv_with(&line_index), - children: None, - }; - parents.push((doc_symbol, symbol.parent)); - } - let mut res = Vec::new(); - while let Some((node, parent)) = parents.pop() { - match parent { - None => res.push(node), - Some(i) => { - let children = &mut parents[i].0.children; - if children.is_none() { - *children = Some(Vec::new()); - } - children.as_mut().unwrap().push(node); - } - } - } - - Ok(Some(req::DocumentSymbolResponse::Nested(res))) -} - -pub fn handle_workspace_symbol( - world: ServerWorld, - params: req::WorkspaceSymbolParams, - token: JobToken, -) -> Result>> { - let all_symbols = params.query.contains("#"); - let libs = params.query.contains("*"); - let query = { - let query: String = params.query.chars() - .filter(|&c| c != '#' && c != '*') - .collect(); - let mut q = Query::new(query); - if !all_symbols { - q.only_types(); - } - if libs { - q.libs(); - } - q.limit(128); - q - }; - let mut res = exec_query(&world, query, &token)?; - if res.is_empty() && !all_symbols { - let mut query = Query::new(params.query); - query.limit(128); - res = exec_query(&world, query, &token)?; - } - - return Ok(Some(res)); - - fn exec_query(world: &ServerWorld, query: Query, token: &JobToken) -> Result> { - let mut res = Vec::new(); - for (file_id, symbol) in world.analysis().symbol_search(query, token) { - let line_index = world.analysis().file_line_index(file_id); - let info = SymbolInformation { - name: symbol.name.to_string(), - kind: symbol.kind.conv(), - location: to_location( - file_id, symbol.node_range, - world, &line_index - )?, - container_name: None, - }; - res.push(info); - }; - Ok(res) - } -} - -pub fn handle_goto_definition( - world: ServerWorld, - params: req::TextDocumentPositionParams, - token: JobToken, -) -> Result> { - let file_id = params.text_document.try_conv_with(&world)?; - let line_index = world.analysis().file_line_index(file_id); - let offset = params.position.conv_with(&line_index); - let mut res = Vec::new(); - for (file_id, symbol) in world.analysis().approximately_resolve_symbol(file_id, offset, &token) { - let line_index = world.analysis().file_line_index(file_id); - let location = to_location( - file_id, symbol.node_range, - &world, &line_index, - )?; - res.push(location) - } - Ok(Some(req::GotoDefinitionResponse::Array(res))) -} - -pub fn handle_parent_module( - world: ServerWorld, - params: TextDocumentIdentifier, - _token: JobToken, -) -> Result> { - let file_id = params.try_conv_with(&world)?; - let mut res = Vec::new(); - for (file_id, symbol) in world.analysis().parent_module(file_id) { - let line_index = world.analysis().file_line_index(file_id); - let location = to_location( - file_id, symbol.node_range, - &world, &line_index - )?; - res.push(location); - } - Ok(res) -} - -pub fn handle_runnables( - world: ServerWorld, - params: req::RunnablesParams, - _token: JobToken, -) -> Result> { - let file_id = params.text_document.try_conv_with(&world)?; - let line_index = world.analysis().file_line_index(file_id); - let offset = params.position.map(|it| it.conv_with(&line_index)); - let mut res = Vec::new(); - for runnable in world.analysis().runnables(file_id) { - if let Some(offset) = offset { - if !contains_offset_nonstrict(runnable.range, offset) { - continue; - } - } - - let args = runnable_args(&world, file_id, &runnable.kind); - - let r = req::Runnable { - range: runnable.range.conv_with(&line_index), - label: match &runnable.kind { - RunnableKind::Test { name } => - format!("test {}", name), - RunnableKind::Bin => - "run binary".to_string(), - }, - bin: "cargo".to_string(), - args, - env: { - let mut m = HashMap::new(); - m.insert( - "RUST_BACKTRACE".to_string(), - "short".to_string(), - ); - m - } - }; - res.push(r); - } - return Ok(res); - - fn runnable_args(world: &ServerWorld, file_id: FileId, kind: &RunnableKind) -> Vec { - let spec = if let Some(&crate_id) = world.analysis().crate_for(file_id).first() { - let file_id = world.analysis().crate_root(crate_id); - let path = world.path_map.get_path(file_id); - world.workspaces.iter() - .filter_map(|ws| { - let tgt = ws.target_by_root(path)?; - Some((tgt.package(ws).name(ws).clone(), tgt.name(ws).clone(), tgt.kind(ws))) - }) - .next() - } else { - None - }; - let mut res = Vec::new(); - match kind { - RunnableKind::Test { name } => { - res.push("test".to_string()); - if let Some((pkg_name, tgt_name, tgt_kind)) = spec { - spec_args(pkg_name, tgt_name, tgt_kind, &mut res); - } - res.push("--".to_string()); - res.push(name.to_string()); - res.push("--nocapture".to_string()); - } - RunnableKind::Bin => { - res.push("run".to_string()); - if let Some((pkg_name, tgt_name, tgt_kind)) = spec { - spec_args(pkg_name, tgt_name, tgt_kind, &mut res); - } - } - } - res - } - - fn spec_args(pkg_name: &str, tgt_name: &str, tgt_kind: TargetKind, buf: &mut Vec) { - buf.push("--package".to_string()); - buf.push(pkg_name.to_string()); - match tgt_kind { - TargetKind::Bin => { - buf.push("--bin".to_string()); - buf.push(tgt_name.to_string()); - } - TargetKind::Test => { - buf.push("--test".to_string()); - buf.push(tgt_name.to_string()); - } - TargetKind::Bench => { - buf.push("--bench".to_string()); - buf.push(tgt_name.to_string()); - } - TargetKind::Example => { - buf.push("--example".to_string()); - buf.push(tgt_name.to_string()); - } - TargetKind::Lib => { - buf.push("--lib".to_string()); - } - TargetKind::Other => (), - } - } -} - -pub fn handle_decorations( - world: ServerWorld, - params: TextDocumentIdentifier, - _token: JobToken, -) -> Result> { - let file_id = params.try_conv_with(&world)?; - Ok(highlight(&world, file_id)) -} - -pub fn handle_completion( - world: ServerWorld, - params: req::CompletionParams, - _token: JobToken, -) -> Result> { - let file_id = params.text_document.try_conv_with(&world)?; - let line_index = world.analysis().file_line_index(file_id); - let offset = params.position.conv_with(&line_index); - let items = match world.analysis().completions(file_id, offset) { - None => return Ok(None), - Some(items) => items, - }; - let items = items.into_iter() - .map(|item| { - let mut res = CompletionItem { - label: item.label, - filter_text: item.lookup, - .. Default::default() - }; - if let Some(snip) = item.snippet { - res.insert_text = Some(snip); - res.insert_text_format = Some(InsertTextFormat::Snippet); - res.kind = Some(CompletionItemKind::Keyword); - }; - res - }) - .collect(); - - Ok(Some(req::CompletionResponse::Array(items))) -} - -pub fn handle_code_action( - world: ServerWorld, - params: req::CodeActionParams, - _token: JobToken, -) -> Result>> { - let file_id = params.text_document.try_conv_with(&world)?; - let line_index = world.analysis().file_line_index(file_id); - let range = params.range.conv_with(&line_index); - - let assists = world.analysis().assists(file_id, range).into_iter(); - let fixes = world.analysis().diagnostics(file_id).into_iter() - .filter_map(|d| Some((d.range, d.fix?))) - .filter(|(range, _fix)| contains_offset_nonstrict(*range, range.start())) - .map(|(_range, fix)| fix); - - let mut res = Vec::new(); - for source_edit in assists.chain(fixes) { - let title = source_edit.label.clone(); - let edit = source_edit.try_conv_with(&world)?; - let cmd = Command { - title, - command: "libsyntax-rust.applySourceChange".to_string(), - arguments: Some(vec![to_value(edit).unwrap()]), - }; - res.push(cmd); - } - - Ok(Some(res)) -} - -pub fn publish_diagnostics( - world: ServerWorld, - file_id: FileId, -) -> Result { - let uri = world.file_id_to_uri(file_id)?; - let line_index = world.analysis().file_line_index(file_id); - let diagnostics = world.analysis().diagnostics(file_id) - .into_iter() - .map(|d| Diagnostic { - range: d.range.conv_with(&line_index), - severity: Some(DiagnosticSeverity::Error), - code: None, - source: Some("libsyntax2".to_string()), - message: d.message, - related_information: None, - }).collect(); - Ok(req::PublishDiagnosticsParams { uri, diagnostics }) -} - -pub fn publish_decorations( - world: ServerWorld, - file_id: FileId, -) -> Result { - let uri = world.file_id_to_uri(file_id)?; - Ok(req::PublishDecorationsParams { - uri, - decorations: highlight(&world, file_id), - }) -} - -fn highlight(world: &ServerWorld, file_id: FileId) -> Vec { - let line_index = world.analysis().file_line_index(file_id); - world.analysis().highlight(file_id) - .into_iter() - .map(|h| Decoration { - range: h.range.conv_with(&line_index), - tag: h.tag, - }).collect() -} diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs deleted file mode 100644 index f3b2744bf..000000000 --- a/crates/server/src/main_loop/mod.rs +++ /dev/null @@ -1,419 +0,0 @@ -mod handlers; -mod subscriptions; - -use std::{ - path::PathBuf, - collections::{HashMap}, -}; - -use serde::{Serialize, de::DeserializeOwned}; -use crossbeam_channel::{unbounded, Sender, Receiver}; -use rayon::{self, ThreadPool}; -use languageserver_types::{NumberOrString}; -use libanalysis::{FileId, JobHandle, JobToken, LibraryData}; -use gen_lsp_server::{ - RawRequest, RawNotification, RawMessage, RawResponse, ErrorCode, - handle_shutdown, -}; - -use { - req, - Result, - vfs::{self, FileEvent}, - server_world::{ServerWorldState, ServerWorld}, - main_loop::subscriptions::{Subscriptions}, - project_model::{CargoWorkspace, workspace_loader}, - thread_watcher::Worker, -}; - -#[derive(Debug)] -enum Task { - Respond(RawResponse), - Notify(RawNotification), -} - -pub fn main_loop( - internal_mode: bool, - root: PathBuf, - msg_receriver: &mut Receiver, - msg_sender: &mut Sender, -) -> Result<()> { - let pool = rayon::ThreadPoolBuilder::new() - .num_threads(4) - .panic_handler(|_| error!("thread panicked :(")) - .build() - .unwrap(); - let (task_sender, task_receiver) = unbounded::(); - let (fs_worker, fs_watcher) = vfs::roots_loader(); - let (ws_worker, ws_watcher) = workspace_loader(); - - info!("server initialized, serving requests"); - let mut state = ServerWorldState::new(); - - let mut pending_requests = HashMap::new(); - let mut subs = Subscriptions::new(); - let main_res = main_loop_inner( - internal_mode, - root, - &pool, - msg_sender, - msg_receriver, - task_sender, - task_receiver.clone(), - fs_worker, - ws_worker, - &mut state, - &mut pending_requests, - &mut subs, - ); - - info!("waiting for tasks to finish..."); - task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests)); - info!("...tasks have finished"); - info!("joining threadpool..."); - drop(pool); - info!("...threadpool has finished"); - - let fs_res = fs_watcher.stop(); - let ws_res = ws_watcher.stop(); - - main_res?; - fs_res?; - ws_res?; - - Ok(()) -} - -fn main_loop_inner( - internal_mode: bool, - ws_root: PathBuf, - pool: &ThreadPool, - msg_sender: &mut Sender, - msg_receiver: &mut Receiver, - task_sender: Sender, - task_receiver: Receiver, - fs_worker: Worker)>, - ws_worker: Worker>, - state: &mut ServerWorldState, - pending_requests: &mut HashMap, - subs: &mut Subscriptions, -) -> Result<()> { - let (libdata_sender, libdata_receiver) = unbounded(); - ws_worker.send(ws_root.clone()); - fs_worker.send(ws_root.clone()); - loop { - #[derive(Debug)] - enum Event { - Msg(RawMessage), - Task(Task), - Fs(PathBuf, Vec), - Ws(Result), - Lib(LibraryData), - } - trace!("selecting"); - let event = select! { - recv(msg_receiver, msg) => match msg { - Some(msg) => Event::Msg(msg), - None => bail!("client exited without shutdown"), - }, - recv(task_receiver, task) => Event::Task(task.unwrap()), - recv(fs_worker.out, events) => match events { - None => bail!("roots watcher died"), - Some((pb, events)) => Event::Fs(pb, events), - } - recv(ws_worker.out, ws) => match ws { - None => bail!("workspace watcher died"), - Some(ws) => Event::Ws(ws), - } - recv(libdata_receiver, data) => Event::Lib(data.unwrap()) - }; - let mut state_changed = false; - match event { - Event::Task(task) => on_task(task, msg_sender, pending_requests), - Event::Fs(root, events) => { - info!("fs change, {}, {} events", root.display(), events.len()); - if root == ws_root { - state.apply_fs_changes(events); - } else { - let (files, resolver) = state.events_to_files(events); - let sender = libdata_sender.clone(); - pool.spawn(move || { - let start = ::std::time::Instant::now(); - info!("indexing {} ... ", root.display()); - let data = LibraryData::prepare(files, resolver); - info!("indexed {:?} {}", start.elapsed(), root.display()); - sender.send(data); - }); - } - state_changed = true; - } - Event::Ws(ws) => { - match ws { - Ok(ws) => { - let workspaces = vec![ws]; - feedback(internal_mode, "workspace loaded", msg_sender); - for ws in workspaces.iter() { - for pkg in ws.packages().filter(|pkg| !pkg.is_member(ws)) { - debug!("sending root, {}", pkg.root(ws).to_path_buf().display()); - fs_worker.send(pkg.root(ws).to_path_buf()); - } - } - state.set_workspaces(workspaces); - state_changed = true; - } - Err(e) => warn!("loading workspace failed: {}", e), - } - } - Event::Lib(lib) => { - feedback(internal_mode, "library loaded", msg_sender); - state.add_lib(lib); - } - Event::Msg(msg) => { - match msg { - RawMessage::Request(req) => { - let req = match handle_shutdown(req, msg_sender) { - Some(req) => req, - None => return Ok(()), - }; - match on_request(state, pending_requests, pool, &task_sender, req)? { - None => (), - Some(req) => { - error!("unknown request: {:?}", req); - let resp = RawResponse::err( - req.id, - ErrorCode::MethodNotFound as i32, - "unknown request".to_string(), - ); - msg_sender.send(RawMessage::Response(resp)) - } - } - } - RawMessage::Notification(not) => { - on_notification(msg_sender, state, pending_requests, subs, not)?; - state_changed = true; - } - RawMessage::Response(resp) => { - error!("unexpected response: {:?}", resp) - } - } - } - }; - - if state_changed { - update_file_notifications_on_threadpool( - pool, - state.snapshot(), - task_sender.clone(), - subs.subscriptions(), - ) - } - } -} - -fn on_task( - task: Task, - msg_sender: &mut Sender, - pending_requests: &mut HashMap, -) { - match task { - Task::Respond(response) => { - if let Some(handle) = pending_requests.remove(&response.id) { - assert!(handle.has_completed()); - } - msg_sender.send(RawMessage::Response(response)) - } - Task::Notify(n) => - msg_sender.send(RawMessage::Notification(n)), - } -} - -fn on_request( - world: &mut ServerWorldState, - pending_requests: &mut HashMap, - pool: &ThreadPool, - sender: &Sender, - req: RawRequest, -) -> Result> { - let mut pool_dispatcher = PoolDispatcher { - req: Some(req), - res: None, - pool, world, sender - }; - let req = pool_dispatcher - .on::(handlers::handle_syntax_tree)? - .on::(handlers::handle_extend_selection)? - .on::(handlers::handle_find_matching_brace)? - .on::(handlers::handle_join_lines)? - .on::(handlers::handle_on_type_formatting)? - .on::(handlers::handle_document_symbol)? - .on::(handlers::handle_workspace_symbol)? - .on::(handlers::handle_goto_definition)? - .on::(handlers::handle_parent_module)? - .on::(handlers::handle_runnables)? - .on::(handlers::handle_decorations)? - .on::(handlers::handle_completion)? - .on::(handlers::handle_code_action)? - .finish(); - match req { - Ok((id, handle)) => { - let inserted = pending_requests.insert(id, handle).is_none(); - assert!(inserted, "duplicate request: {}", id); - Ok(None) - }, - Err(req) => Ok(Some(req)), - } -} - -fn on_notification( - msg_sender: &mut Sender, - state: &mut ServerWorldState, - pending_requests: &mut HashMap, - subs: &mut Subscriptions, - not: RawNotification, -) -> Result<()> { - let not = match not.cast::() { - Ok(params) => { - let id = match params.id { - NumberOrString::Number(id) => id, - NumberOrString::String(id) => { - panic!("string id's not supported: {:?}", id); - } - }; - if let Some(handle) = pending_requests.remove(&id) { - handle.cancel(); - } - return Ok(()) - } - Err(not) => not, - }; - let not = match not.cast::() { - Ok(params) => { - let uri = params.text_document.uri; - let path = uri.to_file_path() - .map_err(|()| format_err!("invalid uri: {}", uri))?; - let file_id = state.add_mem_file(path, params.text_document.text); - subs.add_sub(file_id); - return Ok(()) - } - Err(not) => not, - }; - let not = match not.cast::() { - Ok(mut params) => { - let uri = params.text_document.uri; - let path = uri.to_file_path() - .map_err(|()| format_err!("invalid uri: {}", uri))?; - let text = params.content_changes.pop() - .ok_or_else(|| format_err!("empty changes"))? - .text; - state.change_mem_file(path.as_path(), text)?; - return Ok(()) - } - Err(not) => not, - }; - let not = match not.cast::() { - Ok(params) => { - let uri = params.text_document.uri; - let path = uri.to_file_path() - .map_err(|()| format_err!("invalid uri: {}", uri))?; - let file_id = state.remove_mem_file(path.as_path())?; - subs.remove_sub(file_id); - let params = req::PublishDiagnosticsParams { uri, diagnostics: Vec::new() }; - let not = RawNotification::new::(¶ms); - msg_sender.send(RawMessage::Notification(not)); - return Ok(()) - } - Err(not) => not, - }; - error!("unhandled notification: {:?}", not); - Ok(()) -} - -struct PoolDispatcher<'a> { - req: Option, - res: Option<(u64, JobHandle)>, - pool: &'a ThreadPool, - world: &'a ServerWorldState, - sender: &'a Sender, -} - -impl<'a> PoolDispatcher<'a> { - fn on<'b, R>( - &'b mut self, - f: fn(ServerWorld, R::Params, JobToken) -> Result - ) -> Result<&'b mut Self> - where R: req::Request, - R::Params: DeserializeOwned + Send + 'static, - R::Result: Serialize + 'static, - { - let req = match self.req.take() { - None => return Ok(self), - Some(req) => req, - }; - match req.cast::() { - Ok((id, params)) => { - let (handle, token) = JobHandle::new(); - let world = self.world.snapshot(); - let sender = self.sender.clone(); - self.pool.spawn(move || { - let resp = match f(world, params, token) { - Ok(resp) => RawResponse::ok::(id, &resp), - Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()), - }; - let task = Task::Respond(resp); - sender.send(task); - }); - self.res = Some((id, handle)); - } - Err(req) => { - self.req = Some(req) - } - } - Ok(self) - } - - fn finish(&mut self) -> ::std::result::Result<(u64, JobHandle), RawRequest> { - match (self.res.take(), self.req.take()) { - (Some(res), None) => Ok(res), - (None, Some(req)) => Err(req), - _ => unreachable!(), - } - } -} - -fn update_file_notifications_on_threadpool( - pool: &ThreadPool, - world: ServerWorld, - sender: Sender, - subscriptions: Vec, -) { - pool.spawn(move || { - for file_id in subscriptions { - match handlers::publish_diagnostics(world.clone(), file_id) { - Err(e) => { - error!("failed to compute diagnostics: {:?}", e) - } - Ok(params) => { - let not = RawNotification::new::(¶ms); - sender.send(Task::Notify(not)); - } - } - match handlers::publish_decorations(world.clone(), file_id) { - Err(e) => { - error!("failed to compute decorations: {:?}", e) - } - Ok(params) => { - let not = RawNotification::new::(¶ms); - sender.send(Task::Notify(not)) - } - } - } - }); -} - -fn feedback(intrnal_mode: bool, msg: &str, sender: &Sender) { - if !intrnal_mode { - return; - } - let not = RawNotification::new::(&msg.to_string()); - sender.send(RawMessage::Notification(not)); -} diff --git a/crates/server/src/main_loop/subscriptions.rs b/crates/server/src/main_loop/subscriptions.rs deleted file mode 100644 index 963096aef..000000000 --- a/crates/server/src/main_loop/subscriptions.rs +++ /dev/null @@ -1,21 +0,0 @@ -use std::collections::HashSet; -use libanalysis::FileId; - -pub struct Subscriptions { - subs: HashSet, -} - -impl Subscriptions { - pub fn new() -> Subscriptions { - Subscriptions { subs: HashSet::new() } - } - pub fn add_sub(&mut self, file_id: FileId) { - self.subs.insert(file_id); - } - pub fn remove_sub(&mut self, file_id: FileId) { - self.subs.remove(&file_id); - } - pub fn subscriptions(&self) -> Vec { - self.subs.iter().cloned().collect() - } -} -- cgit v1.2.3