Skip to content

Commit

Permalink
feat: add view meta XML command to switch quickly to the related meta…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
Codeneos committed Oct 27, 2023
1 parent 6b12f0b commit 6c2e688
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/vscode-extension/build/buildCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export function mergeCommandContributions(packageJson: PackageJson, commands: Co
if (command.icon) {
if (typeof command.icon === 'object') {
newCommand.icon = command.icon;
} else if (command.icon.startsWith('$(')) {
newCommand.icon = command.icon;
} else {
newCommand.icon = {
light: command.icon.replace(/{(type|theme)}/ig, 'light'),
Expand Down
18 changes: 18 additions & 0 deletions packages/vscode-extension/commands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,21 @@ vlocode.omniScript.activate:
title: 'OmniScript: (Re-)Activate'
group: v_vlocity_omniscript
menus: *omniScriptCommandMenus

# editor
vlocode.openMetaXml:
title: Open -meta.xml
icon: resources/{type}/meta-xml.svg
when:
- resourceScheme == file && resourcePath =~ /\.cls$/
- resourceScheme == file && resourcePath =~ /\.trigger$/
menus:
- menu: editor/title/run
vlocode.openSourceFile:
title: Open Source
icon: $(code)
when:
- resourceScheme == file && resourcePath =~ /\.cls-meta\.xml$/
- resourceScheme == file && resourcePath =~ /\.trigger-meta\.xml$/
menus:
- menu: editor/title/run
67 changes: 66 additions & 1 deletion packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@
"onCommand:vlocode.deployDeltaMetadata",
"onCommand:vlocode.omniScript.generateLwc",
"onCommand:vlocode.omniScript.deployLwc",
"onCommand:vlocode.omniScript.activate"
"onCommand:vlocode.omniScript.activate",
"onCommand:vlocode.openMetaXml",
"onCommand:vlocode.openSourceFile"
],
"main": "./out/vlocode",
"contributes": {
Expand Down Expand Up @@ -403,6 +405,19 @@
{
"command": "vlocode.omniScript.activate",
"title": "OmniScript: (Re-)Activate"
},
{
"command": "vlocode.openMetaXml",
"title": "Open -meta.xml",
"icon": {
"light": "resources/light/meta-xml.svg",
"dark": "resources/dark/meta-xml.svg"
}
},
{
"command": "vlocode.openSourceFile",
"title": "Open Source",
"icon": "$(code)"
}
],
"menus": {
Expand Down Expand Up @@ -670,6 +685,38 @@
"command": "vlocode.omniScript.activate",
"group": "v_vlocity_omniscript",
"when": "resourceScheme == file && resourcePath =~ /.+\\\\OmniScript\\\\.+\\\\.+\\.json$/"
},
{
"command": "vlocode.openMetaXml",
"when": "false"
},
{
"command": "vlocode.openMetaXml",
"when": "resourceScheme == file && resourcePath =~ /\\.cls$/ && false"
},
{
"command": "vlocode.openMetaXml",
"when": "false"
},
{
"command": "vlocode.openMetaXml",
"when": "resourceScheme == file && resourcePath =~ /\\.trigger$/ && false"
},
{
"command": "vlocode.openSourceFile",
"when": "false"
},
{
"command": "vlocode.openSourceFile",
"when": "resourceScheme == file && resourcePath =~ /\\.cls-meta\\.xml$/ && false"
},
{
"command": "vlocode.openSourceFile",
"when": "false"
},
{
"command": "vlocode.openSourceFile",
"when": "resourceScheme == file && resourcePath =~ /\\.trigger-meta\\.xml$/ && false"
}
],
"explorer/context": [
Expand Down Expand Up @@ -994,6 +1041,24 @@
"group": "navigation",
"when": "view == developerLogsView"
}
],
"editor/title/run": [
{
"command": "vlocode.openMetaXml",
"when": "resourceScheme == file && resourcePath =~ /\\.cls$/"
},
{
"command": "vlocode.openMetaXml",
"when": "resourceScheme == file && resourcePath =~ /\\.trigger$/"
},
{
"command": "vlocode.openSourceFile",
"when": "resourceScheme == file && resourcePath =~ /\\.cls-meta\\.xml$/"
},
{
"command": "vlocode.openSourceFile",
"when": "resourceScheme == file && resourcePath =~ /\\.trigger-meta\\.xml$/"
}
]
},
"configuration": [
Expand Down
9 changes: 9 additions & 0 deletions packages/vscode-extension/resources/dark/meta-xml.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions packages/vscode-extension/resources/light/meta-xml.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion packages/vscode-extension/src/commands/metadata/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export * from './pauseDeploymentsCommand';
export * from './refreshMetadataCommand';
export * from './resumeDeploymentsCommand';
export * from './retrieveMetadataCommand';
export * from './viewInSalesforce';
export * from './toggleMetaXmlCommand';
export * from './viewInSalesforce';
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { VlocodeCommand } from '../../constants';
import * as vscode from 'vscode';
import MetadataCommand from './metadataCommand';
import { vscodeCommand } from '../../lib/commandRouter';

@vscodeCommand(VlocodeCommand.openMetaXml)
@vscodeCommand(VlocodeCommand.openSourceFile)
export default class ToggleMetaXmlCommand extends MetadataCommand {
public execute() {
if (!this.currentOpenDocument) {
return;
}

if (this.currentOpenDocument.path.endsWith('-meta.xml')) {
this.openSourceFile(this.currentOpenDocument);
} else {
this.openMetaXml(this.currentOpenDocument);
}
}

private openMetaXml(documentUri: vscode.Uri) {
const metaFile = documentUri.with({
path: documentUri.path + '-meta.xml'
});
vscode.window.showTextDocument(metaFile);
}

private openSourceFile(documentUri: vscode.Uri) {
const sourceFile = documentUri.with({
path: documentUri.path.slice(0, -'-meta.xml'.length)
});
vscode.window.showTextDocument(sourceFile);
}
}
2 changes: 2 additions & 0 deletions packages/vscode-extension/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export enum VlocodeCommand {
resumeDeploymentQueue = 'vlocode.resumeDeploymentQueue',
addToProfile = 'vlocode.addToProfile',
removeFromProfile = 'vlocode.removeFromProfile',
openMetaXml = 'vlocode.openMetaXml',
openSourceFile = 'vlocode.openSourceFile',
omniScriptGenerateLwc = 'vlocode.omniScript.generateLwc',
omniScriptDeployLwc = 'vlocode.omniScript.deployLwc',
omniScriptActivate = 'vlocode.omniScript.activate',
Expand Down

0 comments on commit 6c2e688

Please sign in to comment.