|
| 1 | +import { AttributeValueCompletionOptions, SuggestionProviders } from '@xml-tools/content-assist'; |
| 2 | +import { XmlDefinitionProvider } from './XmlDefinitionProvider'; |
| 3 | +import { LocationLink, Uri, Range } from 'vscode'; |
| 4 | +import ModuleIndexer from 'indexer/module/ModuleIndexer'; |
| 5 | +import IndexManager from 'indexer/IndexManager'; |
| 6 | + |
| 7 | +export class XmlModuleDefinitionProvider extends XmlDefinitionProvider { |
| 8 | + public getFilePatterns(): string[] { |
| 9 | + return ['**/etc/module.xml', '**/etc/**/routes.xml']; |
| 10 | + } |
| 11 | + |
| 12 | + public getDefinitionProviders(): SuggestionProviders<LocationLink> { |
| 13 | + return { |
| 14 | + attributeValue: [this.getModuleDefinitions], |
| 15 | + }; |
| 16 | + } |
| 17 | + |
| 18 | + private getModuleDefinitions({ |
| 19 | + element, |
| 20 | + attribute, |
| 21 | + }: AttributeValueCompletionOptions<undefined>): LocationLink[] { |
| 22 | + if (element.name !== 'module' || attribute.key !== 'name') { |
| 23 | + return []; |
| 24 | + } |
| 25 | + |
| 26 | + const moduleName = attribute.value; |
| 27 | + |
| 28 | + if (!moduleName) { |
| 29 | + return []; |
| 30 | + } |
| 31 | + |
| 32 | + const moduleIndexData = IndexManager.getIndexData(ModuleIndexer.KEY); |
| 33 | + |
| 34 | + if (!moduleIndexData) { |
| 35 | + return []; |
| 36 | + } |
| 37 | + |
| 38 | + const module = moduleIndexData.getModule(moduleName); |
| 39 | + |
| 40 | + if (!module) { |
| 41 | + return []; |
| 42 | + } |
| 43 | + |
| 44 | + const moduleXmlUri = Uri.file(module.moduleXmlPath); |
| 45 | + |
| 46 | + return [ |
| 47 | + { |
| 48 | + targetUri: moduleXmlUri, |
| 49 | + targetRange: new Range(0, 0, 0, 0), |
| 50 | + originSelectionRange: new Range( |
| 51 | + attribute.position.startLine - 1, |
| 52 | + attribute.position.startColumn + 5, |
| 53 | + attribute.position.endLine - 1, |
| 54 | + attribute.position.endColumn - 1 |
| 55 | + ), |
| 56 | + }, |
| 57 | + ]; |
| 58 | + } |
| 59 | +} |
0 commit comments