@@ -82,7 +82,7 @@ function warnOnUndeclaredLabels(
82
82
return warnings ;
83
83
}
84
84
85
- export function findEndPosition (
85
+ function findEndPosition (
86
86
e : SemanticAnalysisElement ,
87
87
parsingResult : StatementParsing ,
88
88
) : SyntaxDiagnostic {
@@ -147,49 +147,56 @@ export function sortByPosition(a: SyntaxDiagnostic, b: SyntaxDiagnostic) {
147
147
148
148
// TODO Does this need to be exported
149
149
export function lintCypherQuery (
150
- wholeFileText : string ,
150
+ query : string ,
151
151
dbSchema : DbSchema ,
152
152
) : SyntaxDiagnostic [ ] {
153
- const cachedParse = parserWrapper . parse ( wholeFileText ) ;
154
- const statements = cachedParse . statementsParsing ;
155
-
156
- const result = statements . flatMap ( ( statementParsing ) => {
157
- const syntaxErrors = validateSyntax ( statementParsing , dbSchema ) ;
158
-
159
- if ( syntaxErrors . length > 0 ) {
160
- return syntaxErrors ;
161
- }
162
-
163
- // TODO
164
- return validateSemantics ( statementParsing . statement )
165
- . map ( ( el ) => findEndPosition ( el , statementParsing ) )
166
- . sort ( sortByPosition ) ;
167
- } ) ;
153
+ const syntaxErrors = validateSyntax ( query , dbSchema ) ;
154
+ if ( syntaxErrors . length > 0 ) {
155
+ return syntaxErrors ;
156
+ }
168
157
169
- return result ;
158
+ const semanticErrors = validateSemantics ( query ) ;
159
+ return semanticErrors ;
170
160
}
171
161
172
162
// TODO Does this need to be exported
173
163
export function validateSyntax (
174
- statementParsing : StatementParsing ,
164
+ query : string ,
175
165
dbSchema : DbSchema ,
176
166
) : SyntaxDiagnostic [ ] {
177
- if ( statementParsing . statement . length === 0 ) {
167
+ if ( query . length === 0 ) {
178
168
return [ ] ;
179
169
}
180
- const diagnostics = statementParsing . diagnostics ;
181
- const labelWarnings = warnOnUndeclaredLabels ( statementParsing , dbSchema ) ;
182
- return diagnostics . concat ( labelWarnings ) . sort ( sortByPosition ) ;
170
+ const statements = parserWrapper . parse ( query ) ;
171
+ const result = statements . statementsParsing . flatMap ( ( statement ) => {
172
+ const diagnostics = statement . diagnostics ;
173
+ const labelWarnings = warnOnUndeclaredLabels ( statement , dbSchema ) ;
174
+ return diagnostics . concat ( labelWarnings ) . sort ( sortByPosition ) ;
175
+ } ) ;
176
+
177
+ return result ;
183
178
}
184
179
185
180
/**
186
181
* Assumes the provided query has no parse errors
187
182
*/
188
- export function validateSemantics ( query : string ) : SemanticAnalysisElement [ ] {
183
+ export function validateSemantics ( query : string ) : SyntaxDiagnostic [ ] {
189
184
if ( query . length > 0 ) {
190
- const { notifications, errors } = wrappedSemanticAnalysis ( query ) ;
185
+ const cachedParse = parserWrapper . parse ( query ) ;
186
+ const statements = cachedParse . statementsParsing ;
187
+ const semanticErrors = statements . flatMap ( ( current ) => {
188
+ const { notifications, errors } = wrappedSemanticAnalysis (
189
+ current . statement ,
190
+ ) ;
191
+
192
+ const elements = notifications . concat ( errors ) ;
193
+ const result = elements
194
+ . map ( ( el ) => findEndPosition ( el , current ) )
195
+ . sort ( sortByPosition ) ;
196
+ return result ;
197
+ } ) ;
191
198
192
- return notifications . concat ( errors ) ;
199
+ return semanticErrors ;
193
200
}
194
201
195
202
return [ ] ;
0 commit comments