vscode 合并编辑器:将两个输入文件进行比较

nwwlzxa7  于 6个月前  发布在  Vscode
关注(0)|答案(5)|浏览(62)

当前,我们只是查看input1和base之间的差异以及input2和base之间的差异。
然而,如果input1和input2相对于base引起的编辑相同,我们应该更智能。
默认情况下,git使用冲突样式merge,它将更改彼此进行比较并接受最长公共子字符串。
我们的实现匹配git的diff3冲突样式,这不会将公共行移出冲突。
相关:#155965
创建一个名为conflict的新分支
在新分支上创建并提交一个文件merge_conflict_test.go,名称为“n1”

// branch conflict
package main

import (
	"github.com/gin-gonic/gin"
)

func Foo1(c *gin.Context) {
	s1 := s{
		ID:        111,
		Condition: "c1",
		Check:     true,
		Name:      "n1" // diff from master
	}
}

func Foo2(c *gin.Context) {
	line1 := "line1"
	line2 := "line2"
	line3 := "line3"
	line4 := "line4"
	line5 := "line5"
	line6 := "line6"
}

func Foo3(c *gin.Context) {
	s3 := s{
		ID:        123,
		Condition: "c3",
		Check:     true,
		Name:      "n3" // diff from master
	}
}

返回到master分支,也在新分支上创建并提交一个文件merge_conflict_test.go,名称为“n1”

// branch master
package main

import (
	"github.com/gin-gonic/gin"
)

func Foo1(c *gin.Context) {
	s1 := s{
		ID:        111,
		Condition: "c1",
		Check:     true,
	}
}

func Foo2(c *gin.Context) {
	line1 := "line1"
	line2 := "line2"
	line3 := "line3"
	line4 := "line4"
	line5 := "line5"
	line6 := "line6"
}

func Foo3(c *gin.Context) {
	s3 := s{
		ID:        123,
		Condition: "c3",
		Check:     true,
	}
}

提交后,转到conflict分支,重新基于master

在上面加上**"git.mergeEditor": false**

3种合并编辑器:

  • 最初由@Void-king在#157469(评论)中发布*
kknvjkwl

kknvjkwl1#

相关:#157997 (评论) 在 #157997

44u64gxh

44u64gxh2#

这是一个反例,当对两侧进行差异化处理时,体验会变得更糟:

在不移除公共前缀/后缀的情况下,这两个更改可以很容易地合并:

siotufzp

siotufzp3#

是否有办法让复选框体验回来?我更喜欢复选框而不是当前的codesens提示。

mqkwyuun

mqkwyuun4#

另一个我刚刚遇到的Git行为令人困惑的例子:
GitHub/git (冲突是什么?):

VS Code 合并编辑器(显然左边有人插入了两个方法,右边有人添加了一个方法):

1aaf6o9v

1aaf6o9v5#

这个更糟糕:
GitHub(完全无法使用的差异):

VS Code:

两者都很混乱,但VS Code也比较幸运,得到了一个更好的差异,所以它要少混乱一些。

