Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming some Files #61

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion server/src/configuration_set.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) ZeroC, Inc.

use crate::slice_config::{compute_slice_options, ServerConfig, SliceConfig};
use crate::configuration::{compute_slice_options, ServerConfig, SliceConfig};
use crate::utils::sanitize_path;
use std::collections::HashMap;
use std::path::PathBuf;
Expand Down
File renamed without changes.
46 changes: 23 additions & 23 deletions server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// Copyright (c) ZeroC, Inc.

use crate::diagnostic_ext::{clear_diagnostics, process_diagnostics, publish_diagnostics_for_set};
use crate::diagnostic_handler::{clear_diagnostics, process_diagnostics, publish_diagnostics_for_set};
use crate::hover::get_hover_message;
use crate::jump_definition::get_definition_span;
use crate::notifications::{ShowNotification, ShowNotificationParams};
use crate::session::Session;
use crate::slice_config::compute_slice_options;
use crate::server_state::ServerState;
use crate::configuration::compute_slice_options;
use std::ops::DerefMut;
use std::{collections::HashMap, path::Path};
use tokio::sync::Mutex;
use tower_lsp::{jsonrpc::Error, lsp_types::*, Client, LanguageServer, LspService, Server};
use utils::{convert_slice_path_to_uri, span_to_range, url_to_sanitized_file_path};

mod configuration;
mod configuration_set;
mod diagnostic_ext;
mod diagnostic_handler;
mod hover;
mod jump_definition;
mod notifications;
mod session;
mod slice_config;
mod server_state;
mod utils;

#[tokio::main]
Expand All @@ -32,13 +32,13 @@ async fn main() {

struct Backend {
client: Client,
session: Mutex<Session>,
server_state: Mutex<ServerState>,
}

impl Backend {
pub fn new(client: tower_lsp::Client) -> Self {
let session = Mutex::new(Session::default());
Self { client, session }
let server_state = Mutex::new(ServerState::default());
Self { client, server_state }
}

fn capabilities() -> ServerCapabilities {
Expand Down Expand Up @@ -78,8 +78,8 @@ impl Backend {
.log_message(MessageType::INFO, format!("File '{}' changed", file_path.display()))
.await;

let mut session_guard = self.session.lock().await;
let Session { configuration_sets, server_config } = session_guard.deref_mut();
let mut server_guard = self.server_state.lock().await;
let ServerState { configuration_sets, server_config } = server_guard.deref_mut();

let mut publish_map = HashMap::new();
let mut diagnostics = Vec::new();
Expand Down Expand Up @@ -140,8 +140,8 @@ impl Backend {
/// Triggers and compilation and publishes any diagnostics that are reported.
/// It does this for all configuration sets.
pub async fn compile_and_publish_diagnostics(&self) {
let mut session_guard = self.session.lock().await;
let Session { configuration_sets, server_config } = session_guard.deref_mut();
let mut server_guard = self.server_state.lock().await;
let ServerState { configuration_sets, server_config } = server_guard.deref_mut();

self.client
.log_message(
Expand All @@ -164,8 +164,8 @@ impl LanguageServer for Backend {
&self,
params: InitializeParams,
) -> tower_lsp::jsonrpc::Result<InitializeResult> {
let mut session_guard = self.session.lock().await;
session_guard.update_from_initialize_params(params);
let mut server_guard = self.server_state.lock().await;
server_guard.update_from_initialize_params(params);

let capabilities = Backend::capabilities();
Ok(InitializeResult {
Expand All @@ -188,16 +188,16 @@ impl LanguageServer for Backend {
.log_message(MessageType::INFO, "Extension settings changed")
.await;

// Explicit scope to ensure the session lock guard is dropped before we start compilation.
// Explicit scope to ensure the server state lock guard is dropped before we start compilation.
{
let mut session_guard = self.session.lock().await;
let mut server_guard = self.server_state.lock().await;

// When the configuration changes, any of the files in the workspace could be impacted. Therefore, we need to
// clear the diagnostics for all files and then re-publish them.
clear_diagnostics(&self.client, &session_guard.configuration_sets).await;
clear_diagnostics(&self.client, &server_guard.configuration_sets).await;

// Update the stored configuration sets from the data provided in the client notification
session_guard.update_configurations_from_params(params);
server_guard.update_configurations_from_params(params);
}

// Trigger a compilation and publish the diagnostics for all files
Expand All @@ -215,8 +215,8 @@ impl LanguageServer for Backend {
let file_path = url_to_sanitized_file_path(&uri).ok_or_else(Error::internal_error)?;

// Find the configuration set that contains the file
let session_guard = self.session.lock().await;
let configuration_sets = &session_guard.configuration_sets;
let server_guard = self.server_state.lock().await;
let configuration_sets = &server_guard.configuration_sets;

// Get the definition span and convert it to a GotoDefinitionResponse
Ok(configuration_sets.iter().find_map(|set| {
Expand All @@ -241,8 +241,8 @@ impl LanguageServer for Backend {
let file_path = url_to_sanitized_file_path(&uri).ok_or_else(Error::internal_error)?;

// Find the configuration set that contains the file and get the hover info
let session_guard = self.session.lock().await;
let configuration_sets = &session_guard.configuration_sets;
let server_guard = self.server_state.lock().await;
let configuration_sets = &server_guard.configuration_sets;

Ok(configuration_sets.iter().find_map(|set| {
let files = &set.compilation_data.files;
Expand Down
8 changes: 4 additions & 4 deletions server/src/session.rs → server/src/server_state.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) ZeroC, Inc.

use crate::configuration_set::ConfigurationSet;
use crate::slice_config::ServerConfig;
use crate::configuration::ServerConfig;
use crate::utils::{sanitize_path, url_to_sanitized_file_path};
use tower_lsp::lsp_types::{DidChangeConfigurationParams, InitializeParams};

#[derive(Debug, Default)]
pub struct Session {
pub struct ServerState {
/// 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 @@ -15,8 +15,8 @@ pub struct Session {
pub server_config: ServerConfig,
}

impl Session {
// Update the properties of the session from `InitializeParams`
impl ServerState {
// Update the properties of the server from `InitializeParams`
pub fn update_from_initialize_params(&mut self, params: InitializeParams) {
let initialization_options = params.initialization_options;

Expand Down