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

[vscode] Support env.onDidChangeShell event #13097

Merged
merged 1 commit into from
Nov 28, 2023

Conversation

rschnekenbu
Copy link
Contributor

What it does

Add env.onDidChangeShell event made public on vscode 1.83.
The documentation of this one was not obvious, and the doc was updated after testing on vscode side (see microsoft/vscode#194229). This event is triggered when the default profile change, it sends the shell used by this new terminal profile.

I added a sample extension to test this new API. The behavior is now similar to the one present on vscode. It provides a notification message as soon as the event is sent.

Fixes #13061

Contributed on behalf of ST Microelectronics

How to test

  1. Install the following extension on Theia master:
  1. Start browser theia
  2. On activation, an error is shown that the API is not available
  3. Switch to the branch and rebuild
  4. Starting with the extension, no more errors shall popup
  5. When using the action : Terminal: Choose the default terminal profile. A popup with the shell path for the new default profile shall popup.

Follow-ups

  • no specific follow ups

Review checklist

Reminder for reviewers

Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

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

A couple of questions.

@@ -1021,6 +1027,7 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
}

this.preferenceService.set(`terminal.integrated.defaultProfile.${OS.backend.type().toLowerCase()}`, result[0], PreferenceScope.User);
this.profileService.setDefaultProfile(result[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be necessary, see line 275 in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! I removed this line.

@@ -220,6 +220,9 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
protected readonly onDidChangeCurrentTerminalEmitter = new Emitter<TerminalWidget | undefined>();
readonly onDidChangeCurrentTerminal: Event<TerminalWidget | undefined> = this.onDidChangeCurrentTerminalEmitter.event;

protected readonly onDidChangeShellEmitter = new Emitter<string>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we routing this event through the terminal service instead of just listening to the event on the terminal profile service?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did remove this indirection, the terminalProfileService is now directly accessed.

@@ -38,3 +41,9 @@ export class ShellTerminalProfile implements TerminalProfile {
return new ShellTerminalProfile(this.terminalService, { ...this.options, ...options });
}
}

export namespace ShellTerminalProfile {
Copy link
Contributor

Choose a reason for hiding this comment

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

ShellTerminalProfile is a class, we can do an instanceof check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed namespace addition, and use instanceof when required.

import { TerminalService } from './base/terminal-service';
import { TerminalWidget, TerminalWidgetOptions } from './base/terminal-widget';
import { TerminalProfile } from './terminal-profile-service';

export class ShellTerminalProfile implements TerminalProfile {
constructor(protected readonly terminalService: TerminalService, protected readonly options: TerminalWidgetOptions) { }

readonly shellPath: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

If the shell path is optional in the options, it can't be mandatory in this variable. Something clashes here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now potentially undefined


readonly shellPath: string;

constructor(protected readonly terminalService: TerminalService, protected readonly options: TerminalWidgetOptions) { this.shellPath = options.shellPath!; }
Copy link
Contributor

Choose a reason for hiding this comment

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

We keep the options anyway, why not do a getter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, switched to a getter returning string | undefined.

Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

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

I'm happy with the code and the feature appears to work. Please resolve the conflicts and we're good to go.

contributed on behalf of STMicroelectronics

Signed-off-by: Remi Schnekenburger <[email protected]>

Address review comments
- remove indirection from TerminalService
-  change shellPath as getter rather than property
- use instanceof instead of is()
@tsmaeder tsmaeder merged commit c542676 into eclipse-theia:master Nov 28, 2023
13 of 14 checks passed
@vince-fugnitto vince-fugnitto added this to the 1.44.0 milestone Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[vscode] Support new event onDidChangeShell on env
3 participants