From bb7bb76fa2fd3eb40ba449ab1525d732ca1ebbbe Mon Sep 17 00:00:00 2001 From: Emil Andersson Date: Wed, 3 Mar 2021 14:05:58 +0100 Subject: [PATCH 1/4] move startColumn of cypher warnings --- src/browser/modules/Editor/Monaco.tsx | 31 ++++++++++++--------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/browser/modules/Editor/Monaco.tsx b/src/browser/modules/Editor/Monaco.tsx index 12b90c75196..867e43c83c7 100644 --- a/src/browser/modules/Editor/Monaco.tsx +++ b/src/browser/modules/Editor/Monaco.tsx @@ -40,6 +40,7 @@ import { Bus } from 'suber' import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata' import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck' +import { NotificationPosition, QueryResult } from 'neo4j-driver' const shouldCheckForHints = (code: string) => code.trim().length > 0 && @@ -449,7 +450,7 @@ const Monaco = forwardRef( query: 'EXPLAIN ' + text, queryType: NEO4J_BROWSER_USER_ACTION_QUERY }, - response => { + (response: { result: QueryResult; success?: boolean }) => { if ( response.success === true && response.result.summary.notifications.length > 0 @@ -457,22 +458,18 @@ const Monaco = forwardRef( editor.setModelMarkers(model, monacoId, [ ...editor.getModelMarkers({ owner: monacoId }), ...response.result.summary.notifications.map( - ({ - description, - position: { line }, - title - }: { - description: string - position: { line: number } - title: string - }) => ({ - startLineNumber: statementLineNumber + line, - startColumn: 1, - endLineNumber: statementLineNumber + line, - endColumn: 1000, - message: title + '\n\n' + description, - severity: MarkerSeverity.Warning - }) + ({ description, position, title }) => { + const { line, column } = position as NotificationPosition + return { + startLineNumber: statementLineNumber + line, + // The 8 subtracted from the column on the first line is the length of 'EXPLAIN ' + startColumn: line === 1 ? column - 8 : column, + endLineNumber: statementLineNumber + line, + endColumn: 1000, + message: title + '\n\n' + description, + severity: MarkerSeverity.Warning + } + } ) ]) } From 334ca1778d95bcf6586a0a2e74fd501f7d04deac Mon Sep 17 00:00:00 2001 From: Emil Andersson Date: Fri, 5 Mar 2021 14:49:42 +0100 Subject: [PATCH 2/4] use column positions from queriesAndCommands --- src/browser/custom.d.ts | 11 ++++++++++- src/browser/modules/Editor/Monaco.tsx | 14 +++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/browser/custom.d.ts b/src/browser/custom.d.ts index a9dcd5b6f43..07252295950 100644 --- a/src/browser/custom.d.ts +++ b/src/browser/custom.d.ts @@ -118,11 +118,20 @@ declare module 'cypher-editor-support' { setSchema(schema: EditorSupportSchema): void update(input: string): void } + interface CypherPosition { + column: number + line: number + } + export interface QueryOrCommand { + getText: () => string + start: CypherPosition + stop: CypherPosition + } export function parse( input: string ): { referencesListener: { - queriesAndCommands: { getText: () => string; start: { line: number } }[] + queriesAndCommands: QueryOrCommand[] } } export function extractStatements( diff --git a/src/browser/modules/Editor/Monaco.tsx b/src/browser/modules/Editor/Monaco.tsx index 867e43c83c7..00331c8d000 100644 --- a/src/browser/modules/Editor/Monaco.tsx +++ b/src/browser/modules/Editor/Monaco.tsx @@ -19,7 +19,7 @@ */ import { QuickInputList } from 'monaco-editor/esm/vs/base/parts/quickinput/browser/quickInputList' -import { parse } from 'cypher-editor-support' +import { parse, QueryOrCommand } from 'cypher-editor-support' import { debounce } from 'lodash-es' import { editor, @@ -406,9 +406,7 @@ const Monaco = forwardRef( debouncedUpdateCode() } - const addWarnings = ( - statements: { start: { line: number }; getText: () => string }[] - ) => { + const addWarnings = (statements: QueryOrCommand[]) => { if (!statements.length) return const model = editorRef.current?.getModel() as editor.ITextModel @@ -463,9 +461,11 @@ const Monaco = forwardRef( return { startLineNumber: statementLineNumber + line, // The 8 subtracted from the column on the first line is the length of 'EXPLAIN ' - startColumn: line === 1 ? column - 8 : column, - endLineNumber: statementLineNumber + line, - endColumn: 1000, + startColumn: + statement.start.column + + (line === 1 ? column - 8 : column), + endLineNumber: statement.stop.line, + endColumn: statement.stop.column + 2, message: title + '\n\n' + description, severity: MarkerSeverity.Warning } From 01ebbcb23c365b600d032100525c0d0e18c1bfab Mon Sep 17 00:00:00 2001 From: Emil Andersson Date: Fri, 5 Mar 2021 15:32:41 +0100 Subject: [PATCH 3/4] use constants --- src/browser/modules/Editor/Monaco.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/browser/modules/Editor/Monaco.tsx b/src/browser/modules/Editor/Monaco.tsx index 00331c8d000..0d7f5273c96 100644 --- a/src/browser/modules/Editor/Monaco.tsx +++ b/src/browser/modules/Editor/Monaco.tsx @@ -90,6 +90,8 @@ interface MonacoProps { toggleFullscreen: () => void } +const EXPLAIN_QUERY_PREFIX = 'EXPLAIN ' +const EXPLAIN_QUERY_PREFIX_LENGTH = EXPLAIN_QUERY_PREFIX.length const Monaco = forwardRef( ( { @@ -445,7 +447,7 @@ const Monaco = forwardRef( bus.self( CYPHER_REQUEST, { - query: 'EXPLAIN ' + text, + query: EXPLAIN_QUERY_PREFIX + text, queryType: NEO4J_BROWSER_USER_ACTION_QUERY }, (response: { result: QueryResult; success?: boolean }) => { @@ -460,10 +462,11 @@ const Monaco = forwardRef( const { line, column } = position as NotificationPosition return { startLineNumber: statementLineNumber + line, - // The 8 subtracted from the column on the first line is the length of 'EXPLAIN ' startColumn: statement.start.column + - (line === 1 ? column - 8 : column), + (line === 1 + ? column - EXPLAIN_QUERY_PREFIX_LENGTH + : column), endLineNumber: statement.stop.line, endColumn: statement.stop.column + 2, message: title + '\n\n' + description, From d14fe94d890180a53a7b2a6b7464b69835d1f905 Mon Sep 17 00:00:00 2001 From: Emil Andersson Date: Tue, 9 Mar 2021 09:57:34 +0100 Subject: [PATCH 4/4] access line and column of position in a type safe way --- src/browser/modules/Editor/Monaco.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/browser/modules/Editor/Monaco.tsx b/src/browser/modules/Editor/Monaco.tsx index 0d7f5273c96..a2d5d157472 100644 --- a/src/browser/modules/Editor/Monaco.tsx +++ b/src/browser/modules/Editor/Monaco.tsx @@ -459,7 +459,8 @@ const Monaco = forwardRef( ...editor.getModelMarkers({ owner: monacoId }), ...response.result.summary.notifications.map( ({ description, position, title }) => { - const { line, column } = position as NotificationPosition + const line = 'line' in position ? position.line : 0 + const column = 'column' in position ? position.column : 0 return { startLineNumber: statementLineNumber + line, startColumn: