Skip to content

Commit

Permalink
Adds an offset prop and a test to check signature help works on auto-…
Browse files Browse the repository at this point in the history
…closed parenthesis
  • Loading branch information
ncordon committed Jan 19, 2024
1 parent f63c123 commit bcfd87b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 44 deletions.
6 changes: 6 additions & 0 deletions packages/react-codemirror/src/CypherEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -249,6 +253,8 @@ export class CypherEditor extends Component<CypherEditorProps> {
if (this.props.value) {
this.updateCursorPosition(this.props.value.length);
}
} else if (this.props.offset) {
this.updateCursorPosition(this.props.offset);
}
}

Expand Down
56 changes: 14 additions & 42 deletions packages/react-codemirror/src/e2e_tests/signature-help.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
<CypherEditor
value={query}
schema={testData.mockSchema}
autofocus={true}
/>,
);

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,
}) => {
Expand All @@ -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<MAP>',
'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(
<CypherEditor
value={query}
schema={testData.mockSchema}
autofocus={true}
/>,
<CypherEditor value={query} schema={testData.mockSchema} offset={22} />,
);

const tooltip = page.locator('.cm-tooltip-signature-help').last();
Expand Down
1 change: 0 additions & 1 deletion packages/react-codemirror/src/lang-cypher/lang-cypher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const cypherLanguage = new Language(facet, parserAdapter, [], 'cypher');

export type CypherConfig = {
lint?: boolean;
signatureHelp?: boolean;
schema?: DbSchema;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 === '(';
Expand Down

0 comments on commit bcfd87b

Please sign in to comment.