Skip to content

fix: files.ignore setting should work #462

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

Merged
merged 13 commits into from
Jul 19, 2025
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
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ convert_case = "0.6.0"
prost-reflect = "0.15.3"
protox = "0.8.0"
sqlx = { version = "0.8.2", features = ["runtime-tokio", "runtime-async-std", "postgres", "json"] }
syn = "1.0.109"
syn = { version = "1.0.109", features = ["full"] }
termcolor = "1.4.1"
test-log = "0.2.17"
tokio = { version = "1.40.0", features = ["full"] }
Expand Down Expand Up @@ -85,6 +85,7 @@ pgt_tokenizer = { path = "./crates/pgt_tokenizer", version = "0.0.0
pgt_treesitter_queries = { path = "./crates/pgt_treesitter_queries", version = "0.0.0" }
pgt_typecheck = { path = "./crates/pgt_typecheck", version = "0.0.0" }
pgt_workspace = { path = "./crates/pgt_workspace", version = "0.0.0" }
pgt_workspace_macros = { path = "./crates/pgt_workspace_macros", version = "0.0.0" }

pgt_test_macros = { path = "./crates/pgt_test_macros" }
pgt_test_utils = { path = "./crates/pgt_test_utils" }
Expand Down
3 changes: 2 additions & 1 deletion crates/pgt_diagnostics/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ impl From<super::Location<'_>> for Location {
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(test, derive(Eq, PartialEq))]

