File tree Expand file tree Collapse file tree 2 files changed +56
-1
lines changed
crates/pgt_workspace/src/workspace Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff 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 (
You can’t perform that action at this time.
0 commit comments