Skip to content

Preserve output channel visibility on restart - #1849

Open
Pradeep Ramola (pradeep-ramola) wants to merge 6 commits into
microsoft:mainfrom
pradeep-ramola:pradeep-ramola/preserve-output-channel-on-restart
Open

Pradeep Ramola (pradeep-ramola) wants to merge 6 commits into
microsoft:mainfrom
pradeep-ramola:pradeep-ramola/preserve-output-channel-on-restart

Conversation

@pradeep-ramola

@pradeep-ramola Pradeep Ramola (pradeep-ramola) commented Sep 2, 2026

Copy link
Copy Markdown

Summary

Preserves a language client's output channel visibility across LanguageClient.restart().

If the output channel is already visible before restart, the client shows it again after restart succeeds using show(true) so focus is preserved. If the output channel is hidden or has not been created, restart behavior is unchanged.

The visibility detector now matches VS Code log output resources by a normalized <outputChannelId>.<outputChannelName>.log resource name. outputChannelId can be supplied through LanguageClientOptions (for example, an extension id such as publisher.extension) and falls back to the language client id when omitted. This avoids treating another visible output channel with the same display name, or an extension id containing the channel name, as this client's output channel. It also handles channel names that VS Code sanitizes in log file names.

This moves the behavior requested in microsoft/vscode-eslint#2206 into the shared LSP client library so other clients can benefit from it too.

Validation

  • npm run compile:client
  • npm run compile:client-node-tests
  • npm run lint --prefix client
  • npm run lint --prefix client-node-tests
  • npm run test --prefix client-node-tests (211 passing)

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Output-channel matching is unreliable, and the tests bypass that detection logic.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Preserves a language client’s output-channel visibility across successful restarts.

Changes:

  • Detects whether the output channel is visible before stopping.
  • Restores visible channels without stealing focus.
  • Adds restart sequencing tests.
File summaries
File Description
client/src/node/main.ts Captures and restores visibility around restart.
client/src/common/client.ts Implements visibility detection and restoration.
client-node-tests/src/integration.test.ts Adds restart behavior tests.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread client/src/common/client.ts Outdated
Comment thread client-node-tests/src/integration.test.ts Outdated
@dbaeumer

Copy link
Copy Markdown
Member

Pradeep Ramola (@pradeep-ramola) can you have a look at the copilot comments.

@pradeep-ramola

Copy link
Copy Markdown
Author

Addressed the Copilot review comments in 77348094.

What changed:

  • Replaced the substring-based output-channel visibility check with a normalized log resource suffix match. This uses the same invalid filename character removal VS Code applies when creating log output channel resources.
  • Added a protected getVisibleTextEditors() wrapper so tests can exercise the real isOutputChannelVisible() detector without overriding it.
  • Expanded restart/detector coverage for a matching visible output document, a hidden channel with another visible output document whose extension id contains the channel name, and a sanitized channel name such as C/C++.

Validated locally with:

  • npm run compile:client
  • npm run compile:client-node-tests
  • npm run lint --prefix client
  • npm run lint --prefix client-node-tests
  • npm run test --prefix client-node-tests (207 passing)

@pradeep-ramola

Copy link
Copy Markdown
Author

Resolved the merge conflict with current main in 892c8683.

The conflict was in client-node-tests/src/integration.test.ts; I kept both the restart coverage from this PR and the upstream socket transport test added on main.

Validation after resolving conflicts:

  • npm run compile:client
  • npm run compile:client-node-tests
  • npm run lint --prefix client
  • npm run lint --prefix client-node-tests
  • npm run test --prefix client-node-tests (208 passing)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Name-only suffix matching can incorrectly identify another extension’s same-named output channel.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread client/src/common/client.ts Outdated
@pradeep-ramola

Copy link
Copy Markdown
Author

Addressed the latest Copilot comment in b8979147.

What changed:

  • Added LanguageClientOptions.outputChannelId so callers can provide the VS Code log output resource prefix, for example the extension id publisher.extension.
  • Updated output channel visibility detection to match <outputChannelId>.<sanitized output channel name>.log instead of only <sanitized output channel name>.log.
  • Added coverage for a same-name output channel from another extension, matching by file name, defaulting to the language client id, and sanitized names like C/C++.

Validated locally with:

  • npm run compile:client
  • npm run compile:client-node-tests
  • npm run lint --prefix client
  • npm run lint --prefix client-node-tests
  • npm run test --prefix client-node-tests (211 passing)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Case-insensitive matching can confuse distinct case-sensitive output-channel names.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

Comment thread client/src/common/client.ts
@dbaeumer

Copy link
Copy Markdown
Member

Pradeep Ramola (@pradeep-ramola) see latest Copilot comments. They do make sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants