Skip to content

Commit 2d8a646

Browse files
mamma mia
1 parent 61b6266 commit 2d8a646

File tree

7 files changed

+90
-39
lines changed

7 files changed

+90
-39
lines changed

crates/pgt_diagnostics/src/serde.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ impl From<super::Location<'_>> for Location {
164164
#[serde(rename_all = "camelCase")]
165165
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
166166
#[cfg_attr(test, derive(Eq, PartialEq))]
167+
167168
struct Advices {
168169
advices: Vec<Advice>,
169170
}
@@ -250,7 +251,7 @@ impl super::Advices for Advices {
250251
#[derive(Clone, Debug, Serialize, Deserialize)]
251252
#[serde(rename_all = "camelCase")]
252253
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
253-
#[cfg_attr(test, derive(Eq, PartialEq))]
254+
#[cfg_attr(test, derive(PartialEq, Eq))]
254255
enum Advice {
255256
Log(LogCategory, MarkupBuf),
256257
List(Vec<MarkupBuf>),

crates/pgt_workspace/src/features/code_actions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct ExecuteStatementParams {
5757
pub path: PgTPath,
5858
}
5959

60-
#[derive(Debug, serde::Serialize, serde::Deserialize, Default)]
60+
#[derive(Debug, serde::Serialize, serde::Deserialize, Default, PartialEq, Eq)]
6161
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
6262
pub struct ExecuteStatementResult {
6363
pub message: String,

crates/pgt_workspace/src/workspace.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use crate::{
2222

2323
mod client;
2424
mod server;
25-
mod tryout;
2625

2726
pub use server::StatementId;
2827
pub(crate) use server::document::*;

crates/pgt_workspace/src/workspace/server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ impl Workspace for WorkspaceServer {
294294
path = params.path.as_os_str().to_str(),
295295
version = params.version
296296
), err)]
297+
#[ignored_path(path=&params.path)]
297298
fn change_file(&self, params: super::ChangeFileParams) -> Result<(), WorkspaceError> {
298299
let mut documents = self.documents.write().unwrap();
299300

crates/pgt_workspace/src/workspace/server.tests.rs

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
use biome_deserialize::Merge;
1+
use std::sync::Arc;
2+
3+
use biome_deserialize::{Merge, StringSet};
24
use pgt_analyse::RuleCategories;
3-
use pgt_configuration::{PartialConfiguration, database::PartialDatabaseConfiguration};
5+
use pgt_configuration::{
6+
PartialConfiguration, database::PartialDatabaseConfiguration, files::PartialFilesConfiguration,
7+
};
48
use pgt_diagnostics::Diagnostic;
59
use pgt_fs::PgTPath;
610
use pgt_text_size::TextRange;
711
use sqlx::PgPool;
812

913
use crate::{
1014
Workspace, WorkspaceError,
15+
features::code_actions::ExecuteStatementResult,
1116
workspace::{
12-
OpenFileParams, RegisterProjectFolderParams, UpdateSettingsParams, server::WorkspaceServer,
17+
OpenFileParams, RegisterProjectFolderParams, StatementId, UpdateSettingsParams,
18+
server::WorkspaceServer,
1319
},
1420
};
1521

@@ -152,3 +158,51 @@ async fn test_syntax_error(test_db: PgPool) {
152158
Some(TextRange::new(7.into(), 15.into()))
153159
);
154160
}
161+
162+
#[tokio::test]
163+
async fn correctly_ignores_files() {
164+
let mut conf = PartialConfiguration::init();
165+
conf.merge_with(PartialConfiguration {
166+
files: Some(PartialFilesConfiguration {
167+
ignore: Some(StringSet::from_iter(["test.sql".to_string()])),
168+
..Default::default()
169+
}),
170+
..Default::default()
171+
});
172+
173+
let workspace = get_test_workspace(Some(conf)).expect("Unable to create test workspace");
174+
175+
let path = PgTPath::new("test.sql");
176+
let content = r#"
177+
seect 1;
178+
"#;
179+
180+
let diagnostics_result = workspace.pull_diagnostics(crate::workspace::PullDiagnosticsParams {
181+
path: path.clone(),
182+
categories: RuleCategories::all(),
183+
max_diagnostics: 100,
184+
only: vec![],
185+
skip: vec![],
186+
});
187+
188+
assert!(
189+
diagnostics_result.is_ok_and(|res| res.diagnostics.len() == 0
190+
&& res.errors == 0
191+
&& res.skipped_diagnostics == 0)
192+
);
193+
194+
let close_file_result =
195+
workspace.close_file(crate::workspace::CloseFileParams { path: path.clone() });
196+
197+
assert!(close_file_result.is_ok_and(|res| res == ()));
198+
199+
let execute_statement_result =
200+
workspace.execute_statement(crate::workspace::ExecuteStatementParams {
201+
path: path.clone(),
202+
statement_id: StatementId::Root {
203+
content: Arc::from(content),
204+
},
205+
});
206+
207+
assert!(execute_statement_result.is_ok_and(|res| res == ExecuteStatementResult::default()));
208+
}

crates/pgt_workspace/src/workspace/tryout.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

crates/pgt_workspace_macros/src/lib.rs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::ops::Deref;
22

33
use proc_macro::TokenStream;
44
use quote::quote;
5-
use syn::{TypePath, parse_macro_input};
5+
use syn::{TypePath, TypeTuple, parse_macro_input};
66

77
struct IgnoredPath {
88
path: syn::Expr,
@@ -41,38 +41,41 @@ pub fn ignored_path(args: TokenStream, input: TokenStream) -> TokenStream {
4141
let block = &input_fn.block;
4242
let attrs = &input_fn.attrs;
4343

44-
// get T in Result<T, E>
44+
// handles cases `fn foo() -> Result<T, E>` and `fn foo() -> Result<(), E>`
45+
// T needs to implement default
4546
if let syn::ReturnType::Type(_, ty) = &sig.output {
4647
if let syn::Type::Path(TypePath { path, .. }) = ty.deref() {
4748
if let Some(seg) = path.segments.last() {
4849
if seg.ident == "Result" {
4950
if let syn::PathArguments::AngleBracketed(type_args) = &seg.arguments {
5051
if let Some(t) = type_args.args.first() {
5152
if let syn::GenericArgument::Type(t) = t {
53+
if let syn::Type::Tuple(TypeTuple { elems, .. }) = t {
54+
// case: Result<(), E>
55+
if elems.len() == 0 {
56+
return TokenStream::from(quote! {
57+
#(#attrs)*
58+
#vis #sig {
59+
if self.is_ignored(#macro_specified_path) {
60+
return Ok(());
61+
};
62+
#block
63+
}
64+
});
65+
}
66+
}
5267
if let syn::Type::Path(TypePath { path, .. }) = t {
5368
if let Some(seg) = path.segments.first() {
5469
let ident = &seg.ident;
55-
if ident == "()" {
56-
return TokenStream::from(quote! {
57-
#(#attrs)*
58-
#vis #sig {
59-
if self.is_ignored(#macro_specified_path) {
60-
return Ok(());
61-
};
62-
#block
63-
}
64-
});
65-
} else {
66-
return TokenStream::from(quote! {
67-
#(#attrs)*
68-
#vis #sig {
69-
if self.is_ignored(#macro_specified_path) {
70-
return Ok(#ident::default());
71-
};
72-
#block
73-
}
74-
});
75-
}
70+
return TokenStream::from(quote! {
71+
#(#attrs)*
72+
#vis #sig {
73+
if self.is_ignored(#macro_specified_path) {
74+
return Ok(#ident::default());
75+
};
76+
#block
77+
}
78+
});
7679
}
7780
}
7881
};
@@ -83,6 +86,9 @@ pub fn ignored_path(args: TokenStream, input: TokenStream) -> TokenStream {
8386
};
8487
};
8588

89+
// case fn foo() -> T {}
90+
// handles all other T's
91+
// T needs to implement Default
8692
return TokenStream::from(quote! {
8793
#(#attrs)*
8894
#vis #sig {

0 commit comments

Comments
 (0)