struct Advices {
advices: Vec<Advice>,
}
Expand Down Expand Up @@ -250,7 +251,7 @@ impl super::Advices for Advices {
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(test, derive(Eq, PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
enum Advice {
Log(LogCategory, MarkupBuf),
List(Vec<MarkupBuf>),
Expand Down
1 change: 1 addition & 0 deletions crates/pgt_workspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pgt_statement_splitter = { workspace = true }
pgt_suppressions = { workspace = true }
pgt_text_size.workspace = true
pgt_typecheck = { workspace = true }
pgt_workspace_macros = { workspace = true }
rustc-hash = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/pgt_workspace/src/features/code_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct CodeActionsParams {
pub skip: Vec<RuleSelector>,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[derive(Debug, serde::Serialize, serde::Deserialize, Default)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct CodeActionsResult {
pub actions: Vec<CodeAction>,
Expand Down Expand Up @@ -57,7 +57,7 @@ pub struct ExecuteStatementParams {
pub path: PgTPath,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[derive(Debug, serde::Serialize, serde::Deserialize, Default, PartialEq, Eq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct ExecuteStatementResult {
pub message: String,
Expand Down
2 changes: 1 addition & 1 deletion crates/pgt_workspace/src/features/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct PullDiagnosticsParams {
pub skip: Vec<RuleSelector>,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[derive(Debug, serde::Serialize, serde::Deserialize, Default)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PullDiagnosticsResult {
pub diagnostics: Vec<pgt_diagnostics::serde::Diagnostic>,
Expand Down
15 changes: 12 additions & 3 deletions crates/pgt_workspace/src/workspace/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use pgt_diagnostics::{
};
use pgt_fs::{ConfigName, PgTPath};
use pgt_typecheck::{IdentifierType, TypecheckParams, TypedIdentifier};
use pgt_workspace_macros::ignored_path;
use schema_cache_manager::SchemaCacheManager;
use sqlx::{Executor, PgPool};
use tracing::{debug, info};
Expand All @@ -30,7 +31,7 @@ use crate::{
configuration::to_analyser_rules,
features::{
code_actions::{
self, CodeAction, CodeActionKind, CodeActionsResult, CommandAction,
CodeAction, CodeActionKind, CodeActionsParams, CodeActionsResult, CommandAction,
CommandActionCategory, ExecuteStatementParams, ExecuteStatementResult,
},
completions::{CompletionsResult, GetCompletionsParams, get_statement_for_completions},
Expand Down Expand Up @@ -262,6 +263,7 @@ impl Workspace for WorkspaceServer {
}

/// Add a new file to the workspace
#[ignored_path(path=&params.path)]
#[tracing::instrument(level = "info", skip_all, fields(path = params.path.as_path().as_os_str().to_str()), err)]
fn open_file(&self, params: OpenFileParams) -> Result<(), WorkspaceError> {
let mut documents = self.documents.write().unwrap();
Expand All @@ -277,6 +279,7 @@ impl Workspace for WorkspaceServer {
}

/// Remove a file from the workspace
#[ignored_path(path=&params.path)]
fn close_file(&self, params: super::CloseFileParams) -> Result<(), WorkspaceError> {
let mut documents = self.documents.write().unwrap();
documents
Expand All @@ -291,6 +294,7 @@ impl Workspace for WorkspaceServer {
path = params.path.as_os_str().to_str(),
version = params.version
), err)]
#[ignored_path(path=&params.path)]
fn change_file(&self, params: super::ChangeFileParams) -> Result<(), WorkspaceError> {
let mut documents = self.documents.write().unwrap();

Expand All @@ -312,6 +316,7 @@ impl Workspace for WorkspaceServer {
None
}

#[ignored_path(path=&params.path)]
fn get_file_content(&self, params: GetFileContentParams) -> Result<String, WorkspaceError> {
let documents = self.documents.read().unwrap();
let document = documents
Expand All @@ -324,10 +329,11 @@ impl Workspace for WorkspaceServer {
Ok(self.is_ignored(params.pgt_path.as_path()))
}

#[ignored_path(path=&params.path)]
fn pull_code_actions(
&self,
params: code_actions::CodeActionsParams,
) -> Result<code_actions::CodeActionsResult, WorkspaceError> {
params: CodeActionsParams,
) -> Result<CodeActionsResult, WorkspaceError> {
let documents = self.documents.read().unwrap();
let parser = documents
.get(&params.path)
Expand Down Expand Up @@ -366,6 +372,7 @@ impl Workspace for WorkspaceServer {
Ok(CodeActionsResult { actions })
}

#[ignored_path(path=&params.path)]
fn execute_statement(
&self,
params: ExecuteStatementParams,
Expand Down Expand Up @@ -409,6 +416,7 @@ impl Workspace for WorkspaceServer {
})
}

#[ignored_path(path=&params.path)]
fn pull_diagnostics(
&self,
params: PullDiagnosticsParams,
Expand Down Expand Up @@ -607,6 +615,7 @@ impl Workspace for WorkspaceServer {
})
}

#[ignored_path(path=&params.path)]
#[tracing::instrument(level = "debug", skip_all, fields(
path = params.path.as_os_str().to_str(),
position = params.position.to_string()
Expand Down
60 changes: 57 additions & 3 deletions crates/pgt_workspace/src/workspace/server.tests.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
use biome_deserialize::Merge;
use std::sync::Arc;

use biome_deserialize::{Merge, StringSet};
use pgt_analyse::RuleCategories;
use pgt_configuration::{PartialConfiguration, database::PartialDatabaseConfiguration};
use pgt_configuration::{
PartialConfiguration, database::PartialDatabaseConfiguration, files::PartialFilesConfiguration,
};
use pgt_diagnostics::Diagnostic;
use pgt_fs::PgTPath;
use pgt_text_size::TextRange;
use sqlx::PgPool;

use crate::{
Workspace, WorkspaceError,
features::code_actions::ExecuteStatementResult,
workspace::{
OpenFileParams, RegisterProjectFolderParams, UpdateSettingsParams, server::WorkspaceServer,
OpenFileParams, RegisterProjectFolderParams, StatementId, UpdateSettingsParams,
server::WorkspaceServer,
},
};

Expand Down Expand Up @@ -152,3 +158,51 @@ async fn test_syntax_error(test_db: PgPool) {
Some(TextRange::new(7.into(), 15.into()))
);
}

#[tokio::test]
async fn correctly_ignores_files() {
let mut conf = PartialConfiguration::init();
conf.merge_with(PartialConfiguration {
files: Some(PartialFilesConfiguration {
ignore: Some(StringSet::from_iter(["test.sql".to_string()])),
..Default::default()
}),
..Default::default()
});

let workspace = get_test_workspace(Some(conf)).expect("Unable to create test workspace");

let path = PgTPath::new("test.sql");
let content = r#"
seect 1;
"#;

let diagnostics_result = workspace.pull_diagnostics(crate::workspace::PullDiagnosticsParams {
path: path.clone(),
categories: RuleCategories::all(),
max_diagnostics: 100,
only: vec![],
skip: vec![],
});

assert!(
diagnostics_result.is_ok_and(|res| res.diagnostics.is_empty()
&& res.errors == 0
&& res.skipped_diagnostics == 0)
);

let close_file_result =
workspace.close_file(crate::workspace::CloseFileParams { path: path.clone() });

assert!(close_file_result.is_ok());

let execute_statement_result =
workspace.execute_statement(crate::workspace::ExecuteStatementParams {
path: path.clone(),
statement_id: StatementId::Root {
content: Arc::from(content),
},
});

assert!(execute_statement_result.is_ok_and(|res| res == ExecuteStatementResult::default()));
}
19 changes: 19 additions & 0 deletions crates/pgt_workspace_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
authors.workspace = true
categories.workspace = true
description = "<DESCRIPTION>"
edition.workspace = true
homepage.workspace = true
keywords.workspace = true
license.workspace = true
name = "pgt_workspace_macros"
repository.workspace = true
version = "0.0.0"

[lib]
proc-macro = true

[dependencies]
proc-macro2 = { version = "1.0.95" }
quote = { workspace = true }
syn = { workspace = true }
Loading