Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing group proposal #1689

Merged
merged 3 commits into from
Dec 4, 2024
Merged
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
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
Loading