Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix links error reporting #596

Merged
merged 3 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/languageservice/services/yamlCodeLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class YamlCodeLens {
}
}
} catch (err) {
this.telemetry.sendError('yaml.codeLens.error', { error: err, documentUri: document.uri });
this.telemetry.sendError('yaml.codeLens.error', { error: err.toString() });
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/languageservice/services/yamlDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function getDefinition(document: TextDocument, params: DefinitionParams):
}
}
} catch (err) {
this.telemetry.sendError('yaml.definition.error', { error: err });
this.telemetry.sendError('yaml.definition.error', { error: err.toString() });
}

return undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/languageservice/services/yamlHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class YAMLHover {
currentDoc.currentDocIndex = currentDocIndex;
return this.getHover(document, position, currentDoc);
} catch (error) {
this.telemetry.sendError('yaml.hover.error', { error, documentUri: document.uri });
this.telemetry.sendError('yaml.hover.error', { error: error.toString() });
}
}

Expand Down
28 changes: 17 additions & 11 deletions src/languageservice/services/yamlLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
import { findLinks as JSONFindLinks } from 'vscode-json-languageservice/lib/umd/services/jsonLinks';
import { DocumentLink } from 'vscode-languageserver';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { Telemetry } from '../../languageserver/telemetry';
import { yamlDocumentsCache } from '../parser/yaml-documents';

export function findLinks(document: TextDocument): Promise<DocumentLink[]> {
try {
const doc = yamlDocumentsCache.getYamlDocument(document);
// Find links across all YAML Documents then report them back once finished
const linkPromises = [];
for (const yamlDoc of doc.documents) {
linkPromises.push(JSONFindLinks(document, yamlDoc));
export class YamlLinks {
constructor(private readonly telemetry: Telemetry) {}

findLinks(document: TextDocument): Promise<DocumentLink[]> {
try {
const doc = yamlDocumentsCache.getYamlDocument(document);
// Find links across all YAML Documents then report them back once finished
const linkPromises = [];
for (const yamlDoc of doc.documents) {
linkPromises.push(JSONFindLinks(document, yamlDoc));
}
// Wait for all the promises to return and then flatten them into one DocumentLink array
return Promise.all(linkPromises).then((yamlLinkArray) => [].concat(...yamlLinkArray));
} catch (err) {
console.warn(err.toString());
evidolob marked this conversation as resolved.
Show resolved Hide resolved
this.telemetry.sendError('yaml.documentLink.error', { error: err.toString() });
}
// Wait for all the promises to return and then flatten them into one DocumentLink array
return Promise.all(linkPromises).then((yamlLinkArray) => [].concat(...yamlLinkArray));
} catch (err) {
this.telemetry.sendError('yaml.documentLink.error', { error: err });
}
}
5 changes: 3 additions & 2 deletions src/languageservice/yamlLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { YAMLHover } from './services/yamlHover';
import { YAMLValidation } from './services/yamlValidation';
import { YAMLFormatter } from './services/yamlFormatter';
import { DocumentSymbolsContext } from 'vscode-json-languageservice';
import { findLinks } from './services/yamlLinks';
import { YamlLinks } from './services/yamlLinks';
import {
FoldingRange,
ClientCapabilities,
Expand Down Expand Up @@ -169,6 +169,7 @@ export function getLanguageService(
const formatter = new YAMLFormatter();
const yamlCodeActions = new YamlCodeActions(clientCapabilities);
const yamlCodeLens = new YamlCodeLens(schemaService, telemetry);
const yamlLinks = new YamlLinks(telemetry);
// register all commands
registerCommands(commandExecutor, connection);
return {
Expand Down Expand Up @@ -197,7 +198,7 @@ export function getLanguageService(
registerCustomSchemaProvider: (schemaProvider: CustomSchemaProvider) => {
schemaService.registerCustomSchemaProvider(schemaProvider);
},
findLinks,
findLinks: yamlLinks.findLinks.bind(yamlLinks),
doComplete: completer.doComplete.bind(completer),
doValidation: yamlValidation.doValidation.bind(yamlValidation),
doHover: hover.doHover.bind(hover),
Expand Down