Skip to content

Commit cfe0b00

Browse files
committed
add scope provider to fix linker errors
1 parent 4805133 commit cfe0b00

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/language/ContextMapperDslModule.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ContextMapperDslSemanticTokenProvider } from './semantictokens/ContextM
1313
import { SemanticTokenProviderRegistry } from './semantictokens/SemanticTokenProviderRegistry.js'
1414
import { ContextMapperDslValidationRegistry } from './validation/ContextMapperDslValidationRegistry.js'
1515
import { ContextMapperValidationProviderRegistry } from './validation/ContextMapperValidationProviderRegistry.js'
16+
import { ContextMapperDslScopeProvider } from './references/ContextMapperDslScopeProvider.js'
1617

1718
/**
1819
* Declaration of custom services - add your own service classes here.
@@ -47,6 +48,9 @@ export const ContextMapperDslModule: Module<ContextMapperDslServices, ModuleType
4748
},
4849
lsp: {
4950
SemanticTokenProvider: (services) => new ContextMapperDslSemanticTokenProvider(services, semanticTokenProviderRegistry)
51+
},
52+
references: {
53+
ScopeProvider: (services) => new ContextMapperDslScopeProvider(services)
5054
}
5155
}
5256

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { AstUtils, DefaultScopeProvider, ReferenceInfo, Scope } from 'langium'
2+
import {
3+
AbstractStakeholder,
4+
Aggregate,
5+
DomainPart,
6+
isContextMappingModel,
7+
isStakeholderGroup, StakeholderGroup
8+
} from '../generated/ast.js'
9+
10+
export class ContextMapperDslScopeProvider extends DefaultScopeProvider {
11+
override getScope (context: ReferenceInfo): Scope {
12+
const referenceType = this.reflection.getReferenceType(context)
13+
const model = AstUtils.getContainerOfType(context.container, isContextMappingModel)!
14+
15+
if (referenceType === DomainPart) {
16+
const domainPartDescriptions = model.domains.map(d => this.descriptions.createDescription(d, d.name))
17+
.concat(
18+
model.domains.flatMap(d => d.subdomains)
19+
.map(sd => this.descriptions.createDescription(sd, sd.name))
20+
)
21+
return this.createScope(domainPartDescriptions)
22+
}
23+
24+
if (referenceType === Aggregate) {
25+
const aggregateDescriptions = model.boundedContexts.flatMap(bc => bc.aggregates)
26+
.map(a => this.descriptions.createDescription(a, a.name))
27+
.concat(
28+
model.boundedContexts.flatMap(bc => bc.modules)
29+
.flatMap(m => m.aggregates)
30+
.map(a => this.descriptions.createDescription(a, a.name))
31+
)
32+
return this.createScope(aggregateDescriptions)
33+
}
34+
35+
if (referenceType === AbstractStakeholder) {
36+
const stakeholderDescriptions = model.stakeholders.flatMap(s => s.stakeholders)
37+
.map(s => this.descriptions.createDescription(s, s.name))
38+
.concat(
39+
model.stakeholders.flatMap(s => s.stakeholders)
40+
.filter(s => isStakeholderGroup(s))
41+
.flatMap(sg => (sg as StakeholderGroup).stakeholders)
42+
.map(s => this.descriptions.createDescription(s, s.name))
43+
)
44+
return this.createScope(stakeholderDescriptions)
45+
}
46+
47+
return super.getScope(context)
48+
}
49+
}

0 commit comments

Comments
 (0)