|
5 | 5 | import { findLinks as JSONFindLinks } from 'vscode-json-languageservice/lib/umd/services/jsonLinks';
|
6 | 6 | import { DocumentLink } from 'vscode-languageserver';
|
7 | 7 | import { TextDocument } from 'vscode-languageserver-textdocument';
|
| 8 | +import { Telemetry } from '../../languageserver/telemetry'; |
8 | 9 | import { yamlDocumentsCache } from '../parser/yaml-documents';
|
9 | 10 |
|
10 |
| -export function findLinks(document: TextDocument): Promise<DocumentLink[]> { |
11 |
| - try { |
12 |
| - const doc = yamlDocumentsCache.getYamlDocument(document); |
13 |
| - // Find links across all YAML Documents then report them back once finished |
14 |
| - const linkPromises = []; |
15 |
| - for (const yamlDoc of doc.documents) { |
16 |
| - linkPromises.push(JSONFindLinks(document, yamlDoc)); |
| 11 | +export class YamlLinks { |
| 12 | + constructor(private readonly telemetry: Telemetry) {} |
| 13 | + |
| 14 | + findLinks(document: TextDocument): Promise<DocumentLink[]> { |
| 15 | + try { |
| 16 | + const doc = yamlDocumentsCache.getYamlDocument(document); |
| 17 | + // Find links across all YAML Documents then report them back once finished |
| 18 | + const linkPromises = []; |
| 19 | + for (const yamlDoc of doc.documents) { |
| 20 | + linkPromises.push(JSONFindLinks(document, yamlDoc)); |
| 21 | + } |
| 22 | + // Wait for all the promises to return and then flatten them into one DocumentLink array |
| 23 | + return Promise.all(linkPromises).then((yamlLinkArray) => [].concat(...yamlLinkArray)); |
| 24 | + } catch (err) { |
| 25 | + this.telemetry.sendError('yaml.documentLink.error', { error: err.toString() }); |
17 | 26 | }
|
18 |
| - // Wait for all the promises to return and then flatten them into one DocumentLink array |
19 |
| - return Promise.all(linkPromises).then((yamlLinkArray) => [].concat(...yamlLinkArray)); |
20 |
| - } catch (err) { |
21 |
| - this.telemetry.sendError('yaml.documentLink.error', { error: err }); |
22 | 27 | }
|
23 | 28 | }
|
0 commit comments