Skip to content

Commit

Permalink
Remove 'Arc' wrapper, and Decouple 'session' and 'client'. (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
InsertCreativityHere authored Jan 15, 2024
1 parent bc18be1 commit 1ce3bf2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use hover::try_into_hover_result;
use jump_definition::get_definition_span;
use std::collections::HashMap;
use std::path::Path;
use std::sync::Arc;
use tower_lsp::{jsonrpc::Error, lsp_types::*, Client, LanguageServer, LspService, Server};
use utils::{convert_slice_url_to_uri, url_to_file_path, FindFile};

use crate::session::Session;

mod configuration_set;
mod diagnostic_ext;
mod hover;
Expand All @@ -28,12 +29,12 @@ async fn main() {

struct Backend {
client: Client,
session: Arc<crate::session::Session>,
session: Session,
}

impl Backend {
pub fn new(client: tower_lsp::Client) -> Self {
let session = Arc::new(crate::session::Session::new(client.clone()));
let session = Session::new();
Self { client, session }
}

Expand Down Expand Up @@ -88,7 +89,7 @@ impl LanguageServer for Backend {
async fn initialized(&self, _: InitializedParams) {
// Update the configuration sets by fetching the configurations from the client. This is performed after
// initialization because the client may not be ready to provide configurations before initialization.
self.session.fetch_configurations().await;
self.session.fetch_configurations(&self.client).await;

// Publish the diagnostics for all files
publish_diagnostics(&self.client, &self.session.configuration_sets).await;
Expand Down
14 changes: 7 additions & 7 deletions server/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

use crate::configuration_set::ConfigurationSet;
use tokio::sync::{Mutex, RwLock};
use tower_lsp::lsp_types::{ConfigurationItem, DidChangeConfigurationParams, Url};
use tower_lsp::{
lsp_types::{ConfigurationItem, DidChangeConfigurationParams, Url},
Client,
};

pub struct Session {
client: tower_lsp::Client,
/// This vector contains all of the configuration sets for the language server. Each element is a tuple containing
/// `SliceConfig` and `CompilationState`. The `SliceConfig` is used to determine which configuration set to use when
/// publishing diagnostics. The `CompilationState` is used to retrieve the diagnostics for a given file.
Expand All @@ -17,9 +19,8 @@ pub struct Session {
}

impl Session {
pub fn new(client: tower_lsp::Client) -> Self {
pub fn new() -> Self {
Self {
client,
configuration_sets: Mutex::new(Vec::new()),
root_uri: RwLock::new(None),
built_in_slice_path: RwLock::new(String::new()),
Expand Down Expand Up @@ -52,7 +53,7 @@ impl Session {
}

// Update the stored configuration sets by fetching them from the client.
pub async fn fetch_configurations(&self) {
pub async fn fetch_configurations(&self, client: &Client) {
let built_in_path = &self.built_in_slice_path.read().await;
let root_uri_guard = self.root_uri.read().await;
let root_uri = (*root_uri_guard).clone().expect("root_uri not set");
Expand All @@ -63,8 +64,7 @@ impl Session {
}];

// Fetch the configurations from the client and parse them.
let configurations = self
.client
let configurations = client
.configuration(params)
.await
.ok()
Expand Down

0 comments on commit 1ce3bf2

Please sign in to comment.