Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .rebase/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ https://github.com/che-incubator/che-code/pull/456
- code/src/vs/workbench/browser/workbench.contribution.ts
---

#### @RomanNikitenko
https://github.com/che-incubator/che-code/pull/460

- code/remote/package.json
---

#### @benoitf @RomanNikitenko
https://github.com/che-incubator/che-code/pull/379 \
https://github.com/che-incubator/che-code/commit/d3cf7dc86d284bc4cdff7cc163c5642bb6744524#diff-36f85da944a1b6c01cb656687e520f7415d692e1b7d8856e2161db97a134b224
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2024 Red Hat, Inc.
* Copyright (c) 2024-2025 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,13 +13,24 @@
import * as vscode from 'vscode';
import * as fs from 'fs-extra';
import * as path from 'path';
import { EditorConfigurations } from './editor-configurations';
import { INSTALL_FROM_VSIX } from './install-from-vsix';

const DEFAULT_EXTENSIONS_FILE = path.join(process.env.PROJECTS_ROOT!, '.default-extensions');

export class DefaultExtensions {
constructor(private outputChannel: vscode.OutputChannel, private editorConfigs?: EditorConfigurations) { }

async install(): Promise<void> {
if (!process.env.DEFAULT_EXTENSIONS) {
this.outputChannel.appendLine(`[DefaultExtensions] DEFAULT_EXTENSIONS env variable not found - default extensions installation skipped`);
return;
}

const installFromVsix = this.editorConfigs?.[INSTALL_FROM_VSIX];
if (installFromVsix === false || installFromVsix === 'false') {
this.outputChannel.appendLine('[DefaultExtensions] Can not install default extensions - Install from VSIX command is disabled');
vscode.window.showInformationMessage('Can not install default extensions - Install from VSIX command is disabled');
return;
}

Expand All @@ -32,13 +43,14 @@ export class DefaultExtensions {
extensions = extensions.filter(value => !installed.includes(value));

if (extensions.length) {
console.log(`Installing default extensions: ${extensions.join('; ')}`);
this.outputChannel.appendLine(`[DefaultExtensions] Installing default extensions: ${extensions.join('; ')}`);
const result = await this.installExtensions(extensions);
if (result) {
this.writeDotDefaultExtensionsFile(extensions);
}
}
} catch (error) {
this.outputChannel.appendLine(`[DefaultExtensions] Failed to install default extensions. ${error}`);
console.error(`Failed to install default extensions. ${error}`);
}
}
Expand All @@ -50,6 +62,7 @@ export class DefaultExtensions {
}

} catch (error) {
this.outputChannel.appendLine(`[DefaultExtensions] Failed to read .default-extensions file. ${error}`);
console.error(`Failed to read .default-extensions file. ${error}`);
}

Expand All @@ -74,6 +87,7 @@ export class DefaultExtensions {
await fs.writeFile(DEFAULT_EXTENSIONS_FILE, fileContent);

} catch (error) {
this.outputChannel.appendLine(`[DefaultExtensions] Failed to write to .default-extensions file. ${error}`);
console.error(`Failed to write to .default-extensions file. ${error}`);
}
}
Expand All @@ -95,6 +109,7 @@ export class DefaultExtensions {
installed = true;
} catch (error) {
vscode.window.showInformationMessage(`Failed to install default extensions. ${error.message ? error.message : error}`);
this.outputChannel.appendLine(`[DefaultExtensions] Failed to install default extensions. ${error.message ? error.message : error}`);
}

progress.report({ increment: 100 });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**********************************************************************
* Copyright (c) 2025 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

/* eslint-disable header/header */

import * as fs from 'fs-extra';
import * as vscode from 'vscode';
import { DefaultExtensions } from './default-extensions';
import { InstallFromVSIX } from './install-from-vsix';

const CONFIGS_PATH = '/checode-config/configurations.json';
export interface EditorConfigurations {
[key: string]: any;
}

export class EditorConfigurations {
constructor(private outputChannel: vscode.OutputChannel) { }

async initialize(): Promise<void> {
try {
const configs = await this.getConfigurations();
new DefaultExtensions(this.outputChannel, configs).install();

if (!configs) {
this.outputChannel.appendLine(`[EditorConfigsHandler] Configurations not found`);
return;
}
await new InstallFromVSIX(this.outputChannel).apply(configs);
} catch (error) {
this.outputChannel.appendLine(`[EditorConfigsHandler] Failed to apply editor configurations ${error}`);
}
}

private async getConfigurations(): Promise<EditorConfigurations | undefined> {
if (!await fs.pathExists(CONFIGS_PATH)) {
this.outputChannel.appendLine('[EditorConfigsHandler] File with configurations does not exist');
return;
}

try {
this.outputChannel.appendLine('[EditorConfigsHandler] Reading configurations...');
const configsFileContent = await fs.readFile(CONFIGS_PATH, 'utf8');
return JSON.parse(configsFileContent);
} catch (error) {
this.outputChannel.appendLine(`[EditorConfigsHandler] Error occurred when read configurations ${error}`);
return;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**********************************************************************
* Copyright (c) 2025 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

/* eslint-disable header/header */

import * as vscode from 'vscode';
import { EditorConfigurations } from './editor-configurations';

export const INSTALL_FROM_VSIX = 'extensions.install-from-vsix-enabled';

export class InstallFromVSIX {
constructor(private outputChannel: vscode.OutputChannel) { }

async apply(configs: EditorConfigurations): Promise<void> {
this.outputChannel.appendLine('[InstallFromVSIX] Looking for configurations...');

try {
const installFromVsix = configs[INSTALL_FROM_VSIX];
if (installFromVsix === undefined) {
this.outputChannel.appendLine('[InstallFromVSIX] Configuration for the Install From VSIX command not found');
return;
}

if (installFromVsix === false || installFromVsix === 'false') {
this.outputChannel.appendLine(`[InstallFromVSIX] Applying ${installFromVsix} value for the ${INSTALL_FROM_VSIX} configuration.`);
// disable command
vscode.commands.executeCommand('setContext', INSTALL_FROM_VSIX, false);
}
} catch (error) {
this.outputChannel.appendLine(`[InstallFromVSIX] Failed to configure Install From VSIX command: ${error}`);
}
}
}
6 changes: 3 additions & 3 deletions code/extensions/che-commands/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2022 Red Hat, Inc.
* Copyright (c) 2022-2025 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -12,7 +12,7 @@

import * as vscode from 'vscode';
import { DevfileTaskProvider } from './taskProvider';
import { DefaultExtensions } from './default-extensions';
import { EditorConfigurations } from './editorConfigs/editor-configurations';

export async function activate(context: vscode.ExtensionContext): Promise<void> {
const channel: vscode.OutputChannel = vscode.window.createOutputChannel('Devfile Commands');
Expand All @@ -25,7 +25,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>

context.subscriptions.push(disposable);

await new DefaultExtensions().install();
await new EditorConfigurations(channel).initialize();
}

async function getExtensionAPI(extID: string): Promise<any> {
Expand Down
Loading