Skip to content

Commit

Permalink
Fix missing group completion proposal (#1689)
Browse files Browse the repository at this point in the history
  • Loading branch information
ydaveluy authored Dec 4, 2024
1 parent 3170af9 commit 4e96814
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ function findNextFeaturesInternal(options: { next: NextFeature, cardinalities: M
const feature = next.feature;
if (visited.has(feature)) {
return [];
} else {
} else if (!ast.isGroup(feature)) {
// Do not add the feature to the list if it is a group
// `findFirstFeaturesInternal` will take care of this
visited.add(feature);
}
let parent: ast.Group | undefined;
Expand Down Expand Up @@ -132,8 +134,6 @@ function findFirstFeaturesInternal(options: { next: NextFeature, cardinalities:
} else {
visited.add(feature);
}
}
if (ast.isGroup(feature)) {
return findNextFeaturesInGroup(next as NextFeature<ast.Group>, 0, cardinalities, visited, plus)
.map(e => modifyCardinality(e, feature.cardinality, cardinalities));
} else if (ast.isAlternatives(feature) || ast.isUnorderedGroup(feature)) {
Expand Down
28 changes: 28 additions & 0 deletions packages/langium/test/lsp/completion-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,35 @@ describe('Completion within alternatives', () => {
expectedItems: ['c', 'd']
});
});
test('Should show correct keywords in completion of group', async () => {

const grammar = `
grammar g
entry Main: ('a' a+=ID | 'b' b+=ID | 'c' c+=ID)*;
hidden terminal WS: /\\s+/;
terminal ID: /\\w+/;
`;

const services = await createServicesForGrammar({ grammar });
const completion = expectCompletion(services);
const text = '<|>a id1 <|>b id2 <|>c id3';

await completion({
text,
index: 0,
expectedItems: ['a', 'b', 'c']
});
await completion({
text,
index: 1,
expectedItems: ['a', 'b', 'c']
});
await completion({
text,
index: 2,
expectedItems: ['a', 'b', 'c']
});
});
test('Should show correct cross reference and keyword in completion', async () => {

const grammar = `
Expand Down

0 comments on commit 4e96814

Please sign in to comment.