Skip to content

Commit

Permalink
[vscode] Support EnvironmentVariableCollection description #12696
Browse files Browse the repository at this point in the history
* implement enhanced preview for terminal widget
* remove terminal info toolbar item

Contributed on behalf of STMicroelectronics

Signed-off-by: Johannes Faltermeier <[email protected]>
  • Loading branch information
jfaltermeier committed Aug 24, 2023
1 parent 81de14d commit bab13b9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 132 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/browser/shell/tab-bars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ export class TabBarRenderer extends TabBar.Renderer {
const hover = this.tabBar && (this.tabBar.orientation === 'horizontal' && this.corePreferences?.['window.tabbar.enhancedPreview'] === 'classic')
? { title: title.caption }
: {
onmouseenter: this.handleMouseEnterEvent
};
onmouseenter: this.handleMouseEnterEvent
};

return h.li(
{
Expand Down
16 changes: 1 addition & 15 deletions packages/terminal/src/browser/terminal-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import {
ApplicationShell, KeybindingContribution, KeyCode, Key, WidgetManager, PreferenceService,
KeybindingRegistry, LabelProvider, WidgetOpenerOptions, StorageService, QuickInputService,
codicon, CommonCommands, FrontendApplicationContribution, OnWillStopAction, Dialog, ConfirmDialog, FrontendApplication, PreferenceScope, Widget, HoverService
codicon, CommonCommands, FrontendApplicationContribution, OnWillStopAction, Dialog, ConfirmDialog, FrontendApplication, PreferenceScope, Widget
} from '@theia/core/lib/browser';
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
import { TERMINAL_WIDGET_FACTORY_ID, TerminalWidgetFactoryOptions, TerminalWidgetImpl } from './terminal-widget-impl';
Expand Down Expand Up @@ -60,8 +60,6 @@ import { nls } from '@theia/core/lib/common/nls';
import { Profiles, TerminalPreferences } from './terminal-preferences';
import { ShellTerminalProfile } from './shell-terminal-profile';
import { VariableResolverService } from '@theia/variable-resolver/lib/browser';
import { TerminalInfoToolbarItem } from './terminal-info-toolbar-item';
import { MarkdownRenderer, MarkdownRendererFactory } from '@theia/core/lib/browser/markdown-rendering/markdown-renderer';

export namespace TerminalMenus {
export const TERMINAL = [...MAIN_MENU_BAR, '7_terminal'];
Expand Down Expand Up @@ -218,17 +216,6 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
@inject(TerminalPreferences)
protected terminalPreferences: TerminalPreferences;

@inject(HoverService)
protected readonly hoverService: HoverService;

@inject(MarkdownRendererFactory) protected readonly markdownRendererFactory: MarkdownRendererFactory;

protected _markdownRenderer: MarkdownRenderer | undefined;
protected get markdownRenderer(): MarkdownRenderer {
this._markdownRenderer ||= this.markdownRendererFactory();
return this._markdownRenderer;
}

protected mergePreferencesPromise: Promise<void> = Promise.resolve();

protected readonly onDidCreateTerminalEmitter = new Emitter<TerminalWidget>();
Expand Down Expand Up @@ -744,7 +731,6 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
}

registerToolbarItems(toolbar: TabBarToolbarRegistry): void {
toolbar.registerItem(new TerminalInfoToolbarItem(this.hoverService, this.markdownRenderer));
toolbar.registerItem({
id: TerminalCommands.SPLIT.id,
command: TerminalCommands.SPLIT.id,
Expand Down
113 changes: 0 additions & 113 deletions packages/terminal/src/browser/terminal-info-toolbar-item.tsx

This file was deleted.

60 changes: 58 additions & 2 deletions packages/terminal/src/browser/terminal-widget-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ import { Key } from '@theia/core/lib/browser/keys';
import { nls } from '@theia/core/lib/common/nls';
import { TerminalMenus } from './terminal-frontend-contribution';
import debounce = require('p-debounce');
import { MarkdownString } from '@theia/core/lib/common/markdown-rendering/markdown-string';
import { MarkdownString, MarkdownStringImpl } from '@theia/core/lib/common/markdown-rendering/markdown-string';
import { EnhancedPreviewWidget } from '@theia/core/lib/browser/widgets/enhanced-preview-widget';
import { MarkdownRenderer, MarkdownRendererFactory } from '@theia/core/lib/browser/markdown-rendering/markdown-renderer';

export const TERMINAL_WIDGET_FACTORY_ID = 'terminal';

Expand All @@ -58,7 +60,7 @@ export interface TerminalContribution {
}

@injectable()
export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget, ExtractableWidget {
export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget, ExtractableWidget, EnhancedPreviewWidget {
readonly isExtractable: boolean = true;
secondaryWindow: Window | undefined;
location: TerminalLocationOptions;
Expand All @@ -82,6 +84,7 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
protected lastMousePosition: { x: number, y: number } | undefined;
protected isAttachedCloseListener: boolean = false;
protected shown = false;
protected enhancedPreviewNode: Node | undefined;
override lastCwd = new URI();

@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
Expand All @@ -99,6 +102,13 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
@inject(TerminalThemeService) protected readonly themeService: TerminalThemeService;
@inject(ShellCommandBuilder) protected readonly shellCommandBuilder: ShellCommandBuilder;
@inject(ContextMenuRenderer) protected readonly contextMenuRenderer: ContextMenuRenderer;
@inject(MarkdownRendererFactory) protected readonly markdownRendererFactory: MarkdownRendererFactory;

protected _markdownRenderer: MarkdownRenderer | undefined;
protected get markdownRenderer(): MarkdownRenderer {
this._markdownRenderer ||= this.markdownRendererFactory();
return this._markdownRenderer;
}

protected readonly onDidOpenEmitter = new Emitter<void>();
readonly onDidOpen: Event<void> = this.onDidOpenEmitter.event;
Expand Down Expand Up @@ -764,6 +774,10 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
if (this.exitStatus) {
this.onTermDidClose.fire(this);
}
if (this.enhancedPreviewNode) {
// don't use preview node anymore. rendered markdown will be disposed on super call
this.enhancedPreviewNode = undefined;
}
super.dispose();
}

Expand Down Expand Up @@ -867,4 +881,46 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
private disableEnterWhenAttachCloseListener(): boolean {
return this.isAttachedCloseListener;
}

getEnhancedPreviewNode(): Node | undefined {
if (this.enhancedPreviewNode) {
return this.enhancedPreviewNode;
}

this.enhancedPreviewNode = document.createElement('div');

Promise.all([this.envVarCollectionDescriptionsByExtension, this.processId, this.processInfo])
.then((values: [Map<string, string | MarkdownString | undefined>, number, TerminalProcessInfo]) => {
const extensions = values[0];
const processId = values[1];
const processInfo = values[2];

const markdown = new MarkdownStringImpl();
markdown.appendMarkdown('Process ID: ' + processId + '\\\n');
markdown.appendMarkdown('Command line: ' +
processInfo.executable +
' ' +
processInfo.arguments.join(' ') +
'\n\n---\n\n');
markdown.appendMarkdown('The following extensions have contributed to this terminal\'s environment:\n');
extensions.forEach((value, key) => {
if (value === undefined) {
markdown.appendMarkdown('* ' + key + '\n');
} else if (typeof value === 'string') {
markdown.appendMarkdown('* ' + key + ': ' + value + '\n');
} else {
markdown.appendMarkdown('* ' + key + ': ' + value.value + '\n');
}
});

const enhancedPreviewNode = this.enhancedPreviewNode;
if (!this.isDisposed && enhancedPreviewNode) {
const result = this.markdownRenderer.render(markdown);
this.toDispose.push(result);
enhancedPreviewNode.appendChild(result.element);
}
});

return this.enhancedPreviewNode;
}
}

0 comments on commit bab13b9

Please sign in to comment.