import * as vscode from "vscode" ; import { diagnosticProvider , MAVEN_DEPENDENCY_CONFLICT } from "../DiagnosticProvider" ; import { mavenExplorerProvider } from "../explorer/mavenExplorerProvider" ; import { Dependency } from "../explorer/model/Dependency" ; export class ConflictResolver implements vscode . CodeActionProvider { public static readonly providedCodeActionKinds : vscode . CodeActionKind [ ] = [ vscode . CodeActionKind . QuickFix ] ; public provideCodeActions ( document , _range , context , _token ) { return context . diagnostics . filter ( diagnostic => diagnostic . code === MAVEN_DEPENDENCY_CONFLICT ) . map ( diagnostic => this . createCommandCodeAction ( diagnostic , document ) ) ; } private createCommandCodeAction ( diagnostic , document ) { const node = diagnosticProvider . map . get ( diagnostic ) ; if ( node === undefined ) { throw new Error ( "Failed to find Dependency." ) ; } const gid = node . groupId ; const aid = node . artifactId ; const effectiveVersion = node . omittedStatus ?. effectiveVersion ?? node . version ; const actionSetVersion = new vscode . CodeAction ( `Resolve conflict for ${ gid }:${ aid }` , vscode . CodeActionKind . QuickFix ) ; actionSetVersion . command = { command : "maven.project.setDependencyVersion" , title : "set version to" , arguments : [ { pomPath : document . uri . fsPath , effectiveVersion , groupId : gid , artifactId : aid , fullDependencyText : mavenExplorerProvider . getMavenProject ( document . uri . fsPath ) ?. fullText } ] } ; actionSetVersion . diagnostics = [ diagnostic ] ; actionSetVersion . isPreferred = true ; return actionSetVersion ; } } export const conflictResolver = new ConflictResolver ( ) ;