Skip to content

Commit dccbf4e

Browse files
committed
Revert "feat(lsp): Add completion for the constraint reference inside value types"
This reverts commit 576d597.
1 parent 576d597 commit dccbf4e

File tree

1 file changed

+22
-71
lines changed

1 file changed

+22
-71
lines changed

libs/language-server/src/lib/lsp/jayvee-completion-provider.ts

Lines changed: 22 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
type LangiumDocument,
1212
type LangiumDocuments,
1313
type MaybePromise,
14-
type Stream,
1514
UriUtils,
1615
} from 'langium';
1716
import {
@@ -37,7 +36,6 @@ import {
3736
type ValueTypeConstraintReference,
3837
ValueTypeReference,
3938
isBlockDefinition,
40-
isConstraintDefinition,
4139
isImportDefinition,
4240
isJayveeModel,
4341
isPropertyAssignment,
@@ -85,22 +83,11 @@ export class JayveeCompletionProvider extends DefaultCompletionProvider {
8583
return this.completionForValuetype(context, acceptor);
8684
}
8785

88-
const isValueTypeConstraintReferenceDefinitionCompletion =
89-
isValueTypeConstraintReference(astNode) &&
90-
next.property === 'definition';
91-
if (isValueTypeConstraintReferenceDefinitionCompletion) {
92-
return this.completionForValueTypeConstraintDefinitionReference(
93-
astNode,
94-
context,
95-
acceptor,
96-
);
97-
}
98-
99-
const isValueTypeConstraintReferenceAttributeCompletion =
86+
const isValueTypeConstraintReferenceCompletion =
10087
isValueTypeConstraintReference(astNode) &&
10188
next.property === 'attribute';
102-
if (isValueTypeConstraintReferenceAttributeCompletion) {
103-
return this.completionForValueTypeConstraintAttributeReference(
89+
if (isValueTypeConstraintReferenceCompletion) {
90+
return this.completionForValueTypeConstraintReference(
10491
astNode,
10592
context,
10693
acceptor,
@@ -156,70 +143,34 @@ export class JayveeCompletionProvider extends DefaultCompletionProvider {
156143
});
157144
}
158145

159-
private allAstNodes(): Stream<AstNode> {
160-
return this.langiumDocuments.all
161-
.map((document) => document.parseResult.value)
162-
.flatMap((parsedDocument) => {
163-
if (!isJayveeModel(parsedDocument)) {
164-
throw new Error('Expected parsed document to be a JayveeModel');
165-
}
166-
return AstUtils.streamAllContents(parsedDocument);
167-
});
168-
}
169-
170146
private completionForValuetype(
171147
context: CompletionContext,
172148
acceptor: CompletionAcceptor,
173149
): MaybePromise<void> {
174-
this.allAstNodes()
175-
.filter(isValuetypeDefinition)
176-
.forEach((valueTypeDefinition) => {
177-
const valueType =
178-
this.wrapperFactories.ValueType.wrap(valueTypeDefinition);
179-
if (valueType !== undefined && valueType.isReferenceableByUser()) {
180-
acceptor(context, {
181-
label: valueTypeDefinition.name,
182-
kind: CompletionItemKind.Class,
183-
detail: `(valueType)`,
184-
});
185-
}
186-
});
187-
}
188-
189-
private completionForValueTypeConstraintDefinitionReference(
190-
astNode: ValueTypeConstraintReference,
191-
context: CompletionContext,
192-
acceptor: CompletionAcceptor,
193-
) {
194-
const propertyValueType = this.wrapperFactories.ValueType.wrap(
195-
astNode.$container.attribute?.valueType.reference.ref,
196-
);
197-
198-
const constraintDefinitionsWithSameValueType = this.allAstNodes()
199-
.filter(isConstraintDefinition)
200-
.filter((constraintDefinition) => {
201-
if (propertyValueType === undefined) {
202-
return true;
150+
this.langiumDocuments.all
151+
.map((document) => document.parseResult.value)
152+
.forEach((parsedDocument) => {
153+
if (!isJayveeModel(parsedDocument)) {
154+
throw new Error('Expected parsed document to be a JayveeModel');
203155
}
204-
const constraintValueType = this.wrapperFactories.ValueType.wrap(
205-
constraintDefinition.valueType.reference.ref,
156+
const allValueTypes = AstUtils.streamAllContents(parsedDocument).filter(
157+
isValuetypeDefinition,
206158
);
207-
if (constraintValueType === undefined) {
208-
return false;
209-
}
210-
return constraintValueType.equals(propertyValueType);
211-
});
212-
213-
constraintDefinitionsWithSameValueType.forEach((constraintDefinition) => {
214-
acceptor(context, {
215-
label: constraintDefinition.name,
216-
kind: CompletionItemKind.Reference,
217-
detail: '(constraint definition)',
159+
allValueTypes.forEach((valueTypeDefinition) => {
160+
const valueType =
161+
this.wrapperFactories.ValueType.wrap(valueTypeDefinition);
162+
if (valueType !== undefined && valueType.isReferenceableByUser()) {
163+
acceptor(context, {
164+
label: valueTypeDefinition.name,
165+
kind: CompletionItemKind.Class,
166+
detail: `(valueType)`,
167+
});
168+
}
169+
});
218170
});
219-
});
220171
}
221172

222-
private completionForValueTypeConstraintAttributeReference(
173+
private completionForValueTypeConstraintReference(
223174
astNode: ValueTypeConstraintReference,
224175
context: CompletionContext,
225176
acceptor: CompletionAcceptor,

0 commit comments

Comments
 (0)