From 94fee23612b5023574fdea9d6477b0c735df02f0 Mon Sep 17 00:00:00 2001 From: Thad House Date: Fri, 18 Jan 2019 17:08:04 -0800 Subject: [PATCH] Build automatically upon opening new project Both if cloning from git, or creating a new project, a build sets up a lot of things, and helps ensure things are correctly working. --- vscode-wpilib/src/cpp/buildtest.ts | 2 +- vscode-wpilib/src/cppprovider/apiprovider.ts | 16 ++--- vscode-wpilib/src/extension.ts | 67 ++++++++++++++++---- vscode-wpilib/src/wpilibupdates.ts | 24 +++---- 4 files changed, 73 insertions(+), 36 deletions(-) diff --git a/vscode-wpilib/src/cpp/buildtest.ts b/vscode-wpilib/src/cpp/buildtest.ts index 4de21307..acd7367f 100644 --- a/vscode-wpilib/src/cpp/buildtest.ts +++ b/vscode-wpilib/src/cpp/buildtest.ts @@ -21,7 +21,7 @@ class CodeBuilder implements ICodeBuilder { } public async runBuilder(workspace: vscode.WorkspaceFolder): Promise { - 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()); diff --git a/vscode-wpilib/src/cppprovider/apiprovider.ts b/vscode-wpilib/src/cppprovider/apiprovider.ts index 49f55ad4..9fa58fa8 100644 --- a/vscode-wpilib/src/cppprovider/apiprovider.ts +++ b/vscode-wpilib/src/cppprovider/apiprovider.ts @@ -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'; @@ -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 { @@ -328,6 +323,9 @@ export class ApiProvider implements CustomConfigurationProvider { } private async couldBeUpdated(): Promise { + 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(); diff --git a/vscode-wpilib/src/extension.ts b/vscode-wpilib/src/extension.ts index 07b3a171..ebda58bc 100644 --- a/vscode-wpilib/src/extension.ts +++ b/vscode-wpilib/src/extension.ts @@ -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'; @@ -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'; @@ -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) { @@ -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) { @@ -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) { @@ -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); @@ -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; @@ -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)); @@ -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; } diff --git a/vscode-wpilib/src/wpilibupdates.ts b/vscode-wpilib/src/wpilibupdates.ts index a4a26bac..0e83bfa8 100644 --- a/vscode-wpilib/src/wpilibupdates.ts +++ b/vscode-wpilib/src/wpilibupdates.ts @@ -33,27 +33,27 @@ export class WPILibUpdates { }, this)); } - public async checkForInitialUpdate(wp: vscode.WorkspaceFolder): Promise { + public async checkForInitialUpdate(wp: vscode.WorkspaceFolder): Promise { 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 { @@ -98,7 +98,7 @@ export class WPILibUpdates { } } - private async setGradleRIOVersion(version: string, wp: vscode.WorkspaceFolder): Promise { + public async setGradleRIOVersion(version: string, wp: vscode.WorkspaceFolder): Promise { try { const buildFile = path.join(wp.uri.fsPath, 'build.gradle'); const gradleBuildFile = await promisifyReadFile(buildFile);