Skip to content

Commit

Permalink
many TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykim1 committed Sep 12, 2024
1 parent 294e4e4 commit c803307
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 44 deletions.
30 changes: 1 addition & 29 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ initializeFileLogging(logDispose);
//===============================================
// loading starts here

import { commands, ProgressLocation, ProgressOptions, ShellExecution, Task, tasks, TaskScope, window } from 'vscode';
import { ProgressLocation, ProgressOptions, window } from 'vscode';
import { buildApi } from './api';
import { IApplicationShell, IWorkspaceService } from './common/application/types';
import { IDisposableRegistry, IExperimentService, IExtensionContext } from './common/types';
Expand All @@ -47,7 +47,6 @@ import { disposeAll } from './common/utils/resourceLifecycle';
import { ProposedExtensionAPI } from './proposedApiTypes';
import { buildProposedApi } from './proposedApi';
import { GLOBAL_PERSISTENT_KEYS } from './common/persistentState';
import { registerPythonTaskProvider } from './taskProblemMatcher';

durations.codeLoadingTime = stopWatch.elapsedTime;

Expand Down Expand Up @@ -139,33 +138,6 @@ async function activateUnsafe(
await Promise.all(nonBlocking);
})();

// register task provider for the workspace

const taskProvider = registerPythonTaskProvider();

context.subscriptions.push(taskProvider);

commands.executeCommand('workbench.action.tasks.registerTaskDefinition', {
label: '$pythonCustomMatcher',
owner: 'python',
source: 'python',
fileLocation: 'autoDetect',
pattern: [
{
regexp: '^.*File \\"([^\\"]|.*)\\", line (\\d+).*',
file: 1,
line: 2,
},
{
regexp: '^.*raise.*$',
},
{
regexp: '^\\s*(.*)\\s*$',
message: 1,
},
],
});

//===============================================
// activation ends here

Expand Down
37 changes: 35 additions & 2 deletions src/client/extensionActivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

'use strict';

import { DebugConfigurationProvider, debug, languages, window } from 'vscode';
import { DebugConfigurationProvider, commands, debug, languages, window } from 'vscode';

import { registerTypes as activationRegisterTypes } from './activation/serviceRegistry';
import { IExtensionActivationManager } from './activation/types';
Expand Down Expand Up @@ -32,7 +32,12 @@ import { TerminalProvider } from './providers/terminalProvider';
import { setExtensionInstallTelemetryProperties } from './telemetry/extensionInstallTelemetry';
import { registerTypes as tensorBoardRegisterTypes } from './tensorBoard/serviceRegistry';
import { registerTypes as commonRegisterTerminalTypes } from './terminals/serviceRegistry';
import { ICodeExecutionHelper, ICodeExecutionManager, ITerminalAutoActivation } from './terminals/types';
import {
ICodeExecutionHelper,
ICodeExecutionManager,
ICodeExecutionService,
ITerminalAutoActivation,
} from './terminals/types';
import { registerTypes as unitTestsRegisterTypes } from './testing/serviceRegistry';

// components
Expand All @@ -54,6 +59,7 @@ import { DebuggerTypeName } from './debugger/constants';
import { StopWatch } from './common/utils/stopWatch';
import { registerReplCommands, registerReplExecuteOnEnter, registerStartNativeReplCommand } from './repl/replCommands';
import { registerTriggerForTerminalREPL } from './terminals/codeExecution/terminalReplWatcher';
import { registerPythonTaskProvider } from './taskProblemMatcher';

export async function activateComponents(
// `ext` is passed to any extra activation funcs.
Expand Down Expand Up @@ -109,6 +115,33 @@ export function activateFeatures(ext: ExtensionState, _components: Components):
);
const executionHelper = ext.legacyIOC.serviceContainer.get<ICodeExecutionHelper>(ICodeExecutionHelper);
const commandManager = ext.legacyIOC.serviceContainer.get<ICommandManager>(ICommandManager);
const codeExecutionService = ext.legacyIOC.serviceContainer.get<ICodeExecutionService>(ICodeExecutionService);
// register task provider for the workspace

const taskProvider = registerPythonTaskProvider(executionHelper, codeExecutionService);

// TODO: use command manager and not command directly from VS Code
commands.executeCommand('workbench.action.tasks.registerTaskDefinition', {
label: '$pythonCustomMatcher',
owner: 'python',
source: 'python',
fileLocation: 'autoDetect',
pattern: [
{
regexp: '^.*File \\"([^\\"]|.*)\\", line (\\d+).*',
file: 1,
line: 2,
},
{
regexp: '^.*raise.*$',
},
{
regexp: '^\\s*(.*)\\s*$',
message: 1,
},
],
});

registerTriggerForTerminalREPL(ext.disposables);
registerStartNativeReplCommand(ext.disposables, interpreterService);
registerReplCommands(ext.disposables, interpreterService, executionHelper, commandManager);
Expand Down
31 changes: 23 additions & 8 deletions src/client/taskProblemMatcher.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { ShellExecution, Task, TaskScope, tasks, Disposable } from 'vscode';
import { ShellExecution, Task, TaskScope, tasks } from 'vscode';
import { Disposable } from 'vscode-jsonrpc';
import { traceLog } from './logging';
import { ICodeExecutionHelper, ICodeExecutionService } from './terminals/types';

