Skip to content

Commit

Permalink
✨ Support reviewing resolutions with merge editor (#103)
Browse files Browse the repository at this point in the history
Changes:
1. add optional configuration property "diffEditorType". If set to
   "merge" then open resolutions using merge editor. Otherwise use
   the diff editor.
2. create text document content provider for serving read only virtual
   files to be used as left side of the merge. Register the provider
   under "konveyorReadOnly" scheme.

---------

Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko authored Nov 21, 2024
1 parent 88daae4 commit 126cbe9
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 10 deletions.
24 changes: 18 additions & 6 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,23 @@
"category": "diffEditor",
"title": "Apply Block"
},
{
"command": "konveyor.diffView.applySelectionInline",
"icon": "$(check)",
"category": "diffEditor",
"title": "Apply Selection"
},
{
"command": "konveyor.diffView.applyBlock",
"icon": "$(arrow-left)",
"category": "diffEditor",
"title": "Apply Block"
},
{
"command": "konveyor.diffView.applySelection",
"icon": "$(arrow-left)",
"category": "diffEditor",
"title": "Apply Selection"
}
],
"submenus": [
Expand Down Expand Up @@ -262,26 +274,26 @@
],
"diffEditor/gutter/selection": [
{
"command": "konveyor.diffView.applyBlockInline",
"command": "konveyor.diffView.applySelectionInline",
"group": "primary",
"when": "diffEditorModifiedWritable && diffEditorInlineMode && (diffEditorModifiedUri =~ /^konveyorMemFs\\:.*$/ || diffEditorOriginalUri =~ /^konveyorMemFs\\:.*$/)"
"when": "diffEditorInlineMode && ((diffEditorModifiedUri =~ /^konveyorMemFs\\:.*$/ && diffEditorOriginalWritable) || (diffEditorOriginalUri =~ /^konveyorMemFs\\:.*$/ && diffEditorModifiedWritable))"
},
{
"command": "konveyor.diffView.applyBlock",
"command": "konveyor.diffView.applySelection",
"group": "primary",
"when": "diffEditorModifiedWritable && !diffEditorInlineMode && (diffEditorModifiedUri =~ /^konveyorMemFs\\:.*$/ || diffEditorOriginalUri =~ /^konveyorMemFs\\:.*$/)"
"when": "!diffEditorInlineMode && ((diffEditorModifiedUri =~ /^konveyorMemFs\\:.*$/ && diffEditorOriginalWritable) || (diffEditorOriginalUri =~ /^konveyorMemFs\\:.*$/ && diffEditorModifiedWritable))"
}
],
"diffEditor/gutter/hunk": [
{
"command": "konveyor.diffView.applyBlockInline",
"group": "primary",
"when": "diffEditorModifiedWritable && diffEditorInlineMode && (diffEditorModifiedUri =~ /^konveyorMemFs\\:.*$/ || diffEditorOriginalUri =~ /^konveyorMemFs\\:.*$/)"
"when": "diffEditorInlineMode && ((diffEditorModifiedUri =~ /^konveyorMemFs\\:.*$/ && diffEditorOriginalWritable) || (diffEditorOriginalUri =~ /^konveyorMemFs\\:.*$/ && diffEditorModifiedWritable))"
},
{
"command": "konveyor.diffView.applyBlock",
"group": "primary",
"when": "diffEditorModifiedWritable && !diffEditorInlineMode && (diffEditorModifiedUri =~ /^konveyorMemFs\\:.*$/ || diffEditorOriginalUri =~ /^konveyorMemFs\\:.*$/)"
"when": "!diffEditorInlineMode && ((diffEditorModifiedUri =~ /^konveyorMemFs\\:.*$/ && diffEditorOriginalWritable) || (diffEditorOriginalUri =~ /^konveyorMemFs\\:.*$/ && diffEditorModifiedWritable))"
}
],
"explorer/context": [
Expand Down
2 changes: 2 additions & 0 deletions vscode/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ const commandsMap: (state: ExtensionState) => {
"konveyor.reloadLastResolutions": () => reloadLastResolutions(state),
"konveyor.diffView.applyBlock": applyBlock,
"konveyor.diffView.applyBlockInline": applyBlock,
"konveyor.diffView.applySelection": applyBlock,
"konveyor.diffView.applySelectionInline": applyBlock,
};
};

