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

Build automatically upon opening new project #204

Merged
merged 1 commit into from
Jan 25, 2019
Merged
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
2 changes: 1 addition & 1 deletion vscode-wpilib/src/cpp/buildtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CodeBuilder implements ICodeBuilder {
}

public async runBuilder(workspace: vscode.WorkspaceFolder): Promise<boolean> {
const command = 'build';
const command = 'build generateVsCodeConfig';
const prefs = this.preferences.getPreferences(workspace);
const result = await gradleRun(command, workspace.uri.fsPath, workspace, 'C++ Build', this.executeApi, prefs);
logger.log(result.toString());
Expand Down
16 changes: 7 additions & 9 deletions vscode-wpilib/src/cppprovider/apiprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function normalizeDriveLetter(pth: string): string {
}

export class ApiProvider implements CustomConfigurationProvider {
public static promptForUpdates: boolean = false;

// ConfigurationProvider public variables
public readonly extensionId: string = 'vscode-wpilib';
public readonly name: string = 'WPILib';
Expand Down Expand Up @@ -86,16 +88,9 @@ export class ApiProvider implements CustomConfigurationProvider {

this.setupWatchers();

this.disposables.push(this.headerTreeProvider);
this.loadConfigs().catch();

this.loadConfigs().then(async (found) => {
if (!found) {
await this.runGradleRefresh();
return;
}
}).catch((err) => {
logger.error('Rejected load?', err);
});
this.disposables.push(this.headerTreeProvider);
}

public async canProvideBrowseConfiguration(_?: vscode.CancellationToken | undefined): Promise<boolean> {
Expand Down Expand Up @@ -328,6 +323,9 @@ export class ApiProvider implements CustomConfigurationProvider {
}

private async couldBeUpdated(): Promise<void> {
if (!ApiProvider.promptForUpdates) {
return;
}
const result = await vscode.window.showInformationMessage('Intellisense configurations might have been updated. Refresh them now?', 'Yes', 'No');
if (result && result === 'Yes') {
await this.runGradleRefresh();
Expand Down
67 changes: 53 additions & 14 deletions vscode-wpilib/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { BuildTestAPI } from './buildtestapi';
import { BuiltinTools } from './builtintools';
import { CommandAPI } from './commandapi';
import { activateCpp } from './cpp/cpp';
import { ApiProvider } from './cppprovider/apiprovider';
import { DeployDebugAPI } from './deploydebugapi';
import { ExecuteAPI } from './executor';
import { activateJava } from './java/java';
Expand All @@ -26,7 +27,7 @@ import { promisifyMkdirp } from './shared/generator';
import { UtilitiesAPI } from './shared/utilitiesapi';
import { addVendorExamples } from './shared/vendorexamples';
import { ToolAPI } from './toolapi';
import { setExtensionContext, setJavaHome } from './utilities';
import { promisifyExists, setExtensionContext, setJavaHome } from './utilities';
import { fireVendorDepsChanged, VendorLibraries } from './vendorlibraries';
import { createVsCommands } from './vscommands';
import { AlphaError } from './webviews/alphaerror';
Expand Down Expand Up @@ -92,6 +93,8 @@ class ExternalAPI implements IExternalAPI {
}
}

let updatePromptCount = 0;

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export async function activate(context: vscode.ExtensionContext) {
Expand Down Expand Up @@ -142,7 +145,7 @@ export async function activate(context: vscode.ExtensionContext) {
let help: Help | undefined;

try {
// Create the help window provider
// Create the help window provider
help = await Help.Create(externalApi.getPreferencesAPI(), extensionResourceLocation);
context.subscriptions.push(help);
} catch (err) {
Expand All @@ -151,7 +154,7 @@ export async function activate(context: vscode.ExtensionContext) {
}

try {
// Create the eclipse import provider
// Create the eclipse import provider
const eclipseimport = await EclipseImport.Create(extensionResourceLocation);
context.subscriptions.push(eclipseimport);
} catch (err) {
Expand All @@ -160,16 +163,16 @@ export async function activate(context: vscode.ExtensionContext) {
}

try {
// Create the new project creator provider
const projectcreator = await ProjectCreator.Create(externalApi.getExampleTemplateAPI(), extensionResourceLocation);
context.subscriptions.push(projectcreator);
// Create the new project creator provider
const projectcreator = await ProjectCreator.Create(externalApi.getExampleTemplateAPI(), extensionResourceLocation);
context.subscriptions.push(projectcreator);
} catch (err) {
logger.error('error creating project creator', err);
creationError = true;
}

try {
// Add built in tools
// Add built in tools
context.subscriptions.push(await BuiltinTools.Create(externalApi));
} catch (err) {
logger.error('error creating built in tool handler', err);
Expand Down Expand Up @@ -224,12 +227,44 @@ export async function activate(context: vscode.ExtensionContext) {

if (prefs.getProjectYear() !== '2019') {
vscode.window
.showInformationMessage('This project is not compatible with this version of the extension. Please create a new project.');
.showInformationMessage('This project is not compatible with this version of the extension. Please create a new project.');
continue;
}
if (wpilibUpdate) {
await wpilibUpdate.checkForInitialUpdate(w);

if (prefs.getCurrentLanguage() === 'cpp' || prefs.getCurrentLanguage() === 'java') {
let didUpdate: boolean = false;
if (wpilibUpdate) {
didUpdate = await wpilibUpdate.checkForInitialUpdate(w);
}

let runBuild: boolean = !await promisifyExists(path.join(w.uri.fsPath, 'build'));

if (didUpdate) {
const result = await vscode.window.showInformationMessage('It is recommended to run a "Build" after a WPILib update to ensure ' +
'dependencies are installed correctly. Would you like to do this now?', {
modal: true,
}, 'Yes', 'No');
if (result !== 'Yes') {
runBuild = false;
}
}

if (runBuild) {
updatePromptCount++;
externalApi.getBuildTestAPI().buildCode(w, undefined).then(() => {
updatePromptCount--;
if (updatePromptCount === 0) {
ApiProvider.promptForUpdates = true;
}
}).catch(() => {
updatePromptCount--;
if (updatePromptCount === 0) {
ApiProvider.promptForUpdates = true;
}
});
}
}

const persistentState = new PersistentFolderState('wpilib.newProjectHelp', false, w.uri.fsPath);
if (persistentState.Value === false) {
persistentState.Value = true;
Expand Down Expand Up @@ -263,10 +298,10 @@ export async function activate(context: vscode.ExtensionContext) {
} else if (wpilibFiles.length > 1) {
// Multiple subfolders found
const openResult = await vscode.window.showInformationMessage('Incorrect folder opened for WPILib project. ' +
'Multiple possible subfolders found, ' +
'Would you like to open one? Selecting no will cause many tasks to not work.', {
modal: true,
}, 'Yes', 'No', 'No, Don\'t ask again for this folder');
'Multiple possible subfolders found, ' +
'Would you like to open one? Selecting no will cause many tasks to not work.', {
modal: true,
}, 'Yes', 'No', 'No, Don\'t ask again for this folder');
if (openResult === 'Yes') {
const list = wpilibFiles.map((value) => {
const fullRoot = path.dirname(path.dirname(value.fsPath));
Expand Down Expand Up @@ -298,6 +333,10 @@ export async function activate(context: vscode.ExtensionContext) {
// Log our extension is active
logger.log('Congratulations, your extension "vscode-wpilib" is now active!');

if (updatePromptCount === 0) {
ApiProvider.promptForUpdates = true;
}

return externalApi;
}

Expand Down
24 changes: 12 additions & 12 deletions vscode-wpilib/src/wpilibupdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@ export class WPILibUpdates {
}, this));
}

public async checkForInitialUpdate(wp: vscode.WorkspaceFolder): Promise<void> {
public async checkForInitialUpdate(wp: vscode.WorkspaceFolder): Promise<boolean> {
const grVersion = await this.getGradleRIOVersion(wp);
if (grVersion === undefined) {
return;
return false;
}
const newVersion = await this.checkForLocalGradleRIOUpdate(grVersion);
const persistentState = WPILibUpdates.getUpdatePersistentState(wp);
if (newVersion !== undefined && persistentState.Value === false) {
vscode.window.showInformationMessage
const result = await vscode.window.showInformationMessage
(`WPILib project update (${newVersion}) found, would you like to install it? ` +
`${grVersion} currently installed`, {
modal: true,
}, 'Yes', 'No', 'No, Don\'t ask again')
.then(async (result) => {
if (result !== undefined && result === 'Yes') {
await this.setGradleRIOVersion(newVersion, wp);
} else if (result !== undefined && result === 'No, Don\'t ask again') {
persistentState.Value = true;
}
});
}, 'Yes', 'No', 'No, Don\'t ask again');
if (result !== undefined && result === 'Yes') {
await this.setGradleRIOVersion(newVersion, wp);
return true;
} else if (result !== undefined && result === 'No, Don\'t ask again') {
persistentState.Value = true;
}
}
return false;
}

public async checkForUpdates(): Promise<boolean> {
Expand Down Expand Up @@ -98,7 +98,7 @@ export class WPILibUpdates {
}
}

private async setGradleRIOVersion(version: string, wp: vscode.WorkspaceFolder): Promise<void> {
public async setGradleRIOVersion(version: string, wp: vscode.WorkspaceFolder): Promise<void> {
try {
const buildFile = path.join(wp.uri.fsPath, 'build.gradle');
const gradleBuildFile = await promisifyReadFile(buildFile);
Expand Down