Skip to content

Commit

Permalink
feat: check that the correct version of DiscoPoP is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
goerlibe committed Jan 24, 2024
1 parent ff3bc25 commit c3562ef
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
42 changes: 41 additions & 1 deletion src/DiscoPoPExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { ToolSuite } from './runners/tools/ToolSuite'
import { CancellationError } from './runners/helpers/cancellation/CancellationError'
import { OptimizerWorkflow } from './runners/workflows/OptimizerWorkflow'
import { OptimizerWorkflowUI } from './runners/workflows/OptimizerWorkflowUI'
import { DiscoPoPConfigProvider } from './runners/tools/DiscoPoPConfigProvider'
import { CommandExecution } from './runners/helpers/CommandExecution'

function logAndShowErrorMessageHandler(error: any, optionalMessage?: string) {
if (optionalMessage) {
Expand Down Expand Up @@ -178,7 +180,7 @@ export class DiscoPoPExtension {
)
}

public activate() {
public async activate() {
vscode.commands.executeCommand(
'setContext',
'discopop.codeLensEnabled',
Expand All @@ -191,6 +193,44 @@ export class DiscoPoPExtension {
false
)

// issue a warning if DiscoPoP is not installed or the the installed version of DiscoPoP may be incompatible
const contextProvider = new DiscoPoPConfigProvider()
if (
!(await CommandExecution.commandExists(
'discopop_config_provider',
false
))
) {
vscode.window.showErrorMessage(
'WARNING: DiscoPoP not found. Please install DiscoPoP.'
)
}
const installedVersion = await contextProvider.version
const expectedVersion = '3.2.0'
if (!(installedVersion === expectedVersion)) {
console.error(
'Possible version mismatch between DiscoPoP and DiscoPoP VSCode Extension: Installed version: ' +
installedVersion +
', Expected version: ' +
expectedVersion
)
vscode.window
.showErrorMessage(
'WARNING: DiscoPoP version mismatch detected. Please install the correct DiscoPoP version for full compatibility.',
'Show details'
)
.then((value) => {
if (value === 'Show details') {
vscode.window.showInformationMessage(
'Installed version: ' +
installedVersion +
'\nExpected version: ' +
expectedVersion
)
}
})
}

this.context.subscriptions.push(
vscode.commands.registerCommand(
Commands.editConfigurationOrProperty,
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { DiscoPoPExtension } from './DiscoPoPExtension'

let extension: DiscoPoPExtension | undefined = undefined

export function activate(context: vscode.ExtensionContext) {
export async function activate(context: vscode.ExtensionContext) {
extension = new DiscoPoPExtension(context)
extension.activate()
await extension.activate()
}

// this method is called when your extension is deactivated
Expand Down
15 changes: 15 additions & 0 deletions src/runners/tools/DiscoPoPConfigProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ export class DiscoPoPConfigProvider {

// TODO allow to get the version of DiscoPoP

public get version(): Promise<string> {
return CommandExecution.commandExists(
'discopop_config_provider',
true,
'Is DiscoPoP installed?'
).then((exists) => {
return CommandExecution.execute({
command: 'discopop_config_provider --version',
throwOnNonZeroExitCode: true,
}).then((result) => {
return result.stdout
})
})
}

public get buildDirectory(): Promise<string> {
return CommandExecution.commandExists(
'discopop_config_provider',
Expand Down

0 comments on commit c3562ef

Please sign in to comment.