Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
46 changes: 46 additions & 0 deletions client-node-tests/src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,52 @@ suite('Server output', () => {
});
});

suite('Client restart', () => {

test('Preserves output channel visibility after restart', async () => {
const client = new RestartTestLanguageClient(true);

await client.restart();

assert.deepStrictEqual(client.events, ['isOutputChannelVisible', 'stop', 'start', 'restoreOutputChannelVisibility:true']);
});

test('Does not restore hidden output channel after restart', async () => {
const client = new RestartTestLanguageClient(false);

await client.restart();

assert.deepStrictEqual(client.events, ['isOutputChannelVisible', 'stop', 'start', 'restoreOutputChannelVisibility:false']);
});
});

class RestartTestLanguageClient extends lsclient.LanguageClient {

public readonly events: string[] = [];

public constructor(private readonly outputChannelVisible: boolean) {
super('test restart', { module: 'unused', transport: lsclient.TransportKind.ipc }, {});
}

public override async start(): Promise<void> {
this.events.push('start');
}

public override stop(): Promise<void> {
this.events.push('stop');
return Promise.resolve();
}

protected override isOutputChannelVisible(): boolean {
this.events.push('isOutputChannelVisible');
return this.outputChannelVisible;
}
Comment on lines +281 to +284

protected override restoreOutputChannelVisibility(wasVisible: boolean): void {
this.events.push(`restoreOutputChannelVisibility:${wasVisible}`);
}
}

suite('Client integration', () => {

let client!: lsclient.LanguageClient;
Expand Down
20 changes: 20 additions & 0 deletions client/src/common/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,26 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
return this._outputChannel;
}

protected isOutputChannelVisible(): boolean {
if (this._outputChannel === undefined) {
return false;
}
const outputChannelName = this._outputChannel.name.toLowerCase();
return Window.visibleTextEditors.some(editor => {
if (editor.document.uri.scheme !== 'output') {
return false;
}
const outputResource = `${editor.document.uri.toString(true)}\n${editor.document.fileName}`.toLowerCase();
return outputResource.includes(outputChannelName);
Comment on lines +870 to +871
});
}

protected restoreOutputChannelVisibility(wasVisible: boolean): void {
if (wasVisible) {
this.outputChannel.show(true);
}
}

public get traceOutputChannel(): LogOutputChannel {
return this._traceOutputChannel ? this._traceOutputChannel : this.outputChannel;
}
Expand Down
2 changes: 2 additions & 0 deletions client/src/node/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export class LanguageClient extends BaseLanguageClient {
}

public async restart(): Promise<void> {
const outputChannelVisible = this.isOutputChannelVisible();
await this.stop();
// We are in debug mode. Wait a little before we restart
// so that the debug port can be freed. We can safely ignore
Expand All @@ -247,6 +248,7 @@ export class LanguageClient extends BaseLanguageClient {
} else {
await this.start();
}
this.restoreOutputChannelVisibility(outputChannelVisible);
}

protected shutdown(mode: ShutdownMode, timeout: number = 2000): Promise<void> {
Expand Down