-
Notifications
You must be signed in to change notification settings - Fork 98
feat: allow configuration through workspace/didChangeConfiguration #316
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ use anyhow::Result; | |
use futures::StreamExt; | ||
use futures::stream::FuturesUnordered; | ||
use pgt_analyse::RuleCategoriesBuilder; | ||
use pgt_configuration::ConfigurationPathHint; | ||
use pgt_configuration::{ConfigurationPathHint, PartialConfiguration}; | ||
use pgt_diagnostics::{DiagnosticExt, Error}; | ||
use pgt_fs::{FileSystem, PgTPath}; | ||
use pgt_workspace::Workspace; | ||
|
@@ -386,11 +386,11 @@ impl Session { | |
/// This function attempts to read the `postgrestools.jsonc` configuration file from | ||
/// the root URI and update the workspace settings accordingly | ||
#[tracing::instrument(level = "trace", skip(self))] | ||
pub(crate) async fn load_workspace_settings(&self) { | ||
pub(crate) async fn load_workspace_settings(&self, params: Option<PartialConfiguration>) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I liked the |
||
// Providing a custom configuration path will not allow to support workspaces | ||
if let Some(config_path) = &self.config_path { | ||
let base_path = ConfigurationPathHint::FromUser(config_path.clone()); | ||
let status = self.load_pgt_configuration_file(base_path).await; | ||
let status = self.load_pgt_configuration_file(base_path, params).await; | ||
self.set_configuration_status(status); | ||
} else if let Some(folders) = self.get_workspace_folders() { | ||
info!("Detected workspace folder."); | ||
|
@@ -401,9 +401,10 @@ impl Session { | |
match base_path { | ||
Ok(base_path) => { | ||
let status = self | ||
.load_pgt_configuration_file(ConfigurationPathHint::FromWorkspace( | ||
base_path, | ||
)) | ||
.load_pgt_configuration_file( | ||
ConfigurationPathHint::FromWorkspace(base_path), | ||
params.clone(), | ||
) | ||
.await; | ||
self.set_configuration_status(status); | ||
} | ||
|
@@ -420,14 +421,15 @@ impl Session { | |
None => ConfigurationPathHint::default(), | ||
Some(path) => ConfigurationPathHint::FromLsp(path), | ||
}; | ||
let status = self.load_pgt_configuration_file(base_path).await; | ||
let status = self.load_pgt_configuration_file(base_path, params).await; | ||
self.set_configuration_status(status); | ||
} | ||
} | ||
|
||
async fn load_pgt_configuration_file( | ||
&self, | ||
base_path: ConfigurationPathHint, | ||
extra_config: Option<PartialConfiguration>, | ||
) -> ConfigurationStatus { | ||
match load_configuration(&self.fs, base_path.clone()) { | ||
Ok(loaded_configuration) => { | ||
|
@@ -446,7 +448,10 @@ impl Session { | |
Ok((vcs_base_path, gitignore_matches)) => { | ||
let result = self.workspace.update_settings(UpdateSettingsParams { | ||
workspace_directory: self.fs.working_directory(), | ||
configuration: fs_configuration, | ||
configuration: match extra_config { | ||
Some(config) => fs_configuration.clone().merge(config), | ||
None => fs_configuration, | ||
}, | ||
Comment on lines
+451
to
+454
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need the extra allocation (caused by Maybe it is better to do a If you use the Let me know if you need help with that. |
||
vcs_base_path, | ||
gitignore_matches, | ||
skip_db: false, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do what I wrote above, we don't need this helper and the clone 👍🏻