Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/service/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,27 @@ export function getCompletions(
}
}

if (node.kind === syntaxKind.TextIdentifier && parent?.kind === syntaxKind.NodeId) {
const exclusions = node.symbol ? [node.symbol.name] : undefined;
return getNodeCompletions(symbols, exclusions);
}
const prevNodeNi = findNodeAtOffset(g, node.pos - 1, false);

if (
node.kind === syntaxKind.AttributeContainer ||
// FIXME: conflitcs with #issue 17 9 (last test of nodeCompletion.spec.ts)
// || (node.kind === SyntaxKind.TextIdentifier && prevNodeNi?.kind === SyntaxKind.AttributeContainer)
(node.kind === syntaxKind.TextIdentifier && prevNodeNi?.kind === syntaxKind.CommaToken) ||
(node.kind === syntaxKind.CommaToken && parent?.kind === syntaxKind.Assignment)
) {
return getAttributeCompletions(position);
}

if (node.kind === SyntaxKind.TextIdentifier && parent?.kind === SyntaxKind.NodeId) {
const exclusions = node.symbol ? [node.symbol.name] : undefined;
return getNodeCompletions(symbols, exclusions);
}

const prevNode = findNodeAtOffset(g, node.pos - 1, true);
if (!prevNode) return [];
if (!prevNode) {
return [];
}

if (isIdentifierNode(prevNode)) {
const p = prevNode.parent;
Expand Down
41 changes: 41 additions & 0 deletions tests/completion/attributeCompletion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,47 @@ describe("Attribute completion", () => {
expect(completions).toHaveLength(attributes.length);
});

// FIXME: currently failing
test("should provide completion for attributes (partial input)", () => {
const content = `graph {
node_name_a -- node_name_b [no];
}`;
const requestOffset = invokeIndex(content)("[no");

const [doc, sf] = ensureDocAndSourceFile(content);

const completions = getCompletions(doc, sf, doc.positionAt(requestOffset));

expect(completions).toBeDefined();
assertExists(completions);

expect(completions.length).toBeGreaterThan(0);
expect(completions.map(getLabel)).not.toContain("node_name_a");
expect(completions.map(getLabel)).not.toContain("node_name_b");
expect(completions.map(getLabel)).toEqual(attributes);
expect(completions).toHaveLength(attributes.length);
});

test("should provide completion for attributes (partial input, preceding item)", () => {
const content = `graph {
node_name_a -- node_name_b [color=blue, no];
}`;
const requestOffset = invokeIndex(content)(", no");

const [doc, sf] = ensureDocAndSourceFile(content);

const completions = getCompletions(doc, sf, doc.positionAt(requestOffset));

expect(completions).toBeDefined();
assertExists(completions);

expect(completions.length).toBeGreaterThan(0);
expect(completions.map(getLabel)).not.toContain("node_name_a");
expect(completions.map(getLabel)).not.toContain("node_name_b");
expect(completions.map(getLabel)).toEqual(attributes);
expect(completions).toHaveLength(attributes.length);
});

test("should provide completion for attributes (preceding item)", () => {
const content = `graph {
node_name_a -- node_name_b [color=blue,];
Expand Down