Skip to content

Commit

Permalink
open func.yaml file when clicking on tree view (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudhirverma authored May 4, 2022
1 parent a04c63d commit 3ea7894
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
"onCommand:service.explorer.create",
"onCommand:service.explorer.edit",
"onCommand:service.explorer.openFile",
"onCommand:function.openInEditor",
"onCommand:service.explorer.refresh",
"onCommand:service.explorer.reportIssue",
"onCommand:service.explorer.apply",
Expand Down Expand Up @@ -241,6 +242,11 @@
"title": "Describe",
"category": "Knative"
},
{
"command": "function.openInEditor",
"title": "Open In Editor",
"category": "Knative"
},
{
"command": "service.explorer.tag",
"title": "Add a Tag",
Expand Down Expand Up @@ -436,6 +442,10 @@
"command": "service.explorer.openFile",
"when": "false"
},
{
"command": "function.openInEditor",
"when": "false"
},
{
"command": "service.explorer.deleteLocal",
"when": "false"
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { createFunction } from './functions/function-command/create-function';
import { urlFunction } from './functions/function-command/get-url-function';
// eslint-disable-next-line import/no-cycle
import { createInvokeFunction } from './functions/function-command/invoke-function';
import { openInEditor } from './functions/function-command/open-yaml-file-in-editor';
import { runFunction } from './functions/function-command/run-function';
import { undeployFunction } from './functions/function-command/undeploy-function';
import { functionExplorer } from './functions/functionsExplorer';
Expand Down Expand Up @@ -67,6 +68,7 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi
vscode.commands.registerCommand('function.explorer.create', () => createFunction(extensionContext)),
vscode.commands.registerCommand('function.invoke', (context) => createInvokeFunction(extensionContext, context)),
vscode.commands.registerCommand('function.undeploy', (context) => undeployFunction(context)),
vscode.commands.registerCommand('function.openInEditor', (context) => openInEditor(context)),
vscode.commands.registerCommand('function.build', (context) => buildFunction(context)),
vscode.commands.registerCommand('function.deploy', (context) => deployFunction(context)),
vscode.commands.registerCommand('function.OpenInBrowserAction', (context) => urlFunction(context)),
Expand Down
26 changes: 26 additions & 0 deletions src/functions/function-command/open-yaml-file-in-editor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable import/no-cycle */
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/

import * as path from 'path';
import { Uri, window, workspace } from 'vscode';
import { FunctionNode } from '../function-tree-view/functionsTreeItem';

export function openInEditor(context: FunctionNode): void {
if (!context) {
return null;
}
const uriPath = Uri.file(path.join(context.contextPath.fsPath, 'func.yaml'));
workspace.openTextDocument(uriPath).then(
(doc) => {
if (doc) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
window.showTextDocument(doc, { preserveFocus: true, preview: true });
}
},
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
(err) => window.showErrorMessage(`Error loading document: ${err}`),
);
}
15 changes: 14 additions & 1 deletion src/functions/function-tree-view/functionsTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*-----------------------------------------------------------------------------------------------*/

import * as path from 'path';
import { ProviderResult, QuickPickItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { ProviderResult, QuickPickItem, TreeItemCollapsibleState, Uri, Command as vsCommand } from 'vscode';
import format = require('string-format');
import { FunctionContextType, FunctionStatus } from '../../cli/config';
// eslint-disable-next-line import/no-cycle
Expand Down Expand Up @@ -136,6 +136,19 @@ export class FunctionNodeImpl implements FunctionNode {
return format(this.CONTEXT_DATA[this.contextValue].tooltip, this);
}

get command(): vsCommand | undefined {
const arrName = [
'localDeployFunctions',
'localFunctions',
'localFunctionsEnablement',
'notConnectedLocalFunctions',
'notConnectedLocalFunctionsEnablement',
];
if (arrName.includes(this.contextValue)) {
return { command: 'function.openInEditor', title: 'Open In Editor', arguments: [this] };
}
}

get label(): string {
return this.name;
}
Expand Down

0 comments on commit 3ea7894

Please # to comment.