|
1 | 1 | import { AstNode } from 'langium' |
2 | | -import { AbstractSemanticTokenProvider, SemanticTokenAcceptor } from 'langium/lsp' |
3 | | -import { |
4 | | - ContextMappingModel, |
5 | | - isContextMappingModel |
6 | | -} from '../generated/ast.js' |
7 | | -import { ContextMapSemanticTokenProvider } from './contextMap/ContextMapSemanticTokenProvider.js' |
8 | | -import { SemanticTokenTypes } from 'vscode-languageserver-types' |
9 | | -import { BoundedContextSemanticTokenProvider } from './boundedContext/BoundedContextSemanticTokenProvider.js' |
10 | | -import { DomainSemanticTokenProvider } from './domain/DomainSemanticTokenProvider.js' |
11 | | -import { AggregateSemanticTokenProvider } from './boundedContext/AggregateSemanticTokenProvider.js' |
12 | | -import { RequirementsSemanticTokenProvider } from './requirements/RequirementsSemanticTokenProvider.js' |
13 | | -import { ValueSemanticTokenProvider } from './vdad/ValueSemanticTokenProvider.js' |
14 | | -import { ContextMapperSemanticTokenProvider } from './ContextMapperSemanticTokenProvider.js' |
15 | | -import { SculptorModuleSemanticTokenProvider } from './boundedContext/SculptorModuleSemanticTokenProvider.js' |
16 | | -import { RelationshipSemanticTokenProvider } from './contextMap/RelationshipSemanticTokenProvider.js' |
17 | | -import { FeatureSemanticTokenProvider } from './requirements/FeatureSemanticTokenProvider.js' |
18 | | -import { StoryValuationSemanticTokenProvider } from './requirements/StoryValuationSemanticTokenProvider.js' |
19 | | -import { AbstractStakeholderSemanticTokenProvider } from './vdad/AbstractStakeholderSemanticTokenProvider.js' |
20 | | -import { ActionSemanticTokenProvider } from './vdad/ActionSemanticTokenProvider.js' |
21 | | -import { ConsequenceSemanticTokenProvider } from './vdad/ConsequenceSemanticTokenProvider.js' |
22 | | -import { StakeholderSemanticTokenProvider } from './vdad/StakeholderSemanticTokenProvider.js' |
23 | | -import { ValueClusterSemanticTokenProvider } from './vdad/ValueClusterSemanticTokenProvider.js' |
24 | | -import { ValueElicitationSemanticTokenProvider } from './vdad/ValueElicitationSemanticTokenProvider.js' |
25 | | -import { ValueEpicSemanticTokenProvider } from './vdad/ValueEpicSemanticTokenProvider.js' |
26 | | -import { ValueNarrativeSemanticTokenProvider } from './vdad/ValueNarrativeSemanticTokenProvider.js' |
27 | | -import { ValueRegisterSemanticTokenProvider } from './vdad/ValueRegisterSemanticTokenProvider.js' |
28 | | -import { ValueWeightingSemanticTokenProvider } from './vdad/ValueWeightingSemanticTokenProvider.js' |
| 2 | +import { AbstractSemanticTokenProvider, LangiumServices, SemanticTokenAcceptor } from 'langium/lsp' |
| 3 | +import { SemanticTokenProviderRegistry } from './SemanticTokenProviderRegistry.js' |
29 | 4 |
|
30 | 5 | export class ContextMapperDslSemanticTokenProvider extends AbstractSemanticTokenProvider { |
31 | | - private readonly semanticTokenProviders: ContextMapperSemanticTokenProvider<AstNode>[] = [ |
32 | | - new AggregateSemanticTokenProvider(), |
33 | | - new BoundedContextSemanticTokenProvider(), |
34 | | - new SculptorModuleSemanticTokenProvider(), |
35 | | - new ContextMapSemanticTokenProvider(), |
36 | | - new RelationshipSemanticTokenProvider(), |
37 | | - new DomainSemanticTokenProvider(), |
38 | | - new FeatureSemanticTokenProvider(), |
39 | | - new RequirementsSemanticTokenProvider(), |
40 | | - new StoryValuationSemanticTokenProvider(), |
41 | | - new AbstractStakeholderSemanticTokenProvider(), |
42 | | - new ActionSemanticTokenProvider(), |
43 | | - new ConsequenceSemanticTokenProvider(), |
44 | | - new StakeholderSemanticTokenProvider(), |
45 | | - new ValueClusterSemanticTokenProvider(), |
46 | | - new ValueElicitationSemanticTokenProvider(), |
47 | | - new ValueEpicSemanticTokenProvider(), |
48 | | - new ValueNarrativeSemanticTokenProvider(), |
49 | | - new ValueRegisterSemanticTokenProvider(), |
50 | | - new ValueSemanticTokenProvider(), |
51 | | - new ValueWeightingSemanticTokenProvider() |
52 | | - ] |
| 6 | + private readonly semanticTokenProviderRegistry: SemanticTokenProviderRegistry |
53 | 7 |
|
54 | | - protected override highlightElement (node: AstNode, acceptor: SemanticTokenAcceptor) { |
55 | | - if (isContextMappingModel(node)) { |
56 | | - if (node.$cstNode) { |
57 | | - this.highlightComments(/\/\*[\s\S]*?\*\//g, node, acceptor) |
58 | | - this.highlightComments(/\/\/[^\n\r]*/g, node, acceptor) |
59 | | - } |
60 | | - } else { |
61 | | - for (const provider of this.semanticTokenProviders) { |
62 | | - if (provider.supports(node)) { |
63 | | - provider.highlight(node, acceptor) |
64 | | - return |
65 | | - } |
66 | | - } |
67 | | - |
68 | | - console.error('Uncaught node type', node.$type) |
69 | | - } |
| 8 | + constructor (services: LangiumServices, registry: SemanticTokenProviderRegistry) { |
| 9 | + super(services) |
| 10 | + this.semanticTokenProviderRegistry = registry |
70 | 11 | } |
71 | 12 |
|
72 | | - private highlightComments (regex: RegExp, node: ContextMappingModel, acceptor: SemanticTokenAcceptor) { |
73 | | - if (node.$document == null) { |
74 | | - throw new Error('Document not found') |
75 | | - } |
76 | | - const text = node.$document.textDocument.getText() |
77 | | - for (const match of text.matchAll(regex)) { |
78 | | - if (match?.index == null) { |
79 | | - continue |
80 | | - } |
81 | | - const position = node.$document.textDocument.positionAt(match.index) |
82 | | - acceptor({ |
83 | | - type: SemanticTokenTypes.comment, |
84 | | - line: position.line, |
85 | | - char: position.character, |
86 | | - length: match[0].length |
87 | | - }) |
| 13 | + protected override highlightElement (node: AstNode, acceptor: SemanticTokenAcceptor) { |
| 14 | + const semanticTokenProvider = this.semanticTokenProviderRegistry.get(node) |
| 15 | + if (semanticTokenProvider) { |
| 16 | + semanticTokenProvider.highlight(node, acceptor) |
| 17 | + } else { |
| 18 | + console.error('Node type with no token provider', node.$type) |
88 | 19 | } |
89 | 20 | } |
90 | 21 | } |
0 commit comments