Skip to content

Commit

Permalink
Makes signature help closer to VSCode format
Browse files Browse the repository at this point in the history
  • Loading branch information
ncordon committed Dec 18, 2023
1 parent 711d3d5 commit 6ad77e2
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions packages/react-codemirror/src/lang-cypher/signature-help.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { syntaxTree } from '@codemirror/language';
import { EditorState, StateField } from '@codemirror/state';
import { showTooltip, Tooltip } from '@codemirror/view';
import {
Expand All @@ -18,10 +19,11 @@ function getSignatureHelpTooltip(

if (schema) {
const pos = state.selection.main.head;
//const node = syntaxTree(state).resolveInner(pos, -1);
const symbol = syntaxTree(state).resolveInner(pos, -1);
const tree = parserWrapper.parsingResult;

if (
(symbol.name === 'bracket' || symbol.name === 'separator') &&
tree &&
findParent(
tree.stopNode,
Expand All @@ -34,23 +36,45 @@ function getSignatureHelpTooltip(
const signatureHelpInfo = signatureHelp(query, schema);
const activeSignature = signatureHelpInfo.activeSignature;
const signatures = signatureHelpInfo.signatures;
const activeParameter = signatureHelpInfo.activeParameter;

if (
activeSignature !== undefined &&
signatures[activeSignature].documentation !== undefined
activeSignature >= 0 &&
activeSignature < signatures.length &&
signatures[activeSignature].documentation !== undefined &&
activeParameter >= 0 &&
activeParameter < (signatures[activeSignature].parameters?.length ?? 0)
) {
const signature = signatures[activeSignature];
const parameters = signature.parameters;
const doc =
parameters[activeParameter].documentation.toString() +
'\n\n' +
signature.documentation.toString();

result = [
{
pos: pos,
above: true,
strictSide: true,
arrow: true,
create: () => {
const dom = document.createElement('div');
dom.className = 'cm-tooltip-cursor';
dom.textContent =
signatures[activeSignature].documentation.toString();
return { dom };
const div = document.createElement('div');
const methodName = document.createElement('div');
const argPlusDescription = document.createElement('div');
const separator = document.createElement('hr');
const lineBreak = document.createElement('br');

div.append(
...[methodName, separator, lineBreak, argPlusDescription],
);
div.className = 'cm-tooltip-cursor';

methodName.innerText = signature.label;
argPlusDescription.innerText = doc;

return { dom: div };
},
},
];
Expand Down

0 comments on commit 6ad77e2

Please sign in to comment.