Skip to content

Commit

Permalink
language server code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
micahscopes committed Feb 29, 2024
1 parent 41e206a commit f3dc655
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 37 deletions.
11 changes: 1 addition & 10 deletions crates/language-server/src/backend.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::Arc;
use std::sync::{Mutex, MutexGuard};
// use tokio::sync::{Mutex, MutexGuard};
use std::sync::Mutex;

use crate::db::LanguageServerDatabase;

Expand All @@ -18,14 +17,6 @@ pub struct Backend {
}

impl Backend {
// pub(crate) fn db(&self) -> MutexGuard<LanguageServerDatabase> {
// self.db.lock().unwrap()
// }

// pub(crate) fn workspace(&self) -> MutexGuard<Workspace> {
// self.workspace.lock().unwrap()
// }

pub fn new(client: Client) -> Self {
let db = Arc::new(Mutex::new(LanguageServerDatabase::default()));
let workspace = Arc::new(Mutex::new(Workspace::default()));
Expand Down
14 changes: 6 additions & 8 deletions crates/language-server/src/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use lsp_types::{
TextDocumentItem,
};

use tokio::sync::MutexGuard;
use tower_lsp::{jsonrpc::Result, Client, LanguageServer};
use tower_lsp::{jsonrpc::Result, LanguageServer};

use crate::{
backend::Backend,
Expand Down Expand Up @@ -188,12 +187,11 @@ async fn on_change(backend: &Backend, params: TextDocumentItem) {
};

let client = backend.client.lock().await;
let diagnostics =
diagnostics
.unwrap()
.into_iter()
.map(|(uri, diags)| client.publish_diagnostics(uri, diags, None))
.collect::<Vec<_>>();
let diagnostics = diagnostics
.unwrap()
.into_iter()
.map(|(uri, diags)| client.publish_diagnostics(uri, diags, None))
.collect::<Vec<_>>();

futures::future::join_all(diagnostics).await;
}
18 changes: 1 addition & 17 deletions crates/language-server/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl log::Log for Logger {
let level = record.level();
let client = self.client.clone();
tokio::spawn(async move {
let mut client = client.lock().await;
let client = client.lock().await;
client
.log_message(
match level {
Expand All @@ -37,22 +37,6 @@ impl log::Log for Logger {
)
.await;
});
// let client = self.client.clone();
// tokio::task::spawn_blocking(async move {
// let client = client.lock().await;
// client
// .log_message(
// match level {
// log::Level::Error => lsp_types::MessageType::ERROR,
// log::Level::Warn => lsp_types::MessageType::WARNING,
// log::Level::Info => lsp_types::MessageType::INFO,
// log::Level::Debug => lsp_types::MessageType::LOG,
// log::Level::Trace => lsp_types::MessageType::LOG,
// },
// message,
// )
// .await;
// });
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/language-server/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ impl IngotFileContext for Workspace {
new_path: &str,
) -> Result<()> {
let ctx = get_containing_ingot(&mut self.ingot_contexts, old_path);
if ctx.is_some() {
ctx.unwrap().rename_file(db, old_path, new_path)
if let Some(ctx) = ctx {
ctx.rename_file(db, old_path, new_path)
} else {
self.standalone_ingot_context
.rename_file(db, old_path, new_path)
Expand Down

0 comments on commit f3dc655

Please sign in to comment.