Skip to content

Commit 36a3c52

Browse files
authored
fix: syntax error regression (#461)
syntax errors were not shown anymore due to a missing range. added a test to catch this regression next time.
1 parent fdfbd2c commit 36a3c52

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,58 @@ async fn test_diagnostics(test_db: PgPool) {
9797
Some(TextRange::new(106.into(), 136.into()))
9898
);
9999
}
100+
101+
#[sqlx::test(migrator = "pgt_test_utils::MIGRATIONS")]
102+
async fn test_syntax_error(test_db: PgPool) {
103+
let mut conf = PartialConfiguration::init();
104+
conf.merge_with(PartialConfiguration {
105+
db: Some(PartialDatabaseConfiguration {
106+
database: Some(
107+
test_db
108+
.connect_options()
109+
.get_database()
110+
.unwrap()
111+
.to_string(),
112+
),
113+
..Default::default()
114+
}),
115+
..Default::default()
116+
});
117+
118+
let workspace = get_test_workspace(Some(conf)).expect("Unable to create test workspace");
119+
120+
let path = PgTPath::new("test.sql");
121+
let content = r#"
122+
seect 1;
123+
"#;
124+
125+
workspace
126+
.open_file(OpenFileParams {
127+
path: path.clone(),
128+
content: content.into(),
129+
version: 1,
130+
})
131+
.expect("Unable to open test file");
132+
133+
let diagnostics = workspace
134+
.pull_diagnostics(crate::workspace::PullDiagnosticsParams {
135+
path: path.clone(),
136+
categories: RuleCategories::all(),
137+
max_diagnostics: 100,
138+
only: vec![],
139+
skip: vec![],
140+
})
141+
.expect("Unable to pull diagnostics")
142+
.diagnostics;
143+
144+
assert_eq!(diagnostics.len(), 1, "Expected one diagnostic");
145+
146+
let diagnostic = &diagnostics[0];
147+
148+
assert_eq!(diagnostic.category().map(|c| c.name()), Some("syntax"));
149+
150+
assert_eq!(
151+
diagnostic.location().span,
152+
Some(TextRange::new(7.into(), 15.into()))
153+
);
154+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<'a> StatementMapper<'a> for AnalyserDiagnosticsMapper {
259259
(Some(node.clone()), None)
260260
}
261261
}
262-
Err(diag) => (None, Some(diag.clone())),
262+
Err(diag) => (None, Some(diag.clone().span(range))),
263263
};
264264

265265
(

0 commit comments

Comments
 (0)