diff --git a/src/extension.ts b/src/extension.ts index 21d967990..324d3adba 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,7 +3,6 @@ * Licensed under the MIT License. See LICENSE file in the project root for license information. *-----------------------------------------------------------------------------------------------*/ -import * as path from 'path'; import { authentication, commands, env, ExtensionContext, languages, QuickPickItemKind, @@ -27,14 +26,12 @@ import { ToolsConfig } from './tools'; import { TokenStore } from './util/credentialManager'; import { getNamespaceKind, KubeConfigUtils, setKubeConfig } from './util/kubeUtils'; import { Context as KcuContext } from '@kubernetes/client-node/dist/config_types'; -import { Platform } from './util/platform'; import { setupWorkspaceDevfileContext } from './util/workspace'; import { registerCommands } from './vscommand'; import { OpenShiftTerminalManager } from './webview/openshift-terminal/openShiftTerminal'; import { WelcomePage } from './welcomePage'; import { registerYamlHandlers } from './yaml/yamlDocumentFeatures'; -import fsx = require('fs-extra'); import { Oc } from './oc/ocWrapper'; import { K8S_RESOURCE_SCHEME, K8S_RESOURCE_SCHEME_READONLY, KubernetesResourceVirtualFileSystemProvider } from './k8s/vfs/kuberesources.virtualfs'; import { KubernetesResourceLinkProvider } from './k8s/vfs/kuberesources.linkprovider'; @@ -45,16 +42,6 @@ export function deactivate(): void { // intentionally left blank } -function migrateFromOdo018(): void { - const newCfgDir = path.join(Platform.getUserHomePath(), '.odo'); - const newCfg = path.join(newCfgDir, 'odo-config.yaml'); - const oldCfg = path.join(Platform.getUserHomePath(), '.kube', 'odo'); - if (!fsx.existsSync(newCfg) && fsx.existsSync(oldCfg)) { - fsx.ensureDirSync(newCfgDir); - fsx.copyFileSync(oldCfg, newCfg); - } -} - async function verifyBundledBinaries(): Promise<{ odoPath: string, ocPath: string, helmPath: string }> { return { odoPath: await ToolsConfig.detect('odo'), @@ -72,9 +59,9 @@ async function registerKubernetesCloudProvider(): Promise { export async function activate(extensionContext: ExtensionContext): Promise { void WelcomePage.createOrShow(); - await commands.executeCommand('setContext', 'isVSCode', env.uiKind); + void commands.executeCommand('setContext', 'isVSCode', env.uiKind); // UIKind.Desktop ==1 & UIKind.Web ==2. These conditions are checked for browser based & electron based IDE. - migrateFromOdo018(); + Cluster.extensionContext = extensionContext; TokenStore.extensionContext = extensionContext; @@ -96,49 +83,51 @@ export async function activate(extensionContext: ExtensionContext): Promise extensionContext.subscriptions.push(value)); + const pushSubscriptions = async function(): Promise { + const disposable = [ + ...(await registerCommands( + './k8s/route', + './openshift/project', + './openshift/cluster', + './openshift/service', + './openshift/route', + './k8s/console', + './yamlFileCommands', + './registriesView', + './componentsView', + './webview/devfile-registry/registryViewLoader', + './webview/helm-chart/helmChartLoader', + './webview/helm-manage-repository/manageRepositoryLoader', + './feedback', + './deployment' + )), + crcStatusItem, + activeNamespaceStatusBarItem, + activeContextStatusBarItem, + OpenShiftExplorer.getInstance(), + new DebugSessionsView().createTreeView('openshiftDebugView'), + ...Component.init(), + ComponentTypesView.instance.createTreeView('openshiftComponentTypesView'), + ServerlessFunctionView.getInstance(), + ComponentsTreeDataProvider.instance.createTreeView('openshiftComponentsView'), + setupWorkspaceDevfileContext(), + window.registerWebviewViewProvider('openShiftTerminalView', OpenShiftTerminalManager.getInstance(), { webviewOptions: { retainContextWhenHidden: true, } }), + ...registerYamlHandlers(), + // Temporarily loaded resource providers + workspace.registerFileSystemProvider(K8S_RESOURCE_SCHEME, resourceDocProvider, { /* TODO: case sensitive? */ }), + workspace.registerFileSystemProvider(K8S_RESOURCE_SCHEME_READONLY, resourceDocProvider, { isReadonly: true }), + + // Link from resources to referenced resources + languages.registerDocumentLinkProvider({ scheme: K8S_RESOURCE_SCHEME }, resourceLinkProvider), + ]; + disposable.forEach((value) => extensionContext.subscriptions.push(value)); + } + void pushSubscriptions(); // activate "Sign in with Red Hat ..." void authentication.getSession('redhat-account-auth', ['openid'], { silent: false }); - function statusBarFunctions() { + const statusBarFunctions = function() { return commands.registerCommand('openshift.openStatusBar', async () => { const selection = await window.showQuickPick( [ @@ -201,11 +190,10 @@ export async function activate(extensionContext: ExtensionContext): Promise { - const kind = await getNamespaceKind(); - void Oc.Instance.getActiveProject().then((namespace) => - updateContextStatusBarItem(activeNamespaceStatusBarItem, 'project-node', namespace, `Current ${kind}: ${namespace}`, - !isNamespaceInfoStatusBarDisabled())); + const updateContextAndProjectStatusBarItems = async function(context?: string): Promise { + return getNamespaceKind().then(async (kind) => { + const namespace = await Oc.Instance.getActiveProject(); + if (namespace) { + updateContextStatusBarItem(activeNamespaceStatusBarItem, 'project-node', namespace, `Current ${kind}: ${namespace}`, + !isNamespaceInfoStatusBarDisabled()); + } else { + updateContextStatusBarItem(activeNamespaceStatusBarItem, 'project-node', '', '', false); + } + + const kcu: KubeConfigUtils = new KubeConfigUtils(); + const currentContext: KcuContext = kcu.findContext(context ? context : kcu.currentContext); + updateContextStatusBarItem(activeContextStatusBarItem, 'current-context', currentContext?.name, `${currentContext?.name}\nCluster: ${currentContext?.cluster}`, + !isContextInfoStatusBarDisabled()); + }); + } - const kcu: KubeConfigUtils = new KubeConfigUtils(); - const currentContext: KcuContext = kcu.findContext(context); - updateContextStatusBarItem(activeContextStatusBarItem, 'current-context', currentContext?.name, `${currentContext?.name}\nCluster: ${currentContext?.cluster}`, - !isContextInfoStatusBarDisabled()); + OpenShiftExplorer.getInstance().onDidChangeContextEmitter.event((context) => { + void updateContextAndProjectStatusBarItems(context); }); - const kcu: KubeConfigUtils = new KubeConfigUtils(); - const kind = await getNamespaceKind(); - const currentContext: KcuContext = kcu.findContext(kcu.currentContext); - updateContextStatusBarItem(activeNamespaceStatusBarItem, 'project-node', null, `Current ${kind}`, - !isNamespaceInfoStatusBarDisabled()); - updateContextStatusBarItem(activeContextStatusBarItem, 'current-context', currentContext?.name, `${currentContext?.name}\nCluster: ${currentContext?.cluster}`, - !isContextInfoStatusBarDisabled()); + void updateContextAndProjectStatusBarItems(); updateStatusBarItem(crcStatusItem, 'Stop CRC'); + void extendClusterExplorer(); await registerKubernetesCloudProvider(); @@ -286,6 +276,6 @@ export async function activate(extensionContext: ExtensionContext): Promise