Skip to content

Commit

Permalink
Remove unnecessary file read on execution (#24196)
Browse files Browse the repository at this point in the history
Unused event that is not needed for file execution.
  • Loading branch information
karthiknadig authored Oct 1, 2024
1 parent 23424cb commit 8bcf046
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 22 deletions.
17 changes: 1 addition & 16 deletions src/client/terminals/codeExecution/codeExecutionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
'use strict';

import { inject, injectable } from 'inversify';
import { Disposable, Event, EventEmitter, Uri } from 'vscode';
import { Disposable, EventEmitter, Uri } from 'vscode';

import { ICommandManager, IDocumentManager } from '../../common/application/types';
import { Commands } from '../../common/constants';
import '../../common/extensions';
import { IFileSystem } from '../../common/platform/types';
import { IDisposableRegistry, IConfigurationService, Resource } from '../../common/types';
import { noop } from '../../common/utils/misc';
import { IInterpreterService } from '../../interpreter/contracts';
Expand All @@ -30,15 +29,10 @@ export class CodeExecutionManager implements ICodeExecutionManager {
@inject(ICommandManager) private commandManager: ICommandManager,
@inject(IDocumentManager) private documentManager: IDocumentManager,
@inject(IDisposableRegistry) private disposableRegistry: Disposable[],
@inject(IFileSystem) private fileSystem: IFileSystem,
@inject(IConfigurationService) private readonly configSettings: IConfigurationService,
@inject(IServiceContainer) private serviceContainer: IServiceContainer,
) {}

public get onExecutedCode(): Event<string> {
return this.eventEmitter.event;
}

public registerCommands() {
[Commands.Exec_In_Terminal, Commands.Exec_In_Terminal_Icon, Commands.Exec_In_Separate_Terminal].forEach(
(cmd) => {
Expand Down Expand Up @@ -127,15 +121,6 @@ export class CodeExecutionManager implements ICodeExecutionManager {
fileToExecute = fileAfterSave;
}

try {
const contents = await this.fileSystem.readFile(fileToExecute.fsPath);
this.eventEmitter.fire(contents);
} catch {
// Ignore any errors that occur for firing this event. It's only used
// for telemetry
noop();
}

const executionService = this.serviceContainer.get<ICodeExecutionService>(ICodeExecutionService, 'standard');
await executionService.executeFile(fileToExecute, options);
}
Expand Down
1 change: 0 additions & 1 deletion src/client/terminals/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export interface ICodeExecutionHelper {
export const ICodeExecutionManager = Symbol('ICodeExecutionManager');

export interface ICodeExecutionManager {
onExecutedCode: Event<string>;
registerCommands(): void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Disposable, TextDocument, TextEditor, Uri } from 'vscode';

import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../../client/common/application/types';
import { Commands } from '../../../client/common/constants';
import { IFileSystem } from '../../../client/common/platform/types';
import { IServiceContainer } from '../../../client/ioc/types';
import { CodeExecutionManager } from '../../../client/terminals/codeExecution/codeExecutionManager';
import { ICodeExecutionHelper, ICodeExecutionManager, ICodeExecutionService } from '../../../client/terminals/types';
Expand All @@ -24,12 +23,9 @@ suite('Terminal - Code Execution Manager', () => {
let serviceContainer: TypeMoq.IMock<IServiceContainer>;
let documentManager: TypeMoq.IMock<IDocumentManager>;
let configService: TypeMoq.IMock<IConfigurationService>;
let fileSystem: TypeMoq.IMock<IFileSystem>;
let interpreterService: TypeMoq.IMock<IInterpreterService>;
let triggerCreateEnvironmentCheckNonBlockingStub: sinon.SinonStub;
setup(() => {
fileSystem = TypeMoq.Mock.ofType<IFileSystem>();
fileSystem.setup((f) => f.readFile(TypeMoq.It.isAny())).returns(() => Promise.resolve(''));
workspace = TypeMoq.Mock.ofType<IWorkspaceService>();
workspace
.setup((c) => c.onDidChangeWorkspaceFolders(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
Expand All @@ -51,7 +47,6 @@ suite('Terminal - Code Execution Manager', () => {
commandManager.object,
documentManager.object,
disposables,
fileSystem.object,
configService.object,
serviceContainer.object,
);
Expand Down

0 comments on commit 8bcf046

Please sign in to comment.