{
    "languageId": "typescript",
    "base": "/*---------------------------------------------------------------------------------------------\n *  Copyright (c) Microsoft Corporation. All rights reserved.\n *  Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { Codicon } from 'vs/base/common/codicons';\nimport { ICodeEditor } from 'vs/editor/browser/editorBrowser';\nimport { EditorAction2, ServicesAccessor } from 'vs/editor/browser/editorExtensions';\nimport { findFocusedDiffEditor } from 'vs/editor/browser/widget/diffEditor.contribution';\nimport { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2';\nimport { EditorContextKeys } from 'vs/editor/common/editorContextKeys';\nimport { localize } from 'vs/nls';\nimport { ILocalizedString } from 'vs/platform/action/common/action';\nimport { Action2, MenuId, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions';\nimport { IConfigurationService } from 'vs/platform/configuration/common/configuration';\nimport { ContextKeyEqualsExpr, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';\n\nexport class ToggleCollapseUnchangedRegions extends Action2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.toggleCollapseUnchangedRegions',\n\t\t\ttitle: { value: localize('toggleCollapseUnchangedRegions', \"Toggle Collapse Unchanged Regions\"), original: 'Toggle Collapse Unchanged Regions' },\n\t\t\ticon: Codicon.map,\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\n\t\t\ttoggled: ContextKeyExpr.has('config.diffEditor.experimental.collapseUnchangedRegions'),\n\t\t\tmenu: {\n\t\t\t\tid: MenuId.EditorTitle,\n\t\t\t\torder: 22,\n\t\t\t\tgroup: 'navigation',\n\t\t\t\twhen: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\n\t\t\t},\n\t\t});\n\t}\n\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\n\t\tconst configurationService = accessor.get(IConfigurationService);\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.experimental.collapseUnchangedRegions');\n\t\tconfigurationService.updateValue('diffEditor.experimental.collapseUnchangedRegions', newValue);\n\t}\n}\n\nregisterAction2(ToggleCollapseUnchangedRegions);\n\nexport class ToggleShowMovedCodeBlocks extends Action2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.toggleShowMovedCodeBlocks',\n\t\t\ttitle: { value: localize('toggleShowMovedCodeBlocks', \"Toggle Show Moved Code Blocks\"), original: 'Toggle Show Moved Code Blocks' },\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\n\t\t});\n\t}\n\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\n\t\tconst configurationService = accessor.get(IConfigurationService);\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.experimental.showMoves');\n\t\tconfigurationService.updateValue('diffEditor.experimental.showMoves', newValue);\n\t}\n}\n\nregisterAction2(ToggleShowMovedCodeBlocks);\n\nexport class ToggleUseInlineViewWhenSpaceIsLimited extends Action2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.toggleUseInlineViewWhenSpaceIsLimited',\n\t\t\ttitle: { value: localize('toggleUseInlineViewWhenSpaceIsLimited', \"Toggle Use Inline View When Space Is Limited\"), original: 'Toggle Use Inline View When Space Is Limited' },\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\n\t\t});\n\t}\n\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\n\t\tconst configurationService = accessor.get(IConfigurationService);\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.useInlineViewWhenSpaceIsLimited');\n\t\tconfigurationService.updateValue('diffEditor.useInlineViewWhenSpaceIsLimited', newValue);\n\t}\n}\n\nregisterAction2(ToggleUseInlineViewWhenSpaceIsLimited);\n\nMenuRegistry.appendMenuItem(MenuId.EditorTitle, {\n\tcommand: {\n\t\tid: new ToggleUseInlineViewWhenSpaceIsLimited().desc.id,\n\t\ttitle: localize('useInlineViewWhenSpaceIsLimited', \"Use Inline View When Space Is Limited\"),\n\t\ttoggled: ContextKeyExpr.has('config.diffEditor.useInlineViewWhenSpaceIsLimited'),\n\t},\n\torder: 11,\n\tgroup: '1_diff',\n\twhen: ContextKeyExpr.and(\n\t\tEditorContextKeys.diffEditorRenderSideBySideInlineBreakpointReached,\n\t\tContextKeyEqualsExpr.create('diffEditorVersion', 2)\n\t)\n});\n\n/*\nTODO@hediet add this back once move detection is more polished.\nUsers can still enable this via settings.json (config.diffEditor.experimental.showMoves).\n\nMenuRegistry.appendMenuItem(MenuId.EditorTitle, {\n\tcommand: {\n\t\tid: new ToggleShowMovedCodeBlocks().desc.id,\n\t\ttitle: localize('showMoves', \"Show Moves\"),\n\t\ticon: Codicon.move,\n\t\ttoggled: ContextKeyEqualsExpr.create('config.diffEditor.experimental.showMoves', true),\n\t},\n\torder: 10,\n\tgroup: '1_diff',\n\twhen: ContextKeyEqualsExpr.create('diffEditorVersion', 2)\n});\n*/\n\nconst diffEditorCategory: ILocalizedString = {\n\tvalue: localize('diffEditor', 'Diff Editor'),\n\toriginal: 'Diff Editor',\n};\nexport class SwitchSide extends EditorAction2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.switchSide',\n\t\t\ttitle: { value: localize('switchSide', \"Switch Side\"), original: 'Switch Side' },\n\t\t\ticon: Codicon.arrowSwap,\n\t\t\tprecondition: ContextKeyExpr.and(ContextKeyEqualsExpr.create('diffEditorVersion', 2), ContextKeyExpr.has('isInDiffEditor')),\n\t\t\tf1: true,\n\t\t\tcategory: diffEditorCategory,\n\t\t});\n\t}\n\n\trunEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, ...args: unknown[]): void {\n\t\tconst diffEditor = findFocusedDiffEditor(accessor);\n\t\tif (diffEditor instanceof DiffEditorWidget2) {\n\t\t\tdiffEditor.switchSide();\n\t\t}\n\t}\n}\n\nregisterAction2(SwitchSide);\n",
    "input1": "/*---------------------------------------------------------------------------------------------\n *  Copyright (c) Microsoft Corporation. All rights reserved.\n *  Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { Codicon } from 'vs/base/common/codicons';\nimport { KeyCode } from 'vs/base/common/keyCodes';\nimport { ICodeEditor } from 'vs/editor/browser/editorBrowser';\nimport { EditorAction2, ServicesAccessor } from 'vs/editor/browser/editorExtensions';\nimport { findFocusedDiffEditor } from 'vs/editor/browser/widget/diffEditor.contribution';\nimport { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2';\nimport { EditorContextKeys } from 'vs/editor/common/editorContextKeys';\nimport { localize } from 'vs/nls';\nimport { ILocalizedString } from 'vs/platform/action/common/action';\nimport { Action2, MenuId, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions';\nimport { IConfigurationService } from 'vs/platform/configuration/common/configuration';\nimport { ContextKeyEqualsExpr, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';\n\nexport class ToggleCollapseUnchangedRegions extends Action2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.toggleCollapseUnchangedRegions',\n\t\t\ttitle: { value: localize('toggleCollapseUnchangedRegions', \"Toggle Collapse Unchanged Regions\"), original: 'Toggle Collapse Unchanged Regions' },\n\t\t\ticon: Codicon.map,\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\n\t\t\ttoggled: ContextKeyExpr.has('config.diffEditor.experimental.collapseUnchangedRegions'),\n\t\t\tmenu: {\n\t\t\t\tid: MenuId.EditorTitle,\n\t\t\t\torder: 22,\n\t\t\t\tgroup: 'navigation',\n\t\t\t\twhen: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\n\t\t\t},\n\t\t});\n\t}\n\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\n\t\tconst configurationService = accessor.get(IConfigurationService);\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.experimental.collapseUnchangedRegions');\n\t\tconfigurationService.updateValue('diffEditor.experimental.collapseUnchangedRegions', newValue);\n\t}\n}\n\nregisterAction2(ToggleCollapseUnchangedRegions);\n\nexport class ToggleShowMovedCodeBlocks extends Action2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.toggleShowMovedCodeBlocks',\n\t\t\ttitle: { value: localize('toggleShowMovedCodeBlocks', \"Toggle Show Moved Code Blocks\"), original: 'Toggle Show Moved Code Blocks' },\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\n\t\t});\n\t}\n\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\n\t\tconst configurationService = accessor.get(IConfigurationService);\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.experimental.showMoves');\n\t\tconfigurationService.updateValue('diffEditor.experimental.showMoves', newValue);\n\t}\n}\n\nregisterAction2(ToggleShowMovedCodeBlocks);\n\nexport class ToggleUseInlineViewWhenSpaceIsLimited extends Action2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.toggleUseInlineViewWhenSpaceIsLimited',\n\t\t\ttitle: { value: localize('toggleUseInlineViewWhenSpaceIsLimited', \"Toggle Use Inline View When Space Is Limited\"), original: 'Toggle Use Inline View When Space Is Limited' },\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\n\t\t});\n\t}\n\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\n\t\tconst configurationService = accessor.get(IConfigurationService);\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.useInlineViewWhenSpaceIsLimited');\n\t\tconfigurationService.updateValue('diffEditor.useInlineViewWhenSpaceIsLimited', newValue);\n\t}\n}\n\nregisterAction2(ToggleUseInlineViewWhenSpaceIsLimited);\n\nMenuRegistry.appendMenuItem(MenuId.EditorTitle, {\n\tcommand: {\n\t\tid: new ToggleUseInlineViewWhenSpaceIsLimited().desc.id,\n\t\ttitle: localize('useInlineViewWhenSpaceIsLimited', \"Use Inline View When Space Is Limited\"),\n\t\ttoggled: ContextKeyExpr.has('config.diffEditor.useInlineViewWhenSpaceIsLimited'),\n\t},\n\torder: 11,\n\tgroup: '1_diff',\n\twhen: ContextKeyExpr.and(\n\t\tEditorContextKeys.diffEditorRenderSideBySideInlineBreakpointReached,\n\t\tContextKeyEqualsExpr.create('diffEditorVersion', 2)\n\t)\n});\n\nMenuRegistry.appendMenuItem(MenuId.EditorTitle, {\n\tcommand: {\n\t\tid: new ToggleShowMovedCodeBlocks().desc.id,\n\t\ttitle: localize('showMoves', \"Show Moved Code Blocks\"),\n\t\ticon: Codicon.move,\n\t\ttoggled: ContextKeyEqualsExpr.create('config.diffEditor.experimental.showMoves', true),\n\t},\n\torder: 10,\n\tgroup: '1_diff',\n\twhen: ContextKeyEqualsExpr.create('diffEditorVersion', 2)\n});\n\nconst diffEditorCategory: ILocalizedString = {\n\tvalue: localize('diffEditor', 'Diff Editor'),\n\toriginal: 'Diff Editor',\n};\nexport class SwitchSide extends EditorAction2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.switchSide',\n\t\t\ttitle: { value: localize('switchSide', \"Switch Side\"), original: 'Switch Side' },\n\t\t\ticon: Codicon.arrowSwap,\n\t\t\tprecondition: ContextKeyExpr.and(ContextKeyEqualsExpr.create('diffEditorVersion', 2), ContextKeyExpr.has('isInDiffEditor')),\n\t\t\tf1: true,\n\t\t\tcategory: diffEditorCategory,\n\t\t});\n\t}\n\n\trunEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, arg?: { dryRun: boolean }): unknown {\n\t\tconst diffEditor = findFocusedDiffEditor(accessor);\n\t\tif (diffEditor instanceof DiffEditorWidget2) {\n\t\t\tif (arg && arg.dryRun) {\n\t\t\t\treturn { destinationSelection: diffEditor.mapToOtherSide().destinationSelection };\n\t\t\t} else {\n\t\t\t\tdiffEditor.switchSide();\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n}\n\nregisterAction2(SwitchSide);\n\nexport class ExitCompareMove extends EditorAction2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.exitCompareMove',\n\t\t\ttitle: { value: localize('exitCompareMove', \"Exit Compare Move\"), original: 'Exit Compare Move' },\n\t\t\ticon: Codicon.close,\n\t\t\tprecondition: EditorContextKeys.comparingMovedCode,\n\t\t\tf1: false,\n\t\t\tcategory: diffEditorCategory,\n\t\t\tkeybinding: {\n\t\t\t\tweight: 10000,\n\t\t\t\tprimary: KeyCode.Escape,\n\t\t\t}\n\t\t});\n\t}\n\n\trunEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, ...args: unknown[]): void {\n\t\tconst diffEditor = findFocusedDiffEditor(accessor);\n\t\tif (diffEditor instanceof DiffEditorWidget2) {\n\t\t\tdiffEditor.exitCompareMove();\n\t\t}\n\t}\n}\n\nregisterAction2(ExitCompareMove);\n",
    "input2": "/*---------------------------------------------------------------------------------------------\n *  Copyright (c) Microsoft Corporation. All rights reserved.\n *  Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { Codicon } from 'vs/base/common/codicons';\nimport { ICodeEditor } from 'vs/editor/browser/editorBrowser';\nimport { EditorAction2, ServicesAccessor } from 'vs/editor/browser/editorExtensions';\nimport { findFocusedDiffEditor } from 'vs/editor/browser/widget/diffEditor.contribution';\nimport { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2';\nimport { EditorContextKeys } from 'vs/editor/common/editorContextKeys';\nimport { localize } from 'vs/nls';\nimport { ILocalizedString } from 'vs/platform/action/common/action';\nimport { Action2, MenuId, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions';\nimport { IConfigurationService } from 'vs/platform/configuration/common/configuration';\nimport { ContextKeyEqualsExpr, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';\n\nexport class ToggleCollapseUnchangedRegions extends Action2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.toggleCollapseUnchangedRegions',\n\t\t\ttitle: { value: localize('toggleCollapseUnchangedRegions', \"Toggle Collapse Unchanged Regions\"), original: 'Toggle Collapse Unchanged Regions' },\n\t\t\ticon: Codicon.map,\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\n\t\t\ttoggled: ContextKeyExpr.has('config.diffEditor.experimental.collapseUnchangedRegions'),\n\t\t\tmenu: {\n\t\t\t\tid: MenuId.EditorTitle,\n\t\t\t\torder: 22,\n\t\t\t\tgroup: 'navigation',\n\t\t\t\twhen: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\n\t\t\t},\n\t\t});\n\t}\n\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\n\t\tconst configurationService = accessor.get(IConfigurationService);\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.experimental.collapseUnchangedRegions');\n\t\tconfigurationService.updateValue('diffEditor.experimental.collapseUnchangedRegions', newValue);\n\t}\n}\n\nregisterAction2(ToggleCollapseUnchangedRegions);\n\nexport class ToggleShowMovedCodeBlocks extends Action2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.toggleShowMovedCodeBlocks',\n\t\t\ttitle: { value: localize('toggleShowMovedCodeBlocks', \"Toggle Show Moved Code Blocks\"), original: 'Toggle Show Moved Code Blocks' },\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\n\t\t});\n\t}\n\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\n\t\tconst configurationService = accessor.get(IConfigurationService);\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.experimental.showMoves');\n\t\tconfigurationService.updateValue('diffEditor.experimental.showMoves', newValue);\n\t}\n}\n\nregisterAction2(ToggleShowMovedCodeBlocks);\n\nexport class ToggleUseInlineViewWhenSpaceIsLimited extends Action2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.toggleUseInlineViewWhenSpaceIsLimited',\n\t\t\ttitle: { value: localize('toggleUseInlineViewWhenSpaceIsLimited', \"Toggle Use Inline View When Space Is Limited\"), original: 'Toggle Use Inline View When Space Is Limited' },\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\n\t\t});\n\t}\n\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\n\t\tconst configurationService = accessor.get(IConfigurationService);\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.useInlineViewWhenSpaceIsLimited');\n\t\tconfigurationService.updateValue('diffEditor.useInlineViewWhenSpaceIsLimited', newValue);\n\t}\n}\n\nregisterAction2(ToggleUseInlineViewWhenSpaceIsLimited);\n\nMenuRegistry.appendMenuItem(MenuId.EditorTitle, {\n\tcommand: {\n\t\tid: new ToggleUseInlineViewWhenSpaceIsLimited().desc.id,\n\t\ttitle: localize('useInlineViewWhenSpaceIsLimited', \"Use Inline View When Space Is Limited\"),\n\t\ttoggled: ContextKeyExpr.has('config.diffEditor.useInlineViewWhenSpaceIsLimited'),\n\t},\n\torder: 11,\n\tgroup: '1_diff',\n\twhen: ContextKeyExpr.and(\n\t\tEditorContextKeys.diffEditorRenderSideBySideInlineBreakpointReached,\n\t\tContextKeyEqualsExpr.create('diffEditorVersion', 2)\n\t)\n});\n\n/*\nTODO@hediet add this back once move detection is more polished.\nUsers can still enable this via settings.json (config.diffEditor.experimental.showMoves).\n\nMenuRegistry.appendMenuItem(MenuId.EditorTitle, {\n\tcommand: {\n\t\tid: new ToggleShowMovedCodeBlocks().desc.id,\n\t\ttitle: localize('showMoves', \"Show Moves\"),\n\t\ticon: Codicon.move,\n\t\ttoggled: ContextKeyEqualsExpr.create('config.diffEditor.experimental.showMoves', true),\n\t},\n\torder: 10,\n\tgroup: '1_diff',\n\twhen: ContextKeyEqualsExpr.create('diffEditorVersion', 2)\n});\n*/\n\nconst diffEditorCategory: ILocalizedString = {\n\tvalue: localize('diffEditor', 'Diff Editor'),\n\toriginal: 'Diff Editor',\n};\n\nexport class SwitchSide extends EditorAction2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.switchSide',\n\t\t\ttitle: { value: localize('switchSide', \"Switch Side\"), original: 'Switch Side' },\n\t\t\ticon: Codicon.arrowSwap,\n\t\t\tprecondition: ContextKeyExpr.and(ContextKeyEqualsExpr.create('diffEditorVersion', 2), ContextKeyExpr.has('isInDiffEditor')),\n\t\t\tf1: true,\n\t\t\tcategory: diffEditorCategory,\n\t\t});\n\t}\n\n\trunEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, ...args: unknown[]): void {\n\t\tconst diffEditor = findFocusedDiffEditor(accessor);\n\t\tif (diffEditor instanceof DiffEditorWidget2) {\n\t\t\tdiffEditor.switchSide();\n\t\t}\n\t}\n}\n\nregisterAction2(SwitchSide);\n\nexport class CollapseAllUnchangedRegions extends EditorAction2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.collapseAllUnchangedRegions',\n\t\t\ttitle: { value: localize('collapseAllUnchangedRegions', \"Collapse All Unchanged Regions\"), original: 'Collapse All Unchanged Regions' },\n\t\t\ticon: Codicon.fold,\n\t\t\tprecondition: ContextKeyExpr.and(ContextKeyEqualsExpr.create('diffEditorVersion', 2), ContextKeyExpr.has('isInDiffEditor')),\n\t\t\tf1: true,\n\t\t\tcategory: diffEditorCategory,\n\t\t});\n\t}\n\n\trunEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, ...args: unknown[]): void {\n\t\tconst diffEditor = findFocusedDiffEditor(accessor);\n\t\tif (diffEditor instanceof DiffEditorWidget2) {\n\t\t\tdiffEditor.collapseAllUnchangedRegions();\n\t\t}\n\t}\n}\n\nregisterAction2(CollapseAllUnchangedRegions);\n\nexport class ShowAllUnchangedRegions extends EditorAction2 {\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: 'diffEditor.showAllUnchangedRegions',\n\t\t\ttitle: { value: localize('showAllUnchangedRegions', \"Show All Unchanged Regions\"), original: 'Show All Unchanged Regions' },\n\t\t\ticon: Codicon.unfold,\n\t\t\tprecondition: ContextKeyExpr.and(ContextKeyEqualsExpr.create('diffEditorVersion', 2), ContextKeyExpr.has('isInDiffEditor')),\n\t\t\tf1: true,\n\t\t\tcategory: diffEditorCategory,\n\t\t});\n\t}\n\n\trunEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, ...args: unknown[]): void {\n\t\tconst diffEditor = findFocusedDiffEditor(accessor);\n\t\tif (diffEditor instanceof DiffEditorWidget2) {\n\t\t\tdiffEditor.showAllUnchangedRegions();\n\t\t}\n\t}\n}\n\nregisterAction2(ShowAllUnchangedRegions);\n",
    "result": "/*---------------------------------------------------------------------------------------------\r\n *  Copyright (c) Microsoft Corporation. All rights reserved.\r\n *  Licensed under the MIT License. See License.txt in the project root for license information.\r\n *--------------------------------------------------------------------------------------------*/\r\n\r\nimport { Codicon } from 'vs/base/common/codicons';\r\nimport { KeyCode } from 'vs/base/common/keyCodes';\r\nimport { ICodeEditor } from 'vs/editor/browser/editorBrowser';\r\nimport { EditorAction2, ServicesAccessor } from 'vs/editor/browser/editorExtensions';\r\nimport { findFocusedDiffEditor } from 'vs/editor/browser/widget/diffEditor.contribution';\r\nimport { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2';\r\nimport { EditorContextKeys } from 'vs/editor/common/editorContextKeys';\r\nimport { localize } from 'vs/nls';\r\nimport { ILocalizedString } from 'vs/platform/action/common/action';\r\nimport { Action2, MenuId, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions';\r\nimport { IConfigurationService } from 'vs/platform/configuration/common/configuration';\r\nimport { ContextKeyEqualsExpr, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';\r\n\r\nexport class ToggleCollapseUnchangedRegions extends Action2 {\r\n\tconstructor() {\r\n\t\tsuper({\r\n\t\t\tid: 'diffEditor.toggleCollapseUnchangedRegions',\r\n\t\t\ttitle: { value: localize('toggleCollapseUnchangedRegions', \"Toggle Collapse Unchanged Regions\"), original: 'Toggle Collapse Unchanged Regions' },\r\n\t\t\ticon: Codicon.map,\r\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\r\n\t\t\ttoggled: ContextKeyExpr.has('config.diffEditor.experimental.collapseUnchangedRegions'),\r\n\t\t\tmenu: {\r\n\t\t\t\tid: MenuId.EditorTitle,\r\n\t\t\t\torder: 22,\r\n\t\t\t\tgroup: 'navigation',\r\n\t\t\t\twhen: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\r\n\t\t\t},\r\n\t\t});\r\n\t}\r\n\r\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\r\n\t\tconst configurationService = accessor.get(IConfigurationService);\r\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.experimental.collapseUnchangedRegions');\r\n\t\tconfigurationService.updateValue('diffEditor.experimental.collapseUnchangedRegions', newValue);\r\n\t}\r\n}\r\n\r\nregisterAction2(ToggleCollapseUnchangedRegions);\r\n\r\nexport class ToggleShowMovedCodeBlocks extends Action2 {\r\n\tconstructor() {\r\n\t\tsuper({\r\n\t\t\tid: 'diffEditor.toggleShowMovedCodeBlocks',\r\n\t\t\ttitle: { value: localize('toggleShowMovedCodeBlocks', \"Toggle Show Moved Code Blocks\"), original: 'Toggle Show Moved Code Blocks' },\r\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\r\n\t\t});\r\n\t}\r\n\r\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\r\n\t\tconst configurationService = accessor.get(IConfigurationService);\r\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.experimental.showMoves');\r\n\t\tconfigurationService.updateValue('diffEditor.experimental.showMoves', newValue);\r\n\t}\r\n}\r\n\r\nregisterAction2(ToggleShowMovedCodeBlocks);\r\n\r\nexport class ToggleUseInlineViewWhenSpaceIsLimited extends Action2 {\r\n\tconstructor() {\r\n\t\tsuper({\r\n\t\t\tid: 'diffEditor.toggleUseInlineViewWhenSpaceIsLimited',\r\n\t\t\ttitle: { value: localize('toggleUseInlineViewWhenSpaceIsLimited', \"Toggle Use Inline View When Space Is Limited\"), original: 'Toggle Use Inline View When Space Is Limited' },\r\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\r\n\t\t});\r\n\t}\r\n\r\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\r\n\t\tconst configurationService = accessor.get(IConfigurationService);\r\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.useInlineViewWhenSpaceIsLimited');\r\n\t\tconfigurationService.updateValue('diffEditor.useInlineViewWhenSpaceIsLimited', newValue);\r\n\t}\r\n}\r\n\r\nregisterAction2(ToggleUseInlineViewWhenSpaceIsLimited);\r\n\r\nMenuRegistry.appendMenuItem(MenuId.EditorTitle, {\r\n\tcommand: {\r\n\t\tid: new ToggleUseInlineViewWhenSpaceIsLimited().desc.id,\r\n\t\ttitle: localize('useInlineViewWhenSpaceIsLimited', \"Use Inline View When Space Is Limited\"),\r\n\t\ttoggled: ContextKeyExpr.has('config.diffEditor.useInlineViewWhenSpaceIsLimited'),\r\n\t},\r\n\torder: 11,\r\n\tgroup: '1_diff',\r\n\twhen: ContextKeyExpr.and(\r\n\t\tEditorContextKeys.diffEditorRenderSideBySideInlineBreakpointReached,\r\n\t\tContextKeyEqualsExpr.create('diffEditorVersion', 2)\r\n\t)\r\n});\r\n\r\nMenuRegistry.appendMenuItem(MenuId.EditorTitle, {\r\n\tcommand: {\r\n\t\tid: new ToggleShowMovedCodeBlocks().desc.id,\r\n\t\ttitle: localize('showMoves', \"Show Moved Code Blocks\"),\r\n\t\ticon: Codicon.move,\r\n\t\ttoggled: ContextKeyEqualsExpr.create('config.diffEditor.experimental.showMoves', true),\r\n\t},\r\n\torder: 10,\r\n\tgroup: '1_diff',\r\n\twhen: ContextKeyEqualsExpr.create('diffEditorVersion', 2)\r\n});\r\n\r\nconst diffEditorCategory: ILocalizedString = {\r\n\tvalue: localize('diffEditor', 'Diff Editor'),\r\n\toriginal: 'Diff Editor',\r\n};\r\n\r\nexport class SwitchSide extends EditorAction2 {\r\n\tconstructor() {\r\n\t\tsuper({\r\n\t\t\tid: 'diffEditor.switchSide',\r\n\t\t\ttitle: { value: localize('switchSide', \"Switch Side\"), original: 'Switch Side' },\r\n\t\t\ticon: Codicon.arrowSwap,\r\n\t\t\tprecondition: ContextKeyExpr.and(ContextKeyEqualsExpr.create('diffEditorVersion', 2), ContextKeyExpr.has('isInDiffEditor')),\r\n\t\t\tf1: true,\r\n\t\t\tcategory: diffEditorCategory,\r\n\t\t});\r\n\t}\r\n\r\n\trunEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, arg?: { dryRun: boolean }): unknown {\r\n\t\tconst diffEditor = findFocusedDiffEditor(accessor);\r\n\t\tif (diffEditor instanceof DiffEditorWidget2) {\r\n\t\t\tif (arg && arg.dryRun) {\r\n\t\t\t\treturn { destinationSelection: diffEditor.mapToOtherSide().destinationSelection };\r\n\t\t\t} else {\r\n\t\t\t\tdiffEditor.switchSide();\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn undefined;\r\n\t}\r\n}\r\n\r\nregisterAction2(SwitchSide);\r\n\r\nexport class ExitCompareMove extends EditorAction2 {\r\n\tconstructor() {\r\n\t\tsuper({\r\n\t\t\tid: 'diffEditor.exitCompareMove',\r\n\t\t\ttitle: { value: localize('exitCompareMove', \"Exit Compare Move\"), original: 'Exit Compare Move' },\r\n\t\t\ticon: Codicon.close,\r\n\t\t\tprecondition: EditorContextKeys.comparingMovedCode,\r\n\t\t\tf1: false,\r\n\t\t\tcategory: diffEditorCategory,\r\n\t\t\tkeybinding: {\r\n\t\t\t\tweight: 10000,\r\n\t\t\t\tprimary: KeyCode.Escape,\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n\trunEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, ...args: unknown[]): void {\r\n\t\tconst diffEditor = findFocusedDiffEditor(accessor);\r\n\t\tif (diffEditor instanceof DiffEditorWidget2) {\r\n\t\t\tdiffEditor.exitCompareMove();\r\n\t\t}\r\n\t}\r\n}\r\n\r\nregisterAction2(SwitchSide);\r\n",
    "initialResult": "/*---------------------------------------------------------------------------------------------\r\n *  Copyright (c) Microsoft Corporation. All rights reserved.\r\n *  Licensed under the MIT License. See License.txt in the project root for license information.\r\n *--------------------------------------------------------------------------------------------*/\r\n\r\nimport { Codicon } from 'vs/base/common/codicons';\r\nimport { KeyCode } from 'vs/base/common/keyCodes';\r\nimport { ICodeEditor } from 'vs/editor/browser/editorBrowser';\r\nimport { EditorAction2, ServicesAccessor } from 'vs/editor/browser/editorExtensions';\r\nimport { findFocusedDiffEditor } from 'vs/editor/browser/widget/diffEditor.contribution';\r\nimport { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2';\r\nimport { EditorContextKeys } from 'vs/editor/common/editorContextKeys';\r\nimport { localize } from 'vs/nls';\r\nimport { ILocalizedString } from 'vs/platform/action/common/action';\r\nimport { Action2, MenuId, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions';\r\nimport { IConfigurationService } from 'vs/platform/configuration/common/configuration';\r\nimport { ContextKeyEqualsExpr, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';\r\n\r\nexport class ToggleCollapseUnchangedRegions extends Action2 {\r\n\tconstructor() {\r\n\t\tsuper({\r\n\t\t\tid: 'diffEditor.toggleCollapseUnchangedRegions',\r\n\t\t\ttitle: { value: localize('toggleCollapseUnchangedRegions', \"Toggle Collapse Unchanged Regions\"), original: 'Toggle Collapse Unchanged Regions' },\r\n\t\t\ticon: Codicon.map,\r\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\r\n\t\t\ttoggled: ContextKeyExpr.has('config.diffEditor.experimental.collapseUnchangedRegions'),\r\n\t\t\tmenu: {\r\n\t\t\t\tid: MenuId.EditorTitle,\r\n\t\t\t\torder: 22,\r\n\t\t\t\tgroup: 'navigation',\r\n\t\t\t\twhen: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\r\n\t\t\t},\r\n\t\t});\r\n\t}\r\n\r\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\r\n\t\tconst configurationService = accessor.get(IConfigurationService);\r\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.experimental.collapseUnchangedRegions');\r\n\t\tconfigurationService.updateValue('diffEditor.experimental.collapseUnchangedRegions', newValue);\r\n\t}\r\n}\r\n\r\nregisterAction2(ToggleCollapseUnchangedRegions);\r\n\r\nexport class ToggleShowMovedCodeBlocks extends Action2 {\r\n\tconstructor() {\r\n\t\tsuper({\r\n\t\t\tid: 'diffEditor.toggleShowMovedCodeBlocks',\r\n\t\t\ttitle: { value: localize('toggleShowMovedCodeBlocks', \"Toggle Show Moved Code Blocks\"), original: 'Toggle Show Moved Code Blocks' },\r\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\r\n\t\t});\r\n\t}\r\n\r\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\r\n\t\tconst configurationService = accessor.get(IConfigurationService);\r\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.experimental.showMoves');\r\n\t\tconfigurationService.updateValue('diffEditor.experimental.showMoves', newValue);\r\n\t}\r\n}\r\n\r\nregisterAction2(ToggleShowMovedCodeBlocks);\r\n\r\nexport class ToggleUseInlineViewWhenSpaceIsLimited extends Action2 {\r\n\tconstructor() {\r\n\t\tsuper({\r\n\t\t\tid: 'diffEditor.toggleUseInlineViewWhenSpaceIsLimited',\r\n\t\t\ttitle: { value: localize('toggleUseInlineViewWhenSpaceIsLimited', \"Toggle Use Inline View When Space Is Limited\"), original: 'Toggle Use Inline View When Space Is Limited' },\r\n\t\t\tprecondition: ContextKeyEqualsExpr.create('diffEditorVersion', 2),\r\n\t\t});\r\n\t}\r\n\r\n\trun(accessor: ServicesAccessor, ...args: unknown[]): void {\r\n\t\tconst configurationService = accessor.get(IConfigurationService);\r\n\t\tconst newValue = !configurationService.getValue<boolean>('diffEditor.useInlineViewWhenSpaceIsLimited');\r\n\t\tconfigurationService.updateValue('diffEditor.useInlineViewWhenSpaceIsLimited', newValue);\r\n\t}\r\n}\r\n\r\nregisterAction2(ToggleUseInlineViewWhenSpaceIsLimited);\r\n\r\nMenuRegistry.appendMenuItem(MenuId.EditorTitle, {\r\n\tcommand: {\r\n\t\tid: new ToggleUseInlineViewWhenSpaceIsLimited().desc.id,\r\n\t\ttitle: localize('useInlineViewWhenSpaceIsLimited', \"Use Inline View When Space Is Limited\"),\r\n\t\ttoggled: ContextKeyExpr.has('config.diffEditor.useInlineViewWhenSpaceIsLimited'),\r\n\t},\r\n\torder: 11,\r\n\tgroup: '1_diff',\r\n\twhen: ContextKeyExpr.and(\r\n\t\tEditorContextKeys.diffEditorRenderSideBySideInlineBreakpointReached,\r\n\t\tContextKeyEqualsExpr.create('diffEditorVersion', 2)\r\n\t)\r\n});\r\n\r\nMenuRegistry.appendMenuItem(MenuId.EditorTitle, {\r\n\tcommand: {\r\n\t\tid: new ToggleShowMovedCodeBlocks().desc.id,\r\n\t\ttitle: localize('showMoves', \"Show Moved Code Blocks\"),\r\n\t\ticon: Codicon.move,\r\n\t\ttoggled: ContextKeyEqualsExpr.create('config.diffEditor.experimental.showMoves', true),\r\n\t},\r\n\torder: 10,\r\n\tgroup: '1_diff',\r\n\twhen: ContextKeyEqualsExpr.create('diffEditorVersion', 2)\r\n});\r\n\r\nconst diffEditorCategory: ILocalizedString = {\r\n\tvalue: localize('diffEditor', 'Diff Editor'),\r\n\toriginal: 'Diff Editor',\r\n};\r\n\r\nexport class SwitchSide extends EditorAction2 {\r\n\tconstructor() {\r\n\t\tsuper({\r\n\t\t\tid: 'diffEditor.switchSide',\r\n\t\t\ttitle: { value: localize('switchSide', \"Switch Side\"), original: 'Switch Side' },\r\n\t\t\ticon: Codicon.arrowSwap,\r\n\t\t\tprecondition: ContextKeyExpr.and(ContextKeyEqualsExpr.create('diffEditorVersion', 2), ContextKeyExpr.has('isInDiffEditor')),\r\n\t\t\tf1: true,\r\n\t\t\tcategory: diffEditorCategory,\r\n\t\t});\r\n\t}\r\n\r\n\trunEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, arg?: { dryRun: boolean }): unknown {\r\n\t\tconst diffEditor = findFocusedDiffEditor(accessor);\r\n\t\tif (diffEditor instanceof DiffEditorWidget2) {\r\n\t\t\tif (arg && arg.dryRun) {\r\n\t\t\t\treturn { destinationSelection: diffEditor.mapToOtherSide().destinationSelection };\r\n\t\t\t} else {\r\n\t\t\t\tdiffEditor.switchSide();\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn undefined;\r\n\t}\r\n}\r\n\r\nregisterAction2(SwitchSide);\r\n\r\n<<<<<<< HEAD\r\nexport class CollapseAllUnchangedRegions extends EditorAction2 {\r\n\tconstructor() {\r\n\t\tsuper({\r\n\t\t\tid: 'diffEditor.collapseAllUnchangedRegions',\r\n\t\t\ttitle: { value: localize('collapseAllUnchangedRegions', \"Collapse All Unchanged Regions\"), original: 'Collapse All Unchanged Regions' },\r\n\t\t\ticon: Codicon.fold,\r\n\t\t\tprecondition: ContextKeyExpr.and(ContextKeyEqualsExpr.create('diffEditorVersion', 2), ContextKeyExpr.has('isInDiffEditor')),\r\n\t\t\tf1: true,\r\n\t\t\tcategory: diffEditorCategory,\r\n=======\r\nexport class ExitCompareMove extends EditorAction2 {\r\n\tconstructor() {\r\n\t\tsuper({\r\n\t\t\tid: 'diffEditor.exitCompareMove',\r\n\t\t\ttitle: { value: localize('exitCompareMove', \"Exit Compare Move\"), original: 'Exit Compare Move' },\r\n\t\t\ticon: Codicon.close,\r\n\t\t\tprecondition: EditorContextKeys.comparingMovedCode,\r\n\t\t\tf1: false,\r\n\t\t\tcategory: diffEditorCategory,\r\n\t\t\tkeybinding: {\r\n\t\t\t\tweight: 10000,\r\n\t\t\t\tprimary: KeyCode.Escape,\r\n\t\t\t}\r\n>>>>>>> main\r\n\t\t});\r\n\t}\r\n\r\n\trunEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, ...args: unknown[]): void {\r\n\t\tconst diffEditor = findFocusedDiffEditor(accessor);\r\n\t\tif (diffEditor instanceof DiffEditorWidget2) {\r\n<<<<<<< HEAD\r\n\t\t\tdiffEditor.collapseAllUnchangedRegions();\r\n=======\r\n\t\t\tdiffEditor.exitCompareMove();\r\n>>>>>>> main\r\n\t\t}\r\n\t}\r\n}\r\n\r\n<<<<<<< HEAD\r\nregisterAction2(CollapseAllUnchangedRegions);\r\n\r\nexport class ShowAllUnchangedRegions extends EditorAction2 {\r\n\tconstructor() {\r\n\t\tsuper({\r\n\t\t\tid: 'diffEditor.showAllUnchangedRegions',\r\n\t\t\ttitle: { value: localize('showAllUnchangedRegions', \"Show All Unchanged Regions\"), original: 'Show All Unchanged Regions' },\r\n\t\t\ticon: Codicon.unfold,\r\n\t\t\tprecondition: ContextKeyExpr.and(ContextKeyEqualsExpr.create('diffEditorVersion', 2), ContextKeyExpr.has('isInDiffEditor')),\r\n\t\t\tf1: true,\r\n\t\t\tcategory: diffEditorCategory,\r\n\t\t});\r\n\t}\r\n\r\n\trunEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, ...args: unknown[]): void {\r\n\t\tconst diffEditor = findFocusedDiffEditor(accessor);\r\n\t\tif (diffEditor instanceof DiffEditorWidget2) {\r\n\t\t\tdiffEditor.showAllUnchangedRegions();\r\n\t\t}\r\n\t}\r\n}\r\n\r\nregisterAction2(ShowAllUnchangedRegions);\r\n=======\r\nregisterAction2(ExitCompareMove);\r\n>>>>>>> main\r\n"
}

The right diff is also tough though .

相关问题