Skip to content

Commit 4e96814

Browse files
authored
Fix missing group completion proposal (#1689)
1 parent 3170af9 commit 4e96814

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

packages/langium/src/lsp/completion/follow-element-computation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ function findNextFeaturesInternal(options: { next: NextFeature, cardinalities: M
5252
const feature = next.feature;
5353
if (visited.has(feature)) {
5454
return [];
55-
} else {
55+
} else if (!ast.isGroup(feature)) {
56+
// Do not add the feature to the list if it is a group
57+
// `findFirstFeaturesInternal` will take care of this
5658
visited.add(feature);
5759
}
5860
let parent: ast.Group | undefined;
@@ -132,8 +134,6 @@ function findFirstFeaturesInternal(options: { next: NextFeature, cardinalities:
132134
} else {
133135
visited.add(feature);
134136
}
135-
}
136-
if (ast.isGroup(feature)) {
137137
return findNextFeaturesInGroup(next as NextFeature<ast.Group>, 0, cardinalities, visited, plus)
138138
.map(e => modifyCardinality(e, feature.cardinality, cardinalities));
139139
} else if (ast.isAlternatives(feature) || ast.isUnorderedGroup(feature)) {

packages/langium/test/lsp/completion-provider.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,35 @@ describe('Completion within alternatives', () => {
131131
expectedItems: ['c', 'd']
132132
});
133133
});
134+
test('Should show correct keywords in completion of group', async () => {
134135

136+
const grammar = `
137+
grammar g
138+
entry Main: ('a' a+=ID | 'b' b+=ID | 'c' c+=ID)*;
139+
hidden terminal WS: /\\s+/;
140+
terminal ID: /\\w+/;
141+
`;
142+
143+
const services = await createServicesForGrammar({ grammar });
144+
const completion = expectCompletion(services);
145+
const text = '<|>a id1 <|>b id2 <|>c id3';
146+
147+
await completion({
148+
text,
149+
index: 0,
150+
expectedItems: ['a', 'b', 'c']
151+
});
152+
await completion({
153+
text,
154+
index: 1,
155+
expectedItems: ['a', 'b', 'c']
156+
});
157+
await completion({
158+
text,
159+
index: 2,
160+
expectedItems: ['a', 'b', 'c']
161+
});
162+
});
135163
test('Should show correct cross reference and keyword in completion', async () => {
136164

137165
const grammar = `

0 commit comments

Comments
 (0)