* Add a field to the HostProvider `extensionFsPath` Replace vscode.ExtensionContext `extensionUri` with `HostProvider.extensionFsPath`. This part of removing uses of the VSCode API fom the codebase except for in platform specific code (these are src/hosts/vscode and src/extension.ts). * Remove extra leading slash from webview URL on JetBrains * Remove vscode.Uri from the WebviewProvider Replace `vscode.Uri` with URL strings. Replace Uri with Url in variable names.
74 lines
2.8 KiB
TypeScript
74 lines
2.8 KiB
TypeScript
import { mkdirSync, readFileSync } from "fs"
|
|
import os from "os"
|
|
import path, { join } from "path"
|
|
import type { Extension, ExtensionContext } from "vscode"
|
|
import { ExtensionKind, ExtensionMode } from "vscode"
|
|
import { URI } from "vscode-uri"
|
|
import { log } from "./utils"
|
|
import { EnvironmentVariableCollection, MementoStore, readJson, SecretStore } from "./vscode-context-utils"
|
|
|
|
export const { version, name, publisher } = getPackageInfo()
|
|
log("Running standalone cline", version)
|
|
|
|
export const CLINE_DIR = process.env.CLINE_DIR || `${os.homedir()}/.cline`
|
|
const DATA_DIR = path.join(CLINE_DIR, "data")
|
|
const INSTALL_DIR = process.env.INSTALL_DIR || __dirname
|
|
const WORKSPACE_STORAGE_DIR = process.env.WORKSPACE_STORAGE_DIR || path.join(DATA_DIR, "workspace")
|
|
|
|
mkdirSync(DATA_DIR, { recursive: true })
|
|
mkdirSync(WORKSPACE_STORAGE_DIR, { recursive: true })
|
|
log("Using settings dir:", DATA_DIR)
|
|
|
|
export const EXTENSION_DIR = path.join(INSTALL_DIR, "extension")
|
|
const EXTENSION_MODE = process.env.IS_DEV === "true" ? ExtensionMode.Development : ExtensionMode.Production
|
|
|
|
const extension: Extension<void> = {
|
|
id: `${publisher}.${name}`,
|
|
isActive: true,
|
|
extensionPath: EXTENSION_DIR,
|
|
extensionUri: URI.file(EXTENSION_DIR),
|
|
packageJSON: readJson(path.join(EXTENSION_DIR, "package.json")),
|
|
exports: undefined, // There are no API exports in the standalone version.
|
|
activate: async () => {},
|
|
extensionKind: ExtensionKind.UI,
|
|
}
|
|
|
|
const extensionContext: ExtensionContext = {
|
|
extension: extension,
|
|
extensionMode: EXTENSION_MODE,
|
|
|
|
// Set up KV stores.
|
|
globalState: new MementoStore(path.join(DATA_DIR, "globalState.json")),
|
|
secrets: new SecretStore(path.join(DATA_DIR, "secrets.json")),
|
|
|
|
// Set up URIs.
|
|
storageUri: URI.file(WORKSPACE_STORAGE_DIR),
|
|
storagePath: WORKSPACE_STORAGE_DIR, // Deprecated, not used in cline.
|
|
globalStorageUri: URI.file(DATA_DIR),
|
|
globalStoragePath: DATA_DIR, // Deprecated, not used in cline.
|
|
|
|
// Logs are global per extension, not per workspace.
|
|
logUri: URI.file(DATA_DIR),
|
|
logPath: DATA_DIR, // Deprecated, not used in cline.
|
|
|
|
extensionUri: URI.file(EXTENSION_DIR),
|
|
extensionPath: EXTENSION_DIR, // Deprecated, not used in cline.
|
|
asAbsolutePath: (relPath: string) => path.join(EXTENSION_DIR, relPath),
|
|
|
|
subscriptions: [], // These need to be destroyed when the extension is deactivated.
|
|
|
|
environmentVariableCollection: new EnvironmentVariableCollection(),
|
|
|
|
// Workspace state is per project/workspace when WORKSPACE_STORAGE_DIR is provided by the host.
|
|
workspaceState: new MementoStore(path.join(WORKSPACE_STORAGE_DIR, "workspaceState.json")),
|
|
}
|
|
|
|
function getPackageInfo() {
|
|
const packageJson = JSON.parse(readFileSync(join(__dirname, "package.json"), "utf8"))
|
|
return { version: packageJson.version, name: packageJson.name, publisher: packageJson.publisher }
|
|
}
|
|
|
|
console.log("Finished loading vscode context...")
|
|
|
|
export { extensionContext }
|