Skip to content

Commit b8594ec

Browse files
committed
Use an output channel to log error message #326
Signed-off-by: Aurélien Pupier <apupier@redhat.com>
1 parent 8f2ca66 commit b8594ec

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/extension.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import * as path from 'path';
1010

11-
import { workspace, ExtensionContext, extensions } from 'vscode';
11+
import { workspace, ExtensionContext, extensions, OutputChannel, window } from 'vscode';
1212
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, NotificationType } from 'vscode-languageclient';
1313
import { URI } from 'vscode-uri';
1414
import { CUSTOM_SCHEMA_REQUEST, CUSTOM_CONTENT_REQUEST, SchemaExtensionAPI } from './schema-extension-api';
@@ -25,6 +25,8 @@ namespace DynamicCustomSchemaRequestRegistration {
2525
export const type: NotificationType<{}, {}> = new NotificationType('yaml/registerCustomSchemaRequest');
2626
}
2727

28+
let outputChannel: OutputChannel;
29+
2830
export function activate(context: ExtensionContext) {
2931
// The YAML language server is implemented in node
3032
let serverModule = context.asAbsolutePath(path.join('node_modules', 'yaml-language-server', 'out', 'server', 'src', 'server.js'));
@@ -131,3 +133,10 @@ function getSchemaAssociation(context: ExtensionContext): ISchemaAssociations {
131133

132134
return associations;
133135
}
136+
137+
export function logToExtensionOutputChannel(message: string) {
138+
if(outputChannel === undefined){
139+
outputChannel = window.createOutputChannel('VS Code Yaml extension');
140+
}
141+
outputChannel.appendLine(message);
142+
}

src/schema-extension-api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { URI } from 'vscode-uri'
22
import { LanguageClient, RequestType } from 'vscode-languageclient';
33
import { workspace } from 'vscode';
4+
import { logToExtensionOutputChannel } from './extension';
45

56
interface SchemaContributorProvider {
67
readonly requestSchema: (resource: string) => string;
@@ -113,7 +114,7 @@ class SchemaExtensionAPI implements ExtensionAPI {
113114
matches.push(uri);
114115
}
115116
} catch (error) {
116-
console.log(`Error thrown while requesting schema ` + error);
117+
logToExtensionOutputChannel(`Error thrown while requesting schema "${error}" when calling the registered contributor "${customKey}"`);
117118
}
118119
}
119120
return matches;

0 commit comments

Comments
 (0)