Skip to content

Commit

Permalink
Add optional languageId to window.createOutputChannel API (microsoft#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gjsjohnmurray committed Jan 17, 2022
1 parent 4135ba2 commit 1ecb5f5
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/vs/workbench/api/browser/mainThreadOutputService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export class MainThreadOutputService extends Disposable implements MainThreadOut
setVisibleChannel();
}

public async $register(label: string, log: boolean, file: UriComponents, extensionId: string): Promise<string> {
public async $register(label: string, log: boolean, file: UriComponents, languageId: string, extensionId: string): Promise<string> {
const idCounter = (MainThreadOutputService._extensionIdPool.get(extensionId) || 0) + 1;
MainThreadOutputService._extensionIdPool.set(extensionId, idCounter);
const id = `extension-output-${extensionId}-#${idCounter}`;

Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).registerChannel({ id, label, file: URI.revive(file), log });
Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).registerChannel({ id, label, file: URI.revive(file), log, languageId });
this._register(toDisposable(() => this.$dispose(id)));
return id;
}
Expand Down
7 changes: 5 additions & 2 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,11 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
withProgress<R>(options: vscode.ProgressOptions, task: (progress: vscode.Progress<{ message?: string; worked?: number }>, token: vscode.CancellationToken) => Thenable<R>) {
return extHostProgress.withProgress(extension, options, task);
},
createOutputChannel(name: string): vscode.OutputChannel {
return extHostOutputService.createOutputChannel(name, extension);
createOutputChannel(name: string, languageId?: string): vscode.OutputChannel {
if (languageId) {
checkProposedApiEnabled(extension, 'outputChannelLanguage');
}
return extHostOutputService.createOutputChannel(name, languageId || '', extension);
},
createWebviewPanel(viewType: string, title: string, showOptions: vscode.ViewColumn | { viewColumn: vscode.ViewColumn, preserveFocus?: boolean }, options?: vscode.WebviewPanelOptions & vscode.WebviewOptions): vscode.WebviewPanel {
return extHostWebviewPanels.createWebviewPanel(extension, viewType, title, showOptions, options);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ export interface MainThreadMessageServiceShape extends IDisposable {
}

export interface MainThreadOutputServiceShape extends IDisposable {
$register(label: string, log: boolean, file: UriComponents, extensionId: string): Promise<string>;
$register(label: string, log: boolean, file: UriComponents, languageId: string, extensionId: string): Promise<string>;
$update(channelId: string, mode: OutputChannelUpdateMode.Append): Promise<void>;
$update(channelId: string, mode: OutputChannelUpdateMode, till: number): Promise<void>;
$reveal(channelId: string, preserveFocus: boolean): Promise<void>;
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/api/common/extHostOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,24 @@ export class ExtHostOutputService implements ExtHostOutputServiceShape {
}
}

createOutputChannel(name: string, extension: IExtensionDescription): vscode.OutputChannel {
createOutputChannel(name: string, languageId: string, extension: IExtensionDescription): vscode.OutputChannel {
name = name.trim();
if (!name) {
throw new Error('illegal argument `name`. must not be falsy');
}
const extHostOutputChannel = this.doCreateOutputChannel(name, extension);
const extHostOutputChannel = this.doCreateOutputChannel(name, languageId, extension);
extHostOutputChannel.then(channel => {
this.channels.set(channel.id, channel);
channel.visible = channel.id === this.visibleChannelId;
});
return this.createExtHostOutputChannel(name, extHostOutputChannel);
}

private async doCreateOutputChannel(name: string, extension: IExtensionDescription): Promise<ExtHostOutputChannel> {
private async doCreateOutputChannel(name: string, languageId: string, extension: IExtensionDescription): Promise<ExtHostOutputChannel> {
const outputDir = await this.createOutputDirectory();
const file = this.extHostFileSystemInfo.extUri.joinPath(outputDir, `${this.namePool++}-${name.replace(/[\\/:\*\?"<>\|]/g, '')}.log`);
const logger = this.loggerService.createLogger(file, { always: true, donotRotate: true, donotUseFormatters: true });
const id = await this.proxy.$register(name, false, file, extension.identifier.value);
const id = await this.proxy.$register(name, false, file, languageId, extension.identifier.value);
return new ExtHostOutputChannel(id, name, logger, this.proxy);
}

Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/output/browser/outputServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class OutputChannel extends Disposable implements IOutputChannel {
this.id = outputChannelDescriptor.id;
this.label = outputChannelDescriptor.label;
this.uri = URI.from({ scheme: OUTPUT_SCHEME, path: this.id });
this.model = this._register(outputChannelModelService.createOutputChannelModel(this.id, this.uri, outputChannelDescriptor.log ? LOG_MIME : OUTPUT_MIME, outputChannelDescriptor.file));
this.model = this._register(outputChannelModelService.createOutputChannelModel(this.id, this.uri, outputChannelDescriptor.log ? LOG_MIME : OUTPUT_MIME, outputChannelDescriptor.file, outputChannelDescriptor.languageId));
}

append(output: string): void {
Expand Down Expand Up @@ -216,7 +216,7 @@ export class LogContentProvider {
const channelDisposables: IDisposable[] = [];
const outputChannelDescriptor = this.outputService.getChannelDescriptors().filter(({ id }) => id === channelId)[0];
if (outputChannelDescriptor && outputChannelDescriptor.file) {
channelModel = this.outputChannelModelService.createOutputChannelModel(channelId, resource, outputChannelDescriptor.log ? LOG_MIME : OUTPUT_MIME, outputChannelDescriptor.file);
channelModel = this.outputChannelModelService.createOutputChannelModel(channelId, resource, outputChannelDescriptor.log ? LOG_MIME : OUTPUT_MIME, outputChannelDescriptor.file, outputChannelDescriptor.languageId);
channelModel.onDispose(() => dispose(channelDisposables), channelDisposables);
this.channelModels.set(channelId, channelModel);
}
Expand Down
13 changes: 8 additions & 5 deletions src/vs/workbench/contrib/output/common/outputChannelModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class FileOutputChannelModel extends Disposable implements IOutputChannel
private readonly modelUri: URI,
private readonly mimeType: 'text/x-code-log-output' | 'text/x-code-output',
private readonly file: URI,
private readonly languageId: string,
@IFileService private readonly fileService: IFileService,
@IModelService private readonly modelService: IModelService,
@ILanguageService private readonly languageService: ILanguageService,
Expand Down Expand Up @@ -163,7 +164,7 @@ export class FileOutputChannelModel extends Disposable implements IOutputChannel
if (this.model) {
this.model.setValue(content);
} else {
this.model = this.modelService.createModel(content, this.languageService.createByMimeType(this.mimeType), this.modelUri);
this.model = this.modelService.createModel(content, this.languageId ? this.languageService.createById(this.languageId) : this.languageService.createByMimeType(this.mimeType), this.modelUri);
this.fileHandler.watch(this.etag);
const disposable = this.model.onWillDispose(() => {
this.cancelModelUpdate();
Expand Down Expand Up @@ -326,14 +327,15 @@ class OutputChannelBackedByFile extends FileOutputChannelModel implements IOutpu
modelUri: URI,
mimeType: 'text/x-code-log-output' | 'text/x-code-output',
file: URI,
languageId: string,
@IFileService fileService: IFileService,
@IModelService modelService: IModelService,
@ILanguageService languageService: ILanguageService,
@ILoggerService loggerService: ILoggerService,
@ILogService logService: ILogService,
@IEditorWorkerService editorWorkerService: IEditorWorkerService
) {
super(modelUri, mimeType, file, fileService, modelService, languageService, logService, editorWorkerService);
super(modelUri, mimeType, file, languageId, fileService, modelService, languageService, logService, editorWorkerService);

// Donot rotate to check for the file reset
this.logger = loggerService.createLogger(file, { always: true, donotRotate: true, donotUseFormatters: true });
Expand Down Expand Up @@ -373,18 +375,19 @@ export class DelegatedOutputChannelModel extends Disposable implements IOutputCh
modelUri: URI,
mimeType: 'text/x-code-log-output' | 'text/x-code-output',
outputDir: Promise<URI>,
languageId: string,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IFileService private readonly fileService: IFileService,
) {
super();
this.outputChannelModel = this.createOutputChannelModel(id, modelUri, mimeType, outputDir);
this.outputChannelModel = this.createOutputChannelModel(id, modelUri, mimeType, outputDir, languageId);
}

private async createOutputChannelModel(id: string, modelUri: URI, mimeType: 'text/x-code-log-output' | 'text/x-code-output', outputDirPromise: Promise<URI>): Promise<IOutputChannelModel> {
private async createOutputChannelModel(id: string, modelUri: URI, mimeType: 'text/x-code-log-output' | 'text/x-code-output', outputDirPromise: Promise<URI>, languageId: string): Promise<IOutputChannelModel> {
const outputDir = await outputDirPromise;
const file = resources.joinPath(outputDir, `${id.replace(/[\\/:\*\?"<>\|]/g, '')}.log`);
await this.fileService.createFile(file);
const outputChannelModel = this._register(this.instantiationService.createInstance(OutputChannelBackedByFile, id, modelUri, mimeType, file));
const outputChannelModel = this._register(this.instantiationService.createInstance(OutputChannelBackedByFile, id, modelUri, mimeType, file, languageId));
this._register(outputChannelModel.onDispose(() => this._onDispose.fire()));
return outputChannelModel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const IOutputChannelModelService = createDecorator<IOutputChannelModelSer
export interface IOutputChannelModelService {
readonly _serviceBrand: undefined;

createOutputChannelModel(id: string, modelUri: URI, mimeType: 'text/x-code-log-output' | 'text/x-code-output', file?: URI): IOutputChannelModel;
createOutputChannelModel(id: string, modelUri: URI, mimeType: 'text/x-code-log-output' | 'text/x-code-output', file?: URI, languageId?: string): IOutputChannelModel;

}

Expand All @@ -31,8 +31,8 @@ export abstract class AbstractOutputChannelModelService {
@IInstantiationService protected readonly instantiationService: IInstantiationService
) { }

createOutputChannelModel(id: string, modelUri: URI, mimeType: 'text/x-code-log-output' | 'text/x-code-output', file?: URI): IOutputChannelModel {
return file ? this.instantiationService.createInstance(FileOutputChannelModel, modelUri, mimeType, file) : this.instantiationService.createInstance(DelegatedOutputChannelModel, id, modelUri, mimeType, this.outputDir);
createOutputChannelModel(id: string, modelUri: URI, mimeType: 'text/x-code-log-output' | 'text/x-code-output', file?: URI, languageId?: string): IOutputChannelModel {
return file ? this.instantiationService.createInstance(FileOutputChannelModel, modelUri, mimeType, file, languageId || '') : this.instantiationService.createInstance(DelegatedOutputChannelModel, id, modelUri, mimeType, this.outputDir, languageId || '');
}

private _outputDir: Promise<URI> | null = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const allApiProposals = Object.freeze({
notebookLiveShare: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookLiveShare.d.ts',
notebookMessaging: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookMessaging.d.ts',
notebookMime: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookMime.d.ts',
outputChannelLanguage: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.outputChannelLanguage.d.ts',
portsAttributes: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.portsAttributes.d.ts',
quickPickSeparators: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.quickPickSeparators.d.ts',
quickPickSortByLabel: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.quickPickSortByLabel.d.ts',
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/services/output/common/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface IOutputChannelDescriptor {
label: string;
log: boolean;
file?: URI;
languageId?: string;
}

export interface IFileOutputChannelDescriptor extends IOutputChannelDescriptor {
Expand Down
20 changes: 20 additions & 0 deletions src/vscode-dts/vscode.proposed.outputChannelLanguage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// https://github.com/microsoft/vscode/issues/19561

declare module 'vscode' {

export namespace window {

/**
* Creates a new {@link OutputChannel output channel} with the given name.
*
* @param name Human-readable string which will be used to represent the channel in the UI.
* @param languageId The identifier of the language associated with the channel.
*/
export function createOutputChannel(name: string, languageId?: string): OutputChannel;
}
}

0 comments on commit 1ecb5f5

Please sign in to comment.