Expand Down
17 changes: 17 additions & 0 deletions vscode/src/data/readOnlyStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
CancellationToken,
Event,
ProviderResult,
TextDocumentContentProvider,
Uri,
workspace,
} from "vscode";

export default class KonveyorReadOnlyProvider implements TextDocumentContentProvider {
onDidChange?: Event<Uri> | undefined;
provideTextDocumentContent(uri: Uri, _token: CancellationToken): ProviderResult<string> {
return workspace.fs
.readFile(Uri.from({ ...uri, scheme: "file" }))
.then((buffer) => buffer?.toString() ?? "");
}
}
12 changes: 11 additions & 1 deletion vscode/src/diffView/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as vscode from "vscode";
import { KonveyorTreeDataProvider } from "./fileModel";
import { Navigation } from "./navigation";
import { ExtensionState } from "src/extensionState";
import { KONVEYOR_SCHEME } from "../utilities";
import { KONVEYOR_READ_ONLY_SCHEME, KONVEYOR_SCHEME } from "../utilities";
import KonveyorReadOnlyProvider from "../data/readOnlyStorage";

export function registerDiffView({
extensionContext: context,
Expand All @@ -29,4 +30,13 @@ export function registerDiffView({
provider.onDidChangeTreeData(() => {
treeView.message = model.message;
});

const readOnlyProvider = new KonveyorReadOnlyProvider();

context.subscriptions.push(
vscode.workspace.registerTextDocumentContentProvider(
KONVEYOR_READ_ONLY_SCHEME,
readOnlyProvider,
),
);
}
27 changes: 24 additions & 3 deletions vscode/src/diffView/solutionCommands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode";
import { ExtensionState } from "src/extensionState";
import { fromRelativeToKonveyor } from "../utilities";
import { fromRelativeToKonveyor, KONVEYOR_READ_ONLY_SCHEME } from "../utilities";
import { FileItem, toUri } from "./fileModel";

export const applyAll = async (state: ExtensionState) => {
Expand Down Expand Up @@ -31,12 +31,33 @@ export const discardAll = async (state: ExtensionState) => {
vscode.window.showInformationMessage(`Discarded all resolutions`);
};

export const viewFix = (uri: vscode.Uri, preserveFocus: boolean = false) =>
export const viewFix = async (uri: vscode.Uri, preserveFocus: boolean) =>
vscode.workspace.getConfiguration("konveyor")?.get("diffEditorType") === "merge"
? viewFixInMergeEditor(uri, preserveFocus)
: viewFixInDiffEditor(uri, preserveFocus);

export const viewFixInMergeEditor = async (uri: vscode.Uri, preserveFocus: boolean = false) => {
const readOnlyUri = vscode.Uri.from({ ...uri, scheme: KONVEYOR_READ_ONLY_SCHEME });
const options = {
base: readOnlyUri,
input1: { uri: readOnlyUri, title: "Current" },
input2: {
uri: fromRelativeToKonveyor(vscode.workspace.asRelativePath(uri)),
title: "Suggested",
},
output: uri,
options: { preserveFocus },
};

await vscode.commands.executeCommand("_open.mergeEditor", options);
};

export const viewFixInDiffEditor = async (uri: vscode.Uri, preserveFocus: boolean = false) =>
vscode.commands.executeCommand(
"vscode.diff",
uri,
fromRelativeToKonveyor(vscode.workspace.asRelativePath(uri)),
"Current file <-> Suggested changes",
"Current Suggested",
{
preserveFocus,
},
Expand Down
1 change: 1 addition & 0 deletions vscode/src/utilities/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const KONVEYOR_SCHEME = "konveyorMemFs";
export const KONVEYOR_READ_ONLY_SCHEME = "konveyorReadOnly";
export const RULE_SET_DATA_FILE_PREFIX = "analysis";
export const SOLUTION_DATA_FILE_PREFIX = "solution";

0 comments on commit 126cbe9

Please sign in to comment.