export function registerPythonTaskProvider(): Disposable {
export function registerPythonTaskProvider(
executionHelper: ICodeExecutionHelper,
codeExecutionService: ICodeExecutionService,
): Disposable {
const taskProvider = tasks.registerTaskProvider('pythonTask', {
provideTasks: () =>
Promise.resolve([
Expand All @@ -23,26 +28,36 @@ export function registerPythonTaskProvider(): Disposable {
},
});

tasks.onDidStartTask((e) => {
tasks.onDidStartTask(async (e) => {
traceLog(`Task started: ${e.execution.task.name}`);

if (e.execution.task.name === 'Trigger Python Task') {
// TODO: If the task started is for Python extension,
// Create new task,
// TODO: If the task(dummy task/entry point task --> may cd to prep execution) started is for Python extension,
// Create new task (Real task that will run current Python file),
// execute that new task with their current python file

const runCurrentFileCommand = '';
// TODO: Get the file to execute
// TODO: set cwd for file execution using await this.setCwdForFileExecution(file, options);

const pythonFile = await executionHelper.getFileToExecute();
// TODO: MIGHT NEED TO set cwd for file execution using await this.setCwdForFileExecution(file, options);

// TODO: const { command, args } = await this.getExecuteFileArgs(file, [file.fsPath.fileToCommandArgumentForPythonExt(),]);
const { command, args } = await codeExecutionService.getExecuteFileArgs(
[
pythonFile!.fsPath.fileToCommandArgumentForPythonExt(), // TODO: Remove bang !
],
pythonFile!,
);
// TODO: build command for specific terminal
const finalCommand = terminalHelper.buildCommandForTerminal(terminalShellType, command, args);
// TODO: pass command, args as argument to new ShellExecution below

const currentPythonFileTask = new Task(
{ type: 'pythonTask2', task: 'defaultTask2' },
TaskScope.Workspace,
'Run current Python file',
'pythonTask',
new ShellExecution('python joke.py'), // TODO: Get the current active Python file and make command to run this
new ShellExecution(finalCommand), // TODO: Get the current active Python file and make command to run this
'$pythonCustomMatcher', // Use the custom problem matcher defined in package.json
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class DjangoShellCodeExecutionProvider extends TerminalCodeExecutionProvi
return copyPythonExecInfo(info, [managePyPath.fileToCommandArgumentForPythonExt(), 'shell']);
}

public async getExecuteFileArgs(resource?: Uri, executeArgs: string[] = []): Promise<PythonExecInfo> {
public async getExecuteFileArgs(executeArgs: string[] = [], resource?: Uri): Promise<PythonExecInfo> {
// We need the executable info but not the 'manage.py shell' args
const info = await super.getExecutableInfo(resource);
return copyPythonExecInfo(info, executeArgs);
Expand Down
9 changes: 5 additions & 4 deletions src/client/terminals/codeExecution/terminalCodeExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {

public async executeFile(file: Uri, options?: { newTerminalPerFile: boolean }) {
await this.setCwdForFileExecution(file, options);
const { command, args } = await this.getExecuteFileArgs(file, [
file.fsPath.fileToCommandArgumentForPythonExt(),
]);
const { command, args } = await this.getExecuteFileArgs(
[file.fsPath.fileToCommandArgumentForPythonExt()],
file,
);

await this.getTerminalService(file, options).sendCommand(command, args);
}
Expand Down Expand Up @@ -121,7 +122,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
}

// Overridden in subclasses, see djangoShellCodeExecution.ts
public async getExecuteFileArgs(resource?: Uri, executeArgs: string[] = []): Promise<PythonExecInfo> {
public async getExecuteFileArgs(executeArgs: string[] = [], resource?: Uri): Promise<PythonExecInfo> {
return this.getExecutableInfo(resource, executeArgs);
}
private getTerminalService(resource: Resource, options?: { newTerminalPerFile: boolean }): ITerminalService {
Expand Down
2 changes: 2 additions & 0 deletions src/client/terminals/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

import { Event, Terminal, TextEditor, Uri } from 'vscode';
import { IDisposable, Resource } from '../common/types';
import { PythonExecInfo } from '../pythonEnvironments/exec';

export const ICodeExecutionService = Symbol('ICodeExecutionService');

export interface ICodeExecutionService {
execute(code: string, resource?: Uri): Promise<void>;
executeFile(file: Uri, options?: { newTerminalPerFile: boolean }): Promise<void>;
initializeRepl(resource?: Uri): Promise<void>;
getExecuteFileArgs(executeArgs: string[], resource?: Uri): Promise<PythonExecInfo>;
}

export const ICodeExecutionHelper = Symbol('ICodeExecutionHelper');
Expand Down

0 comments on commit c803307

Please sign in to comment.