mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 01:07:46 +00:00
Sync upstream Gemini-CLI v0.8.2 (#838)
This commit is contained in:
@@ -6,22 +6,107 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { IDEServer } from './ide-server.js';
|
||||
import semver from 'semver';
|
||||
import { DiffContentProvider, DiffManager } from './diff-manager.js';
|
||||
import { createLogger } from './utils/logger.js';
|
||||
import {
|
||||
detectIdeFromEnv,
|
||||
IDE_DEFINITIONS,
|
||||
type IdeInfo,
|
||||
} from '@qwen-code/qwen-code-core/src/ide/detect-ide.js';
|
||||
|
||||
const CLI_IDE_COMPANION_IDENTIFIER = 'qwenlm.qwen-code-vscode-ide-companion';
|
||||
const INFO_MESSAGE_SHOWN_KEY = 'qwenCodeInfoMessageShown';
|
||||
export const DIFF_SCHEME = 'qwen-diff';
|
||||
|
||||
/**
|
||||
* IDE environments where the installation greeting is hidden. In these
|
||||
* environments we either are pre-installed and the installation message is
|
||||
* confusing or we just want to be quiet.
|
||||
*/
|
||||
const HIDE_INSTALLATION_GREETING_IDES: ReadonlySet<IdeInfo['name']> = new Set([
|
||||
IDE_DEFINITIONS.firebasestudio.name,
|
||||
IDE_DEFINITIONS.cloudshell.name,
|
||||
]);
|
||||
|
||||
let ideServer: IDEServer;
|
||||
let logger: vscode.OutputChannel;
|
||||
|
||||
let log: (message: string) => void = () => {};
|
||||
|
||||
async function checkForUpdates(
|
||||
context: vscode.ExtensionContext,
|
||||
log: (message: string) => void,
|
||||
) {
|
||||
try {
|
||||
const currentVersion = context.extension.packageJSON.version;
|
||||
|
||||
// Fetch extension details from the VSCode Marketplace.
|
||||
const response = await fetch(
|
||||
'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery',
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json;api-version=7.1-preview.1',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
filters: [
|
||||
{
|
||||
criteria: [
|
||||
{
|
||||
filterType: 7, // Corresponds to ExtensionName
|
||||
value: CLI_IDE_COMPANION_IDENTIFIER,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
// See: https://learn.microsoft.com/en-us/azure/devops/extend/gallery/apis/hyper-linking?view=azure-devops
|
||||
// 946 = IncludeVersions | IncludeFiles | IncludeCategoryAndTags |
|
||||
// IncludeShortDescription | IncludePublisher | IncludeStatistics
|
||||
flags: 946,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
log(
|
||||
`Failed to fetch latest version info from marketplace: ${response.statusText}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const extension = data?.results?.[0]?.extensions?.[0];
|
||||
// The versions are sorted by date, so the first one is the latest.
|
||||
const latestVersion = extension?.versions?.[0]?.version;
|
||||
|
||||
if (latestVersion && semver.gt(latestVersion, currentVersion)) {
|
||||
const selection = await vscode.window.showInformationMessage(
|
||||
`A new version (${latestVersion}) of the Qwen Code Companion extension is available.`,
|
||||
'Update to latest version',
|
||||
);
|
||||
if (selection === 'Update to latest version') {
|
||||
// The install command will update the extension if a newer version is found.
|
||||
await vscode.commands.executeCommand(
|
||||
'workbench.extensions.installExtension',
|
||||
CLI_IDE_COMPANION_IDENTIFIER,
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
log(`Error checking for extension updates: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext) {
|
||||
logger = vscode.window.createOutputChannel('Qwen Code Companion');
|
||||
log = createLogger(context, logger);
|
||||
log('Extension activated');
|
||||
|
||||
checkForUpdates(context, log);
|
||||
|
||||
const diffContentProvider = new DiffContentProvider();
|
||||
const diffManager = new DiffManager(log, diffContentProvider);
|
||||
|
||||
@@ -57,7 +142,11 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
log(`Failed to start IDE server: ${message}`);
|
||||
}
|
||||
|
||||
if (!context.globalState.get(INFO_MESSAGE_SHOWN_KEY)) {
|
||||
const infoMessageEnabled = !HIDE_INSTALLATION_GREETING_IDES.has(
|
||||
detectIdeFromEnv().name,
|
||||
);
|
||||
|
||||
if (!context.globalState.get(INFO_MESSAGE_SHOWN_KEY) && infoMessageEnabled) {
|
||||
void vscode.window.showInformationMessage(
|
||||
'Qwen Code Companion extension successfully installed.',
|
||||
);
|
||||
@@ -66,7 +155,10 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
context.subscriptions.push(
|
||||
vscode.workspace.onDidChangeWorkspaceFolders(() => {
|
||||
ideServer.updateWorkspacePath();
|
||||
ideServer.syncEnvVars();
|
||||
}),
|
||||
vscode.workspace.onDidGrantWorkspaceTrust(() => {
|
||||
ideServer.syncEnvVars();
|
||||
}),
|
||||
vscode.commands.registerCommand('qwen-code.runQwenCode', async () => {
|
||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||
|
||||
Reference in New Issue
Block a user