From bcfd87b7219cd56a98c033354cbb6d197647b41e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Cord=C3=B3n?= Date: Fri, 19 Jan 2024 11:44:08 +0000 Subject: [PATCH] Adds an offset prop and a test to check signature help works on auto-closed parenthesis --- .../react-codemirror/src/CypherEditor.tsx | 6 ++ .../src/e2e_tests/signature-help.spec.tsx | 56 +++++-------------- .../src/lang-cypher/lang-cypher.ts | 1 - .../src/lang-cypher/signature-help.ts | 2 +- 4 files changed, 21 insertions(+), 44 deletions(-) diff --git a/packages/react-codemirror/src/CypherEditor.tsx b/packages/react-codemirror/src/CypherEditor.tsx index f80930041..d7b9dd130 100644 --- a/packages/react-codemirror/src/CypherEditor.tsx +++ b/packages/react-codemirror/src/CypherEditor.tsx @@ -57,6 +57,10 @@ export interface CypherEditorProps { * @default false */ autofocus?: boolean; + /** + * Where to place the cursor in the query. Cannot be enabled at the same time than autofocus + */ + offset?: number; /** * Whether the editor should wrap lines. * @@ -249,6 +253,8 @@ export class CypherEditor extends Component { if (this.props.value) { this.updateCursorPosition(this.props.value.length); } + } else if (this.props.offset) { + this.updateCursorPosition(this.props.offset); } } diff --git a/packages/react-codemirror/src/e2e_tests/signature-help.spec.tsx b/packages/react-codemirror/src/e2e_tests/signature-help.spec.tsx index 335ca39c6..95e86b18f 100644 --- a/packages/react-codemirror/src/e2e_tests/signature-help.spec.tsx +++ b/packages/react-codemirror/src/e2e_tests/signature-help.spec.tsx @@ -33,10 +33,7 @@ function testTooltip(tooltip: Locator, expectations: TooltipExpectations) { return Promise.all([included, excluded]); } -test('Prop signatureHelp set to false disables signature help for functions', async ({ - page, - mount, -}) => { +test('Signature help works for functions', async ({ page, mount }) => { const query = 'RETURN abs('; await mount( @@ -47,17 +44,12 @@ test('Prop signatureHelp set to false disables signature help for functions', as />, ); - await expect( - page.locator('.cm-tooltip-signature-help').last(), - ).not.toBeVisible({ + await expect(page.locator('.cm-tooltip-signature-help').last()).toBeVisible({ timeout: 2000, }); }); -test('Prop signatureHelp set to true disables signature help for procedures', async ({ - page, - mount, -}) => { +test('Signature help works for procedures', async ({ page, mount }) => { const query = 'CALL apoc.import.csv('; await mount( @@ -68,33 +60,12 @@ test('Prop signatureHelp set to true disables signature help for procedures', as />, ); - await expect( - page.locator('.cm-tooltip-signature-help').last(), - ).not.toBeVisible({ - timeout: 2000, - }); -}); - -test('Prop signatureHelp set to true enables signature help', async ({ - page, - mount, -}) => { - const query = 'RETURN abs('; - - await mount( - , - ); - await expect(page.locator('.cm-tooltip-signature-help').last()).toBeVisible({ timeout: 2000, }); }); -test('Prop signatureHelp enables signature help by default', async ({ +test('Signature help shows the description for the first argument', async ({ page, mount, }) => { @@ -108,23 +79,24 @@ test('Prop signatureHelp enables signature help by default', async ({ />, ); - await expect(page.locator('.cm-tooltip-signature-help').last()).toBeVisible({ - timeout: 2000, + const tooltip = page.locator('.cm-tooltip-signature-help').last(); + + await testTooltip(tooltip, { + includes: [ + 'nodes :: LIST', + 'Imports `NODE` and `RELATIONSHIP` values with the given labels and types from the provided CSV file', + ], }); }); -test('Signature help shows the description for the first argument', async ({ +test('Signature help works when the parenthesis has been auto closed and the cursor is placed before )', async ({ page, mount, }) => { - const query = 'CALL apoc.import.csv('; + const query = 'CALL apoc.import.csv()'; await mount( - , + , ); const tooltip = page.locator('.cm-tooltip-signature-help').last(); diff --git a/packages/react-codemirror/src/lang-cypher/lang-cypher.ts b/packages/react-codemirror/src/lang-cypher/lang-cypher.ts index d8f3e7631..86a3da598 100644 --- a/packages/react-codemirror/src/lang-cypher/lang-cypher.ts +++ b/packages/react-codemirror/src/lang-cypher/lang-cypher.ts @@ -20,7 +20,6 @@ const cypherLanguage = new Language(facet, parserAdapter, [], 'cypher'); export type CypherConfig = { lint?: boolean; - signatureHelp?: boolean; schema?: DbSchema; }; diff --git a/packages/react-codemirror/src/lang-cypher/signature-help.ts b/packages/react-codemirror/src/lang-cypher/signature-help.ts index e510ccf11..fe67aea7d 100644 --- a/packages/react-codemirror/src/lang-cypher/signature-help.ts +++ b/packages/react-codemirror/src/lang-cypher/signature-help.ts @@ -39,7 +39,7 @@ function getSignatureHelpTooltip( const lastToken = tokens.at(-2); const prevToken = tokens.at(-3); - if (schema && config.signatureHelp && lastToken) { + if (schema && lastToken) { const pos = state.selection.main.head; const tree = parserWrapper.parsingResult; const isOpenBracket = lastToken.text === '(';