continue-custom/core/util/paths.ts
Nate Sesti 3bd9c8996c
💫 Preview (#996)
* feat: add fixed version of the nodejs

* revert accidentally committed files

* add: unified version of the Node.js that is used locally and on Github Actions

* Set itemType for querySubmenuItem

This is necessary before calling props.command the same way we do it for non-query item types. Otherwise we receive an 'Unknow provider...' error message in the 'getContextItems' case in the 'panel.webview.onDidReceiveMessage, callback.

* include @vscode node module folder

we need the @vscode folder containing ripgrep in the distribution.

* Amended path for ripgrep executable

We have to preprend the 'out' folder in order to find the ripgrep executable in the distribution.
Prepending 'out' during development is not necessary. We need a way to distinguish in 'ideProtocol'?

* implemented locals context provider

* normal to submenu(select thread) for the locals provider

* added code context from the call stack

* use parameter for callstack retrieving

* added thread filtering and handle a edge case

* revert accidentally committed file

* temporary fix to use refreshSubmenuItems

* added updateSubmenuItems request

* refactor: changed the interface of threads

* polished format and file reading

* added a little doc

* typo

* revert accidentally committed file

* ✨ UI for JetBrains autocomplete

* 🎨 decouple autocomplete from VS Code extension

* ✨ autocomplete in core protocol

* 🚧 jetbrains autocomplete fixes

* 🐛 successfully get responses for jetbrains autocomplete

* Refactored web crawling code for document indexing. The updated code uses a breadth-first search, filters out specific paths, and ensures that websites are not downloaded twice.

* update hasDocs to use new pattern

* feat: add gitlab context class

* feat: update to work as normal context provider

* fix: add context provider

* feat: add code that comment is based on

* docs: add documentation

* feat: enable comment filtering

* 🐛 fix autocomplete with azure

* ✨ jetbrains multiline completions

* 🐛 fix file reading in autocomplete

* ✨ option to disable jetbrains autocomplete

* 📌 update package-lock files

* 🐛 fix localhost ollama bug with jetbrains binary

* 🔥 disable apply to file in jetbrains for now

* 🚸 fix constant re-rendering of code vision in jetbrains

* 🔖 update package.json versiojn

* 🐛 don't override user temperature value for tab autocomplete model

* Fix chat msg formatting in Output for image models (#971)

* 📝 tweak docs for "locals" ctx provider

* 🩹 small tweak to link filtering logic

* Add more C++ extensions for AST parser (#972)

* 🔥 remove ruby example file

* add claude3 to free trial

* 🐛 fix codelens in tutorial

* 🧱 change server url

* 🐛 don't send image_url if not image type

* 🔧 update config schemas

* 📌 update npm version to v20.11.0

* 📈 Locally track tokens generated and show stats (#987)

* ✨ log tokens generated locally

* 💄 UI for usage stats

* 🔥 delete unused test file

* 🚚 rename core package for publishing on npm

* Remove duplicate itemType property (#986)

* 🔒️ add .env to .gitignore for npm package

* Add SystemContextProvider to context providers so that users can use … (#988)

* Add SystemContextProvider to context providers so that users can use their own system cpu and os for a resource

* change to OSContextProvider

* update descriptor

* 🎨 export transformers.js

* 🐛 fix /edit for anthropic

* 🚑 fix autocomplete by binding function

---------

Co-authored-by: my8bit <mail@my8bit.name>
Co-authored-by: Ihor Pavlenko <my8bit@users.noreply.github.com>
Co-authored-by: Lars Pagh <lp@airsupport.dk>
Co-authored-by: commandblock2 <tony_hu@live.com>
Co-authored-by: Jason Jacobs <nerfnerd@gmail.com>
Co-authored-by: Ben Force <benforce@gmail.com>
Co-authored-by: Peter Zaback <pzaback@gmail.com>
Co-authored-by: SR_team <sr_team@sr.team>
2024-03-19 10:35:28 -07:00

230 lines
6.4 KiB
TypeScript

import dotenv from "dotenv";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { IdeType, SerializedContinueConfig } from "..";
import { defaultConfig, defaultConfigJetBrains } from "../config/default";
import Types from "../config/types";
export function getContinueGlobalPath(): string {
// This is ~/.continue on mac/linux
const continuePath = path.join(os.homedir(), ".continue");
if (!fs.existsSync(continuePath)) {
fs.mkdirSync(continuePath);
}
return continuePath;
}
export function getSessionsFolderPath(): string {
const sessionsPath = path.join(getContinueGlobalPath(), "sessions");
if (!fs.existsSync(sessionsPath)) {
fs.mkdirSync(sessionsPath);
}
return sessionsPath;
}
export function getIndexFolderPath(): string {
const indexPath = path.join(getContinueGlobalPath(), "index");
if (!fs.existsSync(indexPath)) {
fs.mkdirSync(indexPath);
}
return indexPath;
}
export function getSessionFilePath(sessionId: string): string {
return path.join(getSessionsFolderPath(), `${sessionId}.json`);
}
export function getSessionsListPath(): string {
const filepath = path.join(getSessionsFolderPath(), "sessions.json");
if (!fs.existsSync(filepath)) {
fs.writeFileSync(filepath, JSON.stringify([]));
}
return filepath;
}
export function getConfigJsonPath(ideType: IdeType = "vscode"): string {
const p = path.join(getContinueGlobalPath(), "config.json");
if (!fs.existsSync(p)) {
if (ideType === "jetbrains") {
fs.writeFileSync(p, JSON.stringify(defaultConfigJetBrains, null, 2));
} else {
fs.writeFileSync(p, JSON.stringify(defaultConfig, null, 2));
}
}
return p;
}
export function getConfigTsPath(): string {
const p = path.join(getContinueGlobalPath(), "config.ts");
if (!fs.existsSync(p)) {
fs.writeFileSync(
p,
`export function modifyConfig(config: Config): Config {
return config;
}`,
);
}
const typesPath = path.join(getContinueGlobalPath(), "types");
if (!fs.existsSync(typesPath)) {
fs.mkdirSync(typesPath);
}
const corePath = path.join(typesPath, "core");
if (!fs.existsSync(corePath)) {
fs.mkdirSync(corePath);
}
const packageJsonPath = path.join(getContinueGlobalPath(), "package.json");
if (!fs.existsSync(packageJsonPath)) {
fs.writeFileSync(
packageJsonPath,
JSON.stringify({
name: "continue-config",
version: "1.0.0",
description: "My Continue Configuration",
main: "config.js",
}),
);
}
fs.writeFileSync(path.join(corePath, "index.d.ts"), Types);
return p;
}
export function getConfigJsPath(): string {
// Do not create automatically
return path.join(getContinueGlobalPath(), "out", "config.js");
}
export function getTsConfigPath(): string {
const tsConfigPath = path.join(getContinueGlobalPath(), "tsconfig.json");
if (!fs.existsSync(tsConfigPath)) {
fs.writeFileSync(
tsConfigPath,
JSON.stringify(
{
compilerOptions: {
target: "ESNext",
useDefineForClassFields: true,
lib: ["DOM", "DOM.Iterable", "ESNext"],
allowJs: true,
skipLibCheck: true,
esModuleInterop: false,
allowSyntheticDefaultImports: true,
strict: true,
forceConsistentCasingInFileNames: true,
module: "System",
moduleResolution: "Node",
noEmit: false,
noEmitOnError: false,
outFile: "./out/config.js",
typeRoots: ["./node_modules/@types", "./types"],
},
include: ["./config.ts"],
},
null,
2,
),
);
}
return tsConfigPath;
}
export function devDataPath(): string {
const sPath = path.join(getContinueGlobalPath(), "dev_data");
if (!fs.existsSync(sPath)) {
fs.mkdirSync(sPath);
}
return sPath;
}
export function getDevDataSqlitePath(): string {
return path.join(devDataPath(), "devdata.sqlite");
}
export function getDevDataFilePath(fileName: string): string {
return path.join(devDataPath(), fileName + ".jsonl");
}
export function editConfigJson(
callback: (config: SerializedContinueConfig) => SerializedContinueConfig,
) {
const config = fs.readFileSync(getConfigJsonPath(), "utf8");
let configJson = JSON.parse(config);
configJson = callback(configJson);
fs.writeFileSync(getConfigJsonPath(), JSON.stringify(configJson, null, 2));
return configJson;
}
function getMigrationsFolderPath(): string {
const migrationsPath = path.join(getContinueGlobalPath(), ".migrations");
if (!fs.existsSync(migrationsPath)) {
fs.mkdirSync(migrationsPath);
}
return migrationsPath;
}
export function migrate(id: string, callback: () => void) {
const migrationsPath = getMigrationsFolderPath();
const migrationPath = path.join(migrationsPath, id);
if (!fs.existsSync(migrationPath)) {
fs.writeFileSync(migrationPath, "");
callback();
}
}
export function getIndexSqlitePath(): string {
return path.join(getIndexFolderPath(), "index.sqlite");
}
export function getLanceDbPath(): string {
return path.join(getIndexFolderPath(), "lancedb");
}
export function getTabAutocompleteCacheSqlitePath(): string {
return path.join(getIndexFolderPath(), "autocompleteCache.sqlite");
}
export function getDocsSqlitePath(): string {
return path.join(getIndexFolderPath(), "docs.sqlite");
}
export function getRemoteConfigsFolderPath(): string {
const dir = path.join(getContinueGlobalPath(), ".configs");
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
return dir;
}
export function getPathToRemoteConfig(remoteConfigServerUrl: URL): string {
const dir = path.join(
getRemoteConfigsFolderPath(),
remoteConfigServerUrl.hostname,
);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
return dir;
}
export function getConfigJsonPathForRemote(remoteConfigServerUrl: URL): string {
return path.join(getPathToRemoteConfig(remoteConfigServerUrl), "config.json");
}
export function getConfigJsPathForRemote(remoteConfigServerUrl: URL): string {
return path.join(getPathToRemoteConfig(remoteConfigServerUrl), "config.js");
}
export function getContinueDotEnv(): { [key: string]: string } {
const filepath = path.join(getContinueGlobalPath(), ".env");
if (fs.existsSync(filepath)) {
return dotenv.parse(fs.readFileSync(filepath));
} else {
return {};
}
}
export function getCoreLogsPath(): string {
return path.join(getContinueGlobalPath(), "core.log");
}