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

Switch over to executeCommand from sendText #24078

Merged
merged 37 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2413118
vscode engine to 1.93
anthonykim1 Sep 9, 2024
5de9ca5
use executeCommand
anthonykim1 Sep 9, 2024
6d1f522
codeaction mock
anthonykim1 Sep 9, 2024
c9fc4f1
compile
anthonykim1 Sep 9, 2024
0d78806
switching version allows debugging - magically
anthonykim1 Sep 10, 2024
a16a102
pin version to equal to or above 1.93
anthonykim1 Sep 10, 2024
ea24d50
try to fix unit test
anthonykim1 Sep 10, 2024
2cb1eb3
Debt: switch Promise<void> in ensureTerminal to Promise<Terminal>
anthonykim1 Sep 10, 2024
88b4e9f
passing test when shell integration disabled
anthonykim1 Sep 10, 2024
6ecf4fc
please
anthonykim1 Sep 10, 2024
831f893
// @ts-ignore: TS6133
anthonykim1 Sep 10, 2024
f3aa28e
a
anthonykim1 Sep 10, 2024
342587a
stop
anthonykim1 Sep 11, 2024
3efaf9a
try idisposable
anthonykim1 Sep 11, 2024
d3b2238
more trials
anthonykim1 Sep 11, 2024
28ef3c1
lint
anthonykim1 Sep 11, 2024
2375490
slowly migrate test from sendText to executeCommand
anthonykim1 Sep 11, 2024
a75656b
TODO: test for when shellIntegration is active, mock and fire onDidEn…
anthonykim1 Sep 11, 2024
a51b6b4
onDidEndTerminalShellExecution never gets fired
anthonykim1 Sep 11, 2024
7c01537
switch up the order
anthonykim1 Sep 11, 2024
923df5c
add test onDidEndTerminalShellExecutionEmitter.fire(event)
anthonykim1 Sep 11, 2024
16839c9
attach callback to executeCommand so onDidEndTerminalShellExecutionEm…
anthonykim1 Sep 11, 2024
e30bb77
switch up the order abit + comment
anthonykim1 Sep 11, 2024
e69c490
wow
anthonykim1 Sep 11, 2024
e2e71d0
remove junk
anthonykim1 Sep 11, 2024
3d31d1a
remove unused
anthonykim1 Sep 11, 2024
46d28d2
remove comment
anthonykim1 Sep 11, 2024
5d3878f
TODO: smart send smoke test are flaky on windows
anthonykim1 Sep 11, 2024
dfe61de
a
anthonykim1 Sep 11, 2024
8f9ab0d
take recommended feedbacks
anthonykim1 Sep 12, 2024
6d095c8
remove leftover comments - done
anthonykim1 Sep 12, 2024
563fb12
final
anthonykim1 Sep 12, 2024
145e2fd
remove weird import
anthonykim1 Sep 12, 2024
8bc3951
last missed comment
anthonykim1 Sep 12, 2024
610d0fb
upgrade actions/download-artifact@v4
anthonykim1 Sep 12, 2024
c6a4713
why
anthonykim1 Sep 12, 2024
2b4c2bf
try with actions/download-artifact@v3
anthonykim1 Sep 12, 2024
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
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"theme": "dark"
},
"engines": {
"vscode": "^1.91.0"
"vscode": "^1.93.0"
},
"enableTelemetry": false,
"keywords": [
Expand Down Expand Up @@ -1570,7 +1570,7 @@
"@types/sinon": "^17.0.3",
"@types/stack-trace": "0.0.29",
"@types/tmp": "^0.0.33",
"@types/vscode": "^1.81.0",
"@types/vscode": "^1.93.0",
"@types/which": "^2.0.1",
"@types/winreg": "^1.2.30",
"@types/xml2js": "^0.4.2",
Expand Down
59 changes: 52 additions & 7 deletions src/client/common/terminal/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { inject, injectable } from 'inversify';
import * as path from 'path';
import { CancellationToken, Disposable, Event, EventEmitter, Terminal } from 'vscode';
import { CancellationToken, Disposable, Event, EventEmitter, Terminal, window } from 'vscode';
import '../../common/extensions';
import { IInterpreterService } from '../../interpreter/contracts';
import { IServiceContainer } from '../../ioc/types';
Expand All @@ -20,6 +20,7 @@ import {
ITerminalService,
TerminalCreationOptions,
TerminalShellType,
ITerminalExecutedCommand,
} from './types';

@injectable()
Expand All @@ -32,6 +33,7 @@ export class TerminalService implements ITerminalService, Disposable {
private terminalActivator: ITerminalActivator;
private terminalAutoActivator: ITerminalAutoActivation;
private readonly envVarScript = path.join(EXTENSION_ROOT_DIR, 'python_files', 'pythonrc.py');
private readonly executeCommandListeners: Set<Disposable> = new Set();
public get onDidCloseTerminal(): Event<void> {
return this.terminalClosed.event.bind(this.terminalClosed);
}
Expand All @@ -48,8 +50,10 @@ export class TerminalService implements ITerminalService, Disposable {
this.terminalActivator = this.serviceContainer.get<ITerminalActivator>(ITerminalActivator);
}
public dispose() {
if (this.terminal) {
this.terminal.dispose();
this.terminal?.dispose();

for (const d of this.executeCommandListeners) {
d.dispose();
}
}
public async sendCommand(command: string, args: string[], _?: CancellationToken): Promise<void> {
Expand All @@ -59,24 +63,64 @@ export class TerminalService implements ITerminalService, Disposable {
this.terminal!.show(true);
}

this.terminal!.sendText(text, true);
await this.executeCommand(text);
}
/** @deprecated */
public async sendText(text: string): Promise<void> {
await this.ensureTerminal();
if (!this.options?.hideFromUser) {
this.terminal!.show(true);
}
this.terminal!.sendText(text);
}
public async executeCommand(commandLine: string): Promise<ITerminalExecutedCommand | undefined> {
const terminal = await this.ensureTerminal();
if (!this.options?.hideFromUser) {
terminal.show(true);
}

// If terminal was just launched, wait some time for shell integration to onDidChangeShellIntegration.
if (!terminal.shellIntegration) {
const promise = new Promise<boolean>((resolve) => {
const shellIntegrationChangeEventListener = window.onDidChangeTerminalShellIntegration(() => {
this.executeCommandListeners.delete(shellIntegrationChangeEventListener);
resolve(true);
});
setTimeout(() => {
this.executeCommandListeners.add(shellIntegrationChangeEventListener);
resolve(true);
}, 3000);
anthonykim1 marked this conversation as resolved.
Show resolved Hide resolved
});
await promise;
}

if (terminal.shellIntegration) {
const execution = terminal.shellIntegration.executeCommand(commandLine);
return await new Promise((resolve) => {
const listener = window.onDidEndTerminalShellExecution((e) => {
anthonykim1 marked this conversation as resolved.
Show resolved Hide resolved
if (e.execution === execution) {
this.executeCommandListeners.delete(listener);
resolve({ execution, exitCode: e.exitCode });
}
});
this.executeCommandListeners.add(listener);
});
} else {
terminal.sendText(commandLine);
}

return undefined;
}

public async show(preserveFocus: boolean = true): Promise<void> {
await this.ensureTerminal(preserveFocus);
if (!this.options?.hideFromUser) {
this.terminal!.show(preserveFocus);
}
}
public async ensureTerminal(preserveFocus: boolean = true): Promise<void> {
public async ensureTerminal(preserveFocus: boolean = true): Promise<Terminal> {
if (this.terminal) {
return;
return this.terminal;
}
this.terminalShellType = this.terminalHelper.identifyTerminalShell(this.terminal);
this.terminal = this.terminalManager.createTerminal({
Expand All @@ -97,10 +141,11 @@ export class TerminalService implements ITerminalService, Disposable {
});

if (!this.options?.hideFromUser) {
this.terminal!.show(preserveFocus);
this.terminal.show(preserveFocus);
}

this.sendTelemetry().ignoreErrors();
return this.terminal;
}
private terminalCloseHandler(terminal: Terminal) {
if (terminal === this.terminal) {
Expand Down
6 changes: 5 additions & 1 deletion src/client/common/terminal/syncTerminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as internalScripts from '../process/internal/scripts';
import { createDeferred, Deferred } from '../utils/async';
import { noop } from '../utils/misc';
import { TerminalService } from './service';
import { ITerminalService } from './types';
import { ITerminalService, ITerminalExecutedCommand } from './types';

enum State {
notStarted = 0,
Expand Down Expand Up @@ -146,9 +146,13 @@ export class SynchronousTerminalService implements ITerminalService, Disposable
lockFile.dispose();
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We should use less of these services when possible.

/** @deprecated */
public sendText(text: string): Promise<void> {
return this.terminalService.sendText(text);
}
public executeCommand(commandLine: string): Promise<ITerminalExecutedCommand | undefined> {
return this.terminalService.executeCommand(commandLine);
}
public show(preserveFocus?: boolean | undefined): Promise<void> {
return this.terminalService.show(preserveFocus);
}
Expand Down
9 changes: 8 additions & 1 deletion src/client/common/terminal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

'use strict';

import { CancellationToken, Event, Terminal, Uri } from 'vscode';
import { CancellationToken, Event, Terminal, Uri, TerminalShellExecution } from 'vscode';
import { PythonEnvironment } from '../../pythonEnvironments/info';
import { IEventNamePropertyMapping } from '../../telemetry/index';
import { IDisposable, Resource } from '../types';
Expand Down Expand Up @@ -52,10 +52,17 @@ export interface ITerminalService extends IDisposable {
cancel?: CancellationToken,
swallowExceptions?: boolean,
): Promise<void>;
/** @deprecated */
sendText(text: string): Promise<void>;
executeCommand(commandLine: string): Promise<ITerminalExecutedCommand | undefined>;
show(preserveFocus?: boolean): Promise<void>;
}

export interface ITerminalExecutedCommand {
execution: TerminalShellExecution;
exitCode: number | undefined;
}

export const ITerminalServiceFactory = Symbol('ITerminalServiceFactory');

export type TerminalCreationOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
this.configurationService.updateSetting('REPL.enableREPLSmartSend', false, resource);
}
} else {
await this.getTerminalService(resource).sendText(code);
await this.getTerminalService(resource).executeCommand(code);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ suite('Terminal Environment Variable Collection Service', () => {

test('When not in experiment, do not apply activated variables to the collection and clear it instead', async () => {
reset(experimentService);
when(context.environmentVariableCollection).thenReturn(instance(collection));
when(experimentService.inExperimentSync(TerminalEnvVarActivation.experiment)).thenReturn(false);
const applyCollectionStub = sinon.stub(terminalEnvVarCollectionService, '_applyCollection');
applyCollectionStub.resolves();
Expand Down
2 changes: 2 additions & 0 deletions src/test/mocks/vsc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ export class CodeActionKind {

public static readonly SourceFixAll: CodeActionKind = new CodeActionKind('source.fix.all');

public static readonly Notebook: CodeActionKind = new CodeActionKind('notebook');

private constructor(private _value: string) {}

public append(parts: string): CodeActionKind {
Expand Down
7 changes: 0 additions & 7 deletions types/vscode.proposed.envCollectionWorkspace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,4 @@ declare module 'vscode' {
*/
getScoped(scope: EnvironmentVariableScope): EnvironmentVariableCollection;
}

export type EnvironmentVariableScope = {
/**
* Any specific workspace folder to get collection for. If unspecified, collection applicable to all workspace folders is returned.
*/
workspaceFolder?: WorkspaceFolder;
};
}
16 changes: 0 additions & 16 deletions types/vscode.proposed.envShellEvent.d.ts

This file was deleted.

Loading
Loading