Skip to content

Commit

Permalink
fix suggestions and suppress recursive suggestions on void node (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpenaranda authored Jun 5, 2023
1 parent 8009b98 commit 9329ebf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 54 deletions.
32 changes: 2 additions & 30 deletions weave-js/src/core/suggest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,7 @@ describe('autosuggest', () => {

expectOnlyNodes(result);
const autosuggestNames = suggestResultNames(result);
expect(autosuggestNames).toEqual([
'x',
'x.isNone',
'x["a"]',
'x["b"]',
'x[]',
]);
expect(autosuggestNames).toEqual(['x']);
});

it('suggest for number', async () => {
Expand All @@ -344,29 +338,7 @@ describe('autosuggest', () => {

expectOnlyNodes(result);
const autosuggestNames = suggestResultNames(result);
expect(autosuggestNames).toEqual([
'x',
'x!=',
'x%',
'x*',
'x**',
'x+',
'x-',
'x/',
'x<',
'x<=',
'x==',
'x>',
'x>=',
'-x',
'abs(x)',
'cos(x)',
'gauss(x,,)',
'sin(x)',
'x.isNone',
'x.toString',
'x.toTimestamp',
]);
expect(autosuggestNames).toEqual(['x']);
});

it('suggest replacements for binary ops', async () => {
Expand Down
35 changes: 11 additions & 24 deletions weave-js/src/core/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ async function autosuggestNodes(
) {
result.push(constNumber(3.14159));
}

// Suggest none for equality comparison ops (which are all nullable),
// if the left hand side might have a null in it based on its input
// type.
Expand All @@ -499,24 +500,24 @@ async function autosuggestNodes(
result.push(constNone());
}
}

if (node.nodeType === 'void') {
const frame = toFrame(stack);
const variableNames = Object.keys(frame);
if (variableNames.length > 0) {
for (const varName of variableNames) {
// Recursively suggest results for each variable
let vNode = varNode(frame[varName].type, varName);
const newGraph = maybeReplaceNode(graph, node, vNode);
const results = await autosuggestNodes(
client,
vNode,
newGraph,
stack
);
vNode = results.refinedNode as any;

// const newGraph = maybeReplaceNode(graph, node, vNode);
// const results = await autosuggestNodes(
// client,
// vNode,
// newGraph,
// stack
// );
// vNode = results.refinedNode as any;
result.push(vNode);
result = result.concat(results.suggestions);
// result = result.concat(results.suggestions);
}
} else if (graph.nodeType === 'void') {
// Suggest root ops when there are no variables in the frame
Expand Down Expand Up @@ -686,20 +687,6 @@ export async function autosuggest(
}

result.sort((a, b) => {
// Picks first
const aIsPick =
a.newNodeOrOp.nodeType === 'output' &&
a.newNodeOrOp.fromOp.name === 'pick';
const bIsPick =
b.newNodeOrOp.nodeType === 'output' &&
b.newNodeOrOp.fromOp.name === 'pick';

if (aIsPick && !bIsPick) {
return -1;
} else if (!aIsPick && bIsPick) {
return 1;
}

const aIsTagGetter = isTagGetterNodeOrOp(a.newNodeOrOp, client.opStore);
const bIsTagGetter = isTagGetterNodeOrOp(b.newNodeOrOp, client.opStore);

Expand Down

0 comments on commit 9329ebf

Please sign in to comment.