|
| 1 | +import { Hover, MarkdownString, Uri, Range, workspace, TextDocument } from 'vscode'; |
| 2 | +import IndexManager from 'indexer/IndexManager'; |
| 3 | +import { CombinedCondition, XmlSuggestionProvider } from 'common/xml/XmlSuggestionProvider'; |
| 4 | +import { ElementNameMatches } from 'common/xml/suggestion/condition/ElementNameMatches'; |
| 5 | +import { XMLElement, XMLAttribute } from '@xml-tools/ast'; |
| 6 | +import ThemeIndexer from 'indexer/theme/ThemeIndexer'; |
| 7 | +import path from 'path'; |
| 8 | + |
| 9 | +export class ThemeHoverProvider extends XmlSuggestionProvider<Hover> { |
| 10 | + public getElementContentMatches(): CombinedCondition[] { |
| 11 | + return [[new ElementNameMatches('parent')]]; |
| 12 | + } |
| 13 | + |
| 14 | + public getConfigKey(): string | undefined { |
| 15 | + return 'provideXmlHovers'; |
| 16 | + } |
| 17 | + |
| 18 | + public getFilePatterns(): string[] { |
| 19 | + return ['**/theme.xml']; |
| 20 | + } |
| 21 | + |
| 22 | + public getSuggestionItems( |
| 23 | + value: string, |
| 24 | + range: Range, |
| 25 | + document: TextDocument, |
| 26 | + element: XMLElement, |
| 27 | + attribute?: XMLAttribute |
| 28 | + ): Hover[] { |
| 29 | + const workspaceFolder = workspace.getWorkspaceFolder(document.uri); |
| 30 | + |
| 31 | + if (!workspaceFolder) { |
| 32 | + return []; |
| 33 | + } |
| 34 | + |
| 35 | + const themeIndexData = IndexManager.getIndexData(ThemeIndexer.KEY); |
| 36 | + |
| 37 | + if (!themeIndexData) { |
| 38 | + return []; |
| 39 | + } |
| 40 | + |
| 41 | + const theme = themeIndexData.getThemeById(value); |
| 42 | + |
| 43 | + if (!theme) { |
| 44 | + return []; |
| 45 | + } |
| 46 | + |
| 47 | + const markdown = new MarkdownString(); |
| 48 | + markdown.appendMarkdown(`**Theme**: ${theme.title}\n\n`); |
| 49 | + markdown.appendMarkdown(`- ID: \`${theme.id}\`\n\n`); |
| 50 | + |
| 51 | + const relativePath = path.relative(workspaceFolder.uri.fsPath, theme.path); |
| 52 | + |
| 53 | + markdown.appendMarkdown(`- Path: \`${relativePath}\`\n\n`); |
| 54 | + |
| 55 | + if (theme.parent) { |
| 56 | + markdown.appendMarkdown(`- Parent: \n\n - ${theme.parent}\n\n`); |
| 57 | + } |
| 58 | + |
| 59 | + markdown.appendMarkdown(`[theme.xml](${Uri.file(theme.path)})`); |
| 60 | + |
| 61 | + return [new Hover(markdown, range)]; |
| 62 | + } |
| 63 | +} |
0 commit comments