Skip to content

Commit 166f5aa

Browse files
author
Will Ruggiano
committed
fixup! feat: allow configuration through workspace/didChangeConfiguration
1 parent 1a8e21c commit 166f5aa

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

crates/pgt_configuration/src/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub use analyser::{
2222
RulePlainConfiguration, RuleSelector, RuleWithFixOptions, RuleWithOptions, Rules,
2323
partial_linter_configuration,
2424
};
25-
use biome_deserialize::Merge;
2625
use biome_deserialize_macros::{Merge, Partial};
2726
use bpaf::Bpaf;
2827
use database::{
@@ -116,11 +115,6 @@ impl PartialConfiguration {
116115
}),
117116
}
118117
}
119-
120-
pub fn merge(&mut self, other: Self) -> Self {
121-
self.merge_with(other);
122-
self.clone()
123-
}
124118
}
125119

126120
pub struct ConfigurationPayload {

crates/pgt_lsp/src/session.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::diagnostics::LspError;
33
use crate::documents::Document;
44
use crate::utils;
55
use anyhow::Result;
6+
use biome_deserialize::Merge;
67
use futures::StreamExt;
78
use futures::stream::FuturesUnordered;
89
use pgt_analyse::RuleCategoriesBuilder;
@@ -386,11 +387,13 @@ impl Session {
386387
/// This function attempts to read the `postgrestools.jsonc` configuration file from
387388
/// the root URI and update the workspace settings accordingly
388389
#[tracing::instrument(level = "trace", skip(self))]
389-
pub(crate) async fn load_workspace_settings(&self, params: Option<PartialConfiguration>) {
390+
pub(crate) async fn load_workspace_settings(&self, extra_config: Option<PartialConfiguration>) {
390391
// Providing a custom configuration path will not allow to support workspaces
391392
if let Some(config_path) = &self.config_path {
392393
let base_path = ConfigurationPathHint::FromUser(config_path.clone());
393-
let status = self.load_pgt_configuration_file(base_path, params).await;
394+
let status = self
395+
.load_pgt_configuration_file(base_path, extra_config)
396+
.await;
394397
self.set_configuration_status(status);
395398
} else if let Some(folders) = self.get_workspace_folders() {
396399
info!("Detected workspace folder.");
@@ -403,7 +406,7 @@ impl Session {
403406
let status = self
404407
.load_pgt_configuration_file(
405408
ConfigurationPathHint::FromWorkspace(base_path),
406-
params.clone(),
409+
extra_config.clone(),
407410
)
408411
.await;
409412
self.set_configuration_status(status);
@@ -421,7 +424,9 @@ impl Session {
421424
None => ConfigurationPathHint::default(),
422425
Some(path) => ConfigurationPathHint::FromLsp(path),
423426
};
424-
let status = self.load_pgt_configuration_file(base_path, params).await;
427+
let status = self
428+
.load_pgt_configuration_file(base_path, extra_config)
429+
.await;
425430
self.set_configuration_status(status);
426431
}
427432
}
@@ -434,24 +439,25 @@ impl Session {
434439
match load_configuration(&self.fs, base_path.clone()) {
435440
Ok(loaded_configuration) => {
436441
let LoadedConfiguration {
437-
configuration: fs_configuration,
442+
configuration: mut fs_configuration,
438443
directory_path: configuration_path,
439444
..
440445
} = loaded_configuration;
441446
info!("Configuration loaded successfully from disk.");
442447
info!("Update workspace settings.");
443448

449+
if let Some(ws_configuration) = extra_config {
450+
fs_configuration.merge_with(ws_configuration);
451+
}
452+
444453
let result = fs_configuration
445454
.retrieve_gitignore_matches(&self.fs, configuration_path.as_deref());
446455

447456
match result {
448457
Ok((vcs_base_path, gitignore_matches)) => {
449458
let result = self.workspace.update_settings(UpdateSettingsParams {
450459
workspace_directory: self.fs.working_directory(),
451-
configuration: match extra_config {
452-
Some(config) => fs_configuration.clone().merge(config),
453-
None => fs_configuration,
454-
},
460+
configuration: fs_configuration,
455461
vcs_base_path,
456462
gitignore_matches,
457463
skip_db: false,

0 commit comments

Comments
 (0)