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

Enable support for run, debug, run test and debug test buttons #261

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion vscode-wpilib/i18n/zh-CN/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
"wpilibcore.setDeployOffline.title": "在离线模式中 更改 部署/调试命令 设置",
"wpilibcore.setOffline.title": "在离线模式中 更改 部署/调试命令 外的设置",
"wpilibcore.selectCppBinaryTypes.title": "Select Enabled C++ Intellisense Binary Types",
"wpilibcore.openApiDocumentation.title": "Open API Documentation"
"wpilibcore.openApiDocumentation.title": "Open API Documentation",
"wpilibjava.setupRunDebugButtons.title": "Setup Java Run and Debug Buttons"
}
5 changes: 5 additions & 0 deletions vscode-wpilib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@
"command": "wpilibcore.openApiDocumentation",
"title": "%wpilibcore.openApiDocumentation.title%",
"category": "WPILib"
},
{
"command": "wpilibjava.setupRunDebugButtons",
"title": "%wpilibjava.setupRunDebugButtons.title%",
"category": "WPILib"
}
],
"views": {
Expand Down
3 changes: 2 additions & 1 deletion vscode-wpilib/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
"wpilibcore.resetAutoUpdate.title": "Reset Ask for WPILib Updates Flag",
"wpilibcore.changeDesktop.title": "Change Desktop Support Enabled Setting",
"wpilibcore.selectCppBinaryTypes.title": "Select Enabled C++ Intellisense Binary Types",
"wpilibcore.openApiDocumentation.title": "Open API Documentation"
"wpilibcore.openApiDocumentation.title": "Open API Documentation",
"wpilibjava.setupRunDebugButtons.title": "Setup Java Run and Debug Buttons"
}
26 changes: 22 additions & 4 deletions vscode-wpilib/src/java/deploydebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ class SimulateCodeDeployer implements ICodeDeployer {
const currentLanguage = prefs.getCurrentLanguage();
return currentLanguage === 'none' || currentLanguage === 'java';
}
public async runDeployer(_: number, workspace: vscode.WorkspaceFolder,
__: vscode.Uri | undefined, ...args: string[]): Promise<boolean> {

public async getSimulationInformation(_: number, workspace: vscode.WorkspaceFolder,
__: vscode.Uri | undefined, ...args: string[]): Promise<ISimulateCommands | undefined> {
const command = 'simulateExternalJava ' + args.join(' ');
const prefs = this.preferences.getPreferences(workspace);
const result = await gradleRun(command, workspace.uri.fsPath, workspace, 'Java Simulate', this.executeApi, prefs);
if (result !== 0) {
return false;
return undefined;
}

const simulateInfo = await readFileAsync(path.join(workspace.uri.fsPath, 'build', 'debug', 'desktopinfo.json'), 'utf8');
Expand All @@ -189,7 +190,7 @@ class SimulateCodeDeployer implements ICodeDeployer {
});
if (picked === undefined) {
vscode.window.showInformationMessage('Artifact cancelled');
return false;
return undefined;
}
targetSimulateInfo = picked.debugInfo;
}
Expand Down Expand Up @@ -224,6 +225,19 @@ class SimulateCodeDeployer implements ICodeDeployer {
workspace,
};

return config;

}

public async runDeployer(_: number, workspace: vscode.WorkspaceFolder,
__: vscode.Uri | undefined, ...args: string[]): Promise<boolean> {

const config = await this.getSimulationInformation(_, workspace, __, ...args);

if (config === undefined) {
return false;
}

await startSimulation(config);

return true;
Expand Down Expand Up @@ -257,6 +271,10 @@ export class DeployDebug {
}
}

public getSimulator(): SimulateCodeDeployer {
return this.simulator;
}

