Skip to content

Commit

Permalink
update config handling
Browse files Browse the repository at this point in the history
  • Loading branch information
HTGAzureX1212 committed Jan 7, 2024
1 parent 3520efa commit 9b5aa44
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub(crate) struct PluginConfiguration {
#[serde(rename = "rustAnalyzer.nightly")]
#[serde(rename = "rustAnalyzer")]
pub rust_analyzer: Option<RustAnalyzerConfiguration>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct RustAnalyzerConfiguration {
#[serde(default)]
#[serde(rename = "nightly")]
pub nightly: bool,
}
24 changes: 15 additions & 9 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ pub(crate) fn initialize_plugin(params: InitializeParams) -> Result<()> {
.map(|value| serde_json::from_value::<PluginConfiguration>(value))
.transpose()?;

if let Some(config) = config {
PLUGIN_RPC.window_show_message(
MessageType::INFO,
format!(
"using {} rust-analyzer",
if config.nightly { "nightly" } else { "stable" }
),
)
}
let nightly = if let Some(config) = config
&& let Some(rust_analyzer) = config.rust_analyzer
{
rust_analyzer.nightly
} else {
false
};

PLUGIN_RPC.window_show_message(
MessageType::INFO,
format!(
"using {} rust-analyzer",
if nightly { "nightly" } else { "stable" }
),
);

Ok(())
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(let_chains)]

use lapce_plugin::psp_types::lsp_types::request::Initialize;
use lapce_plugin::psp_types::lsp_types::{InitializeParams, MessageType};
use lapce_plugin::psp_types::Request;
Expand Down

0 comments on commit 9b5aa44

Please sign in to comment.