1919 */
2020
2121import { QuickInputList } from 'monaco-editor/esm/vs/base/parts/quickinput/browser/quickInputList'
22- import { parse } from 'cypher-editor-support'
22+ import { parse , QueryOrCommand } from 'cypher-editor-support'
2323import { debounce } from 'lodash-es'
2424import {
2525 editor ,
@@ -40,6 +40,7 @@ import { Bus } from 'suber'
4040
4141import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata'
4242import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck'
43+ import { NotificationPosition , QueryResult } from 'neo4j-driver'
4344
4445const shouldCheckForHints = ( code : string ) =>
4546 code . trim ( ) . length > 0 &&
@@ -89,6 +90,8 @@ interface MonacoProps {
8990 toggleFullscreen : ( ) => void
9091}
9192
93+ const EXPLAIN_QUERY_PREFIX = 'EXPLAIN '
94+ const EXPLAIN_QUERY_PREFIX_LENGTH = EXPLAIN_QUERY_PREFIX . length
9295const Monaco = forwardRef < MonacoHandles , MonacoProps > (
9396 (
9497 {
@@ -405,9 +408,7 @@ const Monaco = forwardRef<MonacoHandles, MonacoProps>(
405408 debouncedUpdateCode ( )
406409 }
407410
408- const addWarnings = (
409- statements : { start : { line : number } ; getText : ( ) => string } [ ]
410- ) => {
411+ const addWarnings = ( statements : QueryOrCommand [ ] ) => {
411412 if ( ! statements . length ) return
412413
413414 const model = editorRef . current ?. getModel ( ) as editor . ITextModel
@@ -446,33 +447,33 @@ const Monaco = forwardRef<MonacoHandles, MonacoProps>(
446447 bus . self (
447448 CYPHER_REQUEST ,
448449 {
449- query : 'EXPLAIN ' + text ,
450+ query : EXPLAIN_QUERY_PREFIX + text ,
450451 queryType : NEO4J_BROWSER_USER_ACTION_QUERY
451452 } ,
452- response => {
453+ ( response : { result : QueryResult ; success ?: boolean } ) => {
453454 if (
454455 response . success === true &&
455456 response . result . summary . notifications . length > 0
456457 ) {
457458 editor . setModelMarkers ( model , monacoId , [
458459 ...editor . getModelMarkers ( { owner : monacoId } ) ,
459460 ...response . result . summary . notifications . map (
460- ( {
461- description ,
462- position : { line } ,
463- title
464- } : {
465- description : string
466- position : { line : number }
467- title : string
468- } ) => ( {
469- startLineNumber : statementLineNumber + line ,
470- startColumn : 1 ,
471- endLineNumber : statementLineNumber + line ,
472- endColumn : 1000 ,
473- message : title + '\n\n' + description ,
474- severity : MarkerSeverity . Warning
475- } )
461+ ( { description , position , title } ) => {
462+ const line = 'line' in position ? position . line : 0
463+ const column = 'column' in position ? position . column : 0
464+ return {
465+ startLineNumber : statementLineNumber + line ,
466+ startColumn :
467+ statement . start . column +
468+ ( line === 1
469+ ? column - EXPLAIN_QUERY_PREFIX_LENGTH
470+ : column ) ,
471+ endLineNumber : statement . stop . line ,
472+ endColumn : statement . stop . column + 2 ,
473+ message : title + '\n\n' + description ,
474+ severity : MarkerSeverity . Warning
475+ }
476+ }
476477 )
477478 ] )
478479 }
0 commit comments