public dispose() {
//
}
Expand Down
58 changes: 55 additions & 3 deletions vscode-wpilib/src/java/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import { onVendorDepsChanged } from '../vendorlibraries';
import { BuildTest } from './buildtest';
import { Commands } from './commands';
import { DeployDebug } from './deploydebug';
import { getCodeLensRunCommand, getCodeLensTestCommand } from './simulate';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export async function activateJava(context: vscode.ExtensionContext, coreExports: IExternalAPI) {
export async function activateJava(context: vscode.ExtensionContext, coreExports: IExternalAPI): Promise<void> {

const extensionResourceLocation = path.join(context.extensionPath, 'resources', 'java');

Expand All @@ -33,9 +34,7 @@ export async function activateJava(context: vscode.ExtensionContext, coreExports
}

// Setup build and test

const buildTest = new BuildTest(coreExports);

context.subscriptions.push(buildTest);

// Setup debug and deploy
Expand All @@ -52,6 +51,59 @@ export async function activateJava(context: vscode.ExtensionContext, coreExports
const templates: Templates = new Templates(extensionResourceLocation, true, exampleTemplate);
context.subscriptions.push(templates);

// Setup java run debug configuration
context.subscriptions.push(vscode.commands.registerCommand('wpilibjava.setupRunDebugButtons', async () => {
const preferencesApi = coreExports.getPreferencesAPI();
const workspace = await preferencesApi.getFirstOrSelectedWorkspace();
if (workspace === undefined) {
vscode.window.showInformationMessage('Cannot enable simulation with an empty workspace');
return;
}
const teamNumber = await preferencesApi.getPreferences(workspace).getTeamNumber();
const simInfo = await deployDebug.getSimulator().getSimulationInformation(teamNumber, workspace, undefined);

if (simInfo === undefined) {
return;
}

const config = vscode.workspace.getConfiguration('launch', workspace.uri);
const testConfig = vscode.workspace.getConfiguration('java.test', workspace.uri);

// tslint:disable-next-line:no-any
const testValues: any[] | undefined = testConfig.get<any[] | undefined>('config', undefined);
const has = testConfig.has('config');

// This is broken, getting proxy objects. Need to figure out what is going on.
if (testValues === undefined || !has) {
testConfig.update('config', [await getCodeLensTestCommand(simInfo)]);
} else {
let found = false;
for (let i = 0; i < testValues.length; i++) {
// tslint:disable-next-line: no-unsafe-any
if (testValues[i].name === 'WPILib Configuration') {
testValues[i] = await getCodeLensTestCommand(simInfo);
testConfig.update('config', testValues);
found = true;
break;
}
}
if (!found) {
testValues.push(await getCodeLensTestCommand(simInfo));
testConfig.update('config', testValues);
}
}

// tslint:disable-next-line:no-any
const values: any[] | undefined = config.get('configurations');

if (values === undefined) {
config.update('configurations', [await getCodeLensRunCommand(simInfo)]);
} else {
values.push(await getCodeLensRunCommand(simInfo));
config.update('configurations', values);
}
}));

if (vscode.extensions.getExtension('redhat.java') !== undefined) {
// Add handlers for each workspace if java is installed
const wp = vscode.workspace.workspaceFolders;
Expand Down
53 changes: 53 additions & 0 deletions vscode-wpilib/src/java/simulate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,59 @@ export interface ISimulateCommands {
workspace: vscode.WorkspaceFolder;
}

export interface ICodeLensCommand {
console: string;
cwd: string;
env: { [key: string]: string };
mainClass: string;
name: string;
request: string;
stopOnEntry: boolean;
type: string;
vmArgs: string;
}

export interface ITestCodeLensCommand {
env: { [key: string]: string };
name: string;
vmargs: string[];
workingDirectory: string;
}

export async function getCodeLensRunCommand(commands: ISimulateCommands): Promise<ICodeLensCommand> {
let mainClassName = commands.mainclass;
const lastDot = mainClassName.lastIndexOf('.');
if (lastDot > 0) {
mainClassName = mainClassName.substring(lastDot + 1);
}
return {
console: 'integratedTerminal',
cwd: commands.workspace.uri.fsPath,
env: {
DYLD_LIBRARY_PATH: commands.librarydir,
HALSIM_EXTENSIONS: commands.extensions,
LD_LIBRARY_PATH: commands.librarydir,
PATH: commands.librarydir,
},
mainClass: commands.mainclass,
name: `CodeLens (Launch) - ${mainClassName}`,
request: 'launch',
stopOnEntry: commands.stopOnEntry,
type: 'java',
vmArgs: `-Djava.library.path="${commands.librarydir}"`,
};
}

export async function getCodeLensTestCommand(commands: ISimulateCommands): Promise<ITestCodeLensCommand> {
const runData = await getCodeLensRunCommand(commands);
return {
env: runData.env,
name: 'WPILib Configuration',
vmargs: [runData.vmArgs],
workingDirectory: commands.workspace.uri.fsPath,
};
}

export async function startSimulation(commands: ISimulateCommands): Promise<void> {
const config: vscode.DebugConfiguration = {
args: commands.robotclass,
Expand Down
8 changes: 7 additions & 1 deletion vscode-wpilib/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"allow-leading-underscore"
],
"max-classes-per-file": [
false
false,
1
],
"max-line-length": [
true,
Expand Down Expand Up @@ -57,5 +58,10 @@
"no-var-keyword": true,
"eofline": true
},
"linterOptions": {
"exclude": [
"node_modules/**"
]
},
"defaultSeverity": "error"
}