From e00bc061fcffda38428c157722efe53a0f04b98e Mon Sep 17 00:00:00 2001 From: Thad House Date: Thu, 28 Sep 2023 18:45:23 -0700 Subject: [PATCH] Start adding python support This is just the basic start, and only a code deployer to start with (and one that doesn't deploy at that, as I don't know the command) --- vscode-wpilib/src/extension.ts | 3 ++ vscode-wpilib/src/python/deploydebug.ts | 61 +++++++++++++++++++++++++ vscode-wpilib/src/python/python.ts | 20 ++++++++ 3 files changed, 84 insertions(+) create mode 100644 vscode-wpilib/src/python/deploydebug.ts create mode 100644 vscode-wpilib/src/python/python.ts diff --git a/vscode-wpilib/src/extension.ts b/vscode-wpilib/src/extension.ts index 7e17fdd4..57891610 100644 --- a/vscode-wpilib/src/extension.ts +++ b/vscode-wpilib/src/extension.ts @@ -36,6 +36,7 @@ import { Gradle2020Import } from './webviews/gradle2020import'; import { Help } from './webviews/help'; import { ProjectCreator } from './webviews/projectcreator'; import { WPILibUpdates } from './wpilibupdates'; +import { activatePython } from './python/python'; // External API class to implement the IExternalAPI interface class ExternalAPI implements IExternalAPI { @@ -117,6 +118,8 @@ async function handleAfterTrusted(externalApi: ExternalAPI, context: vscode.Exte await activateCpp(context, externalApi); // Active the java parts of the extension await activateJava(context, externalApi); + // Activate the python parts of the extension + await activatePython(context, externalApi); try { // Add built in tools diff --git a/vscode-wpilib/src/python/deploydebug.ts b/vscode-wpilib/src/python/deploydebug.ts new file mode 100644 index 00000000..ad94f95a --- /dev/null +++ b/vscode-wpilib/src/python/deploydebug.ts @@ -0,0 +1,61 @@ +'use strict'; + +import * as jsonc from 'jsonc-parser'; +import * as path from 'path'; +import * as vscode from 'vscode'; +import { ICodeDeployer, IExecuteAPI, IExternalAPI, IPreferencesAPI } from 'vscode-wpilibapi'; +import { gradleRun, readFileAsync } from '../utilities'; + +class DeployCodeDeployer implements ICodeDeployer { + private preferences: IPreferencesAPI; + private executeApi: IExecuteAPI; + + constructor(externalApi: IExternalAPI) { + this.preferences = externalApi.getPreferencesAPI(); + this.executeApi = externalApi.getExecuteAPI(); + } + + public async getIsCurrentlyValid(workspace: vscode.WorkspaceFolder): Promise { + const prefs = this.preferences.getPreferences(workspace); + const currentLanguage = prefs.getCurrentLanguage(); + return currentLanguage === 'none' || currentLanguage === 'java'; + } + + public async runDeployer(teamNumber: number, workspace: vscode.WorkspaceFolder, + _: vscode.Uri | undefined, ...args: string[]): Promise { + // TODO actaully deploy + return false; + } + + public getDisplayName(): string { + return 'python'; + } + + public getDescription(): string { + return 'Python Deploy'; + } +} + +export class DeployDebug { + private deployDeployer: DeployCodeDeployer; + + constructor(externalApi: IExternalAPI) { + const deployDebugApi = externalApi.getDeployDebugAPI(); + deployDebugApi.addLanguageChoice('python'); + + //this.deployDebuger = new DebugCodeDeployer(externalApi); + this.deployDeployer = new DeployCodeDeployer(externalApi); + //this.simulator = new SimulateCodeDeployer(externalApi); + + deployDebugApi.registerCodeDeploy(this.deployDeployer); + + // if (allowDebug) { + // deployDebugApi.registerCodeDebug(this.deployDebuger); + // deployDebugApi.registerCodeSimulate(this.simulator); + // } + } + + public dispose() { + // + } + } diff --git a/vscode-wpilib/src/python/python.ts b/vscode-wpilib/src/python/python.ts new file mode 100644 index 00000000..d9feb964 --- /dev/null +++ b/vscode-wpilib/src/python/python.ts @@ -0,0 +1,20 @@ +'use strict'; + +import * as path from 'path'; +import * as vscode from 'vscode'; +import { IExternalAPI } from "vscode-wpilibapi"; +import { DeployDebug } from './deploydebug'; + +export async function activatePython(context: vscode.ExtensionContext, coreExports: IExternalAPI) { + + const extensionResourceLocation = path.join(context.extensionPath, 'resources', 'python'); + + const preferences = coreExports.getPreferencesAPI(); + const exampleTemplate = coreExports.getExampleTemplateAPI(); + const commandApi = coreExports.getCommandAPI(); + + const deployDebug = new DeployDebug(coreExports); + context.subscriptions.push(deployDebug); + + +}