* 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>
320 lines
8.6 KiB
TypeScript
320 lines
8.6 KiB
TypeScript
import * as child_process from "child_process";
|
|
import { exec } from "child_process";
|
|
import { ContinueRcJson, IDE, IdeInfo, IndexTag, Problem, Range, Thread } from "core";
|
|
import { getContinueGlobalPath } from "core/util/paths";
|
|
import * as path from "path";
|
|
import * as vscode from "vscode";
|
|
import { DiffManager } from "./diff/horizontal";
|
|
import { VsCodeIdeUtils } from "./util/ideUtils";
|
|
import { traverseDirectory } from "./util/traverseDirectory";
|
|
import {
|
|
getExtensionUri,
|
|
openEditorAndRevealRange,
|
|
uriFromFilePath,
|
|
} from "./util/vscode";
|
|
|
|
class VsCodeIde implements IDE {
|
|
ideUtils: VsCodeIdeUtils;
|
|
|
|
constructor(private readonly diffManager: DiffManager) {
|
|
this.ideUtils = new VsCodeIdeUtils();
|
|
}
|
|
async getTags(artifactId: string): Promise<IndexTag[]> {
|
|
const workspaceDirs = await this.getWorkspaceDirs();
|
|
|
|
const branches = await Promise.all(
|
|
workspaceDirs.map((dir) => this.getBranch(dir)),
|
|
);
|
|
|
|
const tags: IndexTag[] = workspaceDirs.map((directory, i) => ({
|
|
directory,
|
|
branch: branches[i],
|
|
artifactId,
|
|
}));
|
|
|
|
return tags;
|
|
}
|
|
getIdeInfo(): Promise<IdeInfo> {
|
|
return Promise.resolve({
|
|
ideType: "vscode",
|
|
name: vscode.env.appName,
|
|
version: vscode.version,
|
|
remoteName: vscode.env.remoteName || "local",
|
|
});
|
|
}
|
|
readRangeInFile(filepath: string, range: Range): Promise<string> {
|
|
return this.ideUtils.readRangeInFile(
|
|
filepath,
|
|
new vscode.Range(
|
|
new vscode.Position(range.start.line, range.start.character),
|
|
new vscode.Position(range.end.line, range.end.character)
|
|
)
|
|
);
|
|
}
|
|
|
|
async getStats(directory: string): Promise<{ [path: string]: number }> {
|
|
const scheme = vscode.workspace.workspaceFolders?.[0].uri.scheme;
|
|
const files = await this.listWorkspaceContents(directory);
|
|
const pathToLastModified: { [path: string]: number } = {};
|
|
await Promise.all(
|
|
files.map(async (file) => {
|
|
let stat = await vscode.workspace.fs.stat(uriFromFilePath(file));
|
|
pathToLastModified[file] = stat.mtime;
|
|
})
|
|
);
|
|
|
|
return pathToLastModified;
|
|
}
|
|
|
|
async getRepo(dir: vscode.Uri): Promise<any> {
|
|
return this.ideUtils.getRepo(dir);
|
|
}
|
|
|
|
async isTelemetryEnabled(): Promise<boolean> {
|
|
return (
|
|
(await vscode.workspace
|
|
.getConfiguration("continue")
|
|
.get("telemetryEnabled")) ?? true
|
|
);
|
|
}
|
|
getUniqueId(): Promise<string> {
|
|
return Promise.resolve(vscode.env.machineId);
|
|
}
|
|
|
|
async getDiff(): Promise<string> {
|
|
return await this.ideUtils.getDiff();
|
|
}
|
|
|
|
async getTerminalContents(): Promise<string> {
|
|
return await this.ideUtils.getTerminalContents(1);
|
|
}
|
|
|
|
async getDebugLocals(threadIndex: number): Promise<string> {
|
|
return await this.ideUtils.getDebugLocals(threadIndex);
|
|
}
|
|
|
|
async getTopLevelCallStackSources(
|
|
threadIndex: number,
|
|
stackDepth: number
|
|
): Promise<string[]> {
|
|
return await this.ideUtils.getTopLevelCallStackSources(
|
|
threadIndex,
|
|
stackDepth
|
|
);
|
|
}
|
|
async getAvailableThreads(): Promise<Thread[]> {
|
|
return await this.ideUtils.getAvailableThreads();
|
|
}
|
|
|
|
async listWorkspaceContents(directory?: string): Promise<string[]> {
|
|
if (directory) {
|
|
return await this.ideUtils.getDirectoryContents(directory, true);
|
|
} else {
|
|
const contents = await Promise.all(
|
|
this.ideUtils
|
|
.getWorkspaceDirectories()
|
|
.map((dir) => this.ideUtils.getDirectoryContents(dir, true))
|
|
);
|
|
return contents.flat();
|
|
}
|
|
}
|
|
|
|
async getWorkspaceConfigs() {
|
|
const workspaceDirs =
|
|
vscode.workspace.workspaceFolders?.map((folder) => folder.uri) || [];
|
|
const configs: ContinueRcJson[] = [];
|
|
for (const workspaceDir of workspaceDirs) {
|
|
const files = await vscode.workspace.fs.readDirectory(workspaceDir);
|
|
for (const [filename, type] of files) {
|
|
if (type === vscode.FileType.File && filename === ".continuerc.json") {
|
|
const contents = await this.ideUtils.readFile(
|
|
vscode.Uri.joinPath(workspaceDir, filename).fsPath
|
|
);
|
|
configs.push(JSON.parse(contents));
|
|
}
|
|
}
|
|
}
|
|
return configs;
|
|
}
|
|
|
|
async listFolders(): Promise<string[]> {
|
|
const allDirs: string[] = [];
|
|
|
|
const workspaceDirs = await this.getWorkspaceDirs();
|
|
for (const directory of workspaceDirs) {
|
|
for await (const dir of traverseDirectory(
|
|
directory,
|
|
[],
|
|
false,
|
|
undefined
|
|
)) {
|
|
allDirs.push(dir);
|
|
}
|
|
}
|
|
|
|
return allDirs;
|
|
}
|
|
|
|
async getWorkspaceDirs(): Promise<string[]> {
|
|
return this.ideUtils.getWorkspaceDirectories();
|
|
}
|
|
|
|
async getContinueDir(): Promise<string> {
|
|
return getContinueGlobalPath();
|
|
}
|
|
|
|
async writeFile(path: string, contents: string): Promise<void> {
|
|
await vscode.workspace.fs.writeFile(
|
|
vscode.Uri.file(path),
|
|
Buffer.from(contents)
|
|
);
|
|
}
|
|
|
|
async showVirtualFile(title: string, contents: string): Promise<void> {
|
|
this.ideUtils.showVirtualFile(title, contents);
|
|
}
|
|
|
|
async openFile(path: string): Promise<void> {
|
|
this.ideUtils.openFile(path);
|
|
}
|
|
|
|
async showLines(
|
|
filepath: string,
|
|
startLine: number,
|
|
endLine: number
|
|
): Promise<void> {
|
|
const range = new vscode.Range(
|
|
new vscode.Position(startLine, 0),
|
|
new vscode.Position(endLine, 0)
|
|
);
|
|
openEditorAndRevealRange(filepath, range).then(() => {
|
|
// TODO: Highlight lines
|
|
// this.ideUtils.highlightCode(
|
|
// {
|
|
// filepath,
|
|
// range,
|
|
// },
|
|
// "#fff1"
|
|
// );
|
|
});
|
|
}
|
|
|
|
async runCommand(command: string): Promise<void> {
|
|
if (vscode.window.terminals.length) {
|
|
vscode.window.terminals[0].show();
|
|
vscode.window.terminals[0].sendText(command, false);
|
|
} else {
|
|
const terminal = vscode.window.createTerminal();
|
|
terminal.show();
|
|
terminal.sendText(command, false);
|
|
}
|
|
}
|
|
|
|
async saveFile(filepath: string): Promise<void> {
|
|
await this.ideUtils.saveFile(filepath);
|
|
}
|
|
async readFile(filepath: string): Promise<string> {
|
|
return await this.ideUtils.readFile(filepath);
|
|
}
|
|
async showDiff(
|
|
filepath: string,
|
|
newContents: string,
|
|
stepIndex: number
|
|
): Promise<void> {
|
|
await this.diffManager.writeDiff(filepath, newContents, stepIndex);
|
|
}
|
|
|
|
async getOpenFiles(): Promise<string[]> {
|
|
return await this.ideUtils.getOpenFiles();
|
|
}
|
|
|
|
async getPinnedFiles(): Promise<string[]> {
|
|
const tabArray = vscode.window.tabGroups.all[0].tabs;
|
|
|
|
return tabArray
|
|
.filter((t) => t.isPinned)
|
|
.map((t) => (t.input as vscode.TabInputText).uri.fsPath);
|
|
}
|
|
|
|
private async _searchDir(query: string, dir: string): Promise<string> {
|
|
const p = child_process.spawn(
|
|
path.join(
|
|
getExtensionUri().fsPath,
|
|
"out",
|
|
"node_modules",
|
|
"@vscode",
|
|
"ripgrep",
|
|
"bin",
|
|
"rg"
|
|
),
|
|
["-i", "-C", "2", "--", `${query}`, "."], //no regex
|
|
//["-i", "-C", "2", "-e", `${query}`, "."], //use regex
|
|
{ cwd: dir }
|
|
);
|
|
let output = "";
|
|
|
|
p.stdout.on("data", (data) => {
|
|
output += data.toString();
|
|
});
|
|
|
|
return new Promise<string>((resolve, reject) => {
|
|
p.on("error", reject);
|
|
p.on("close", (code) => {
|
|
if (code === 0) {
|
|
resolve(output);
|
|
} else {
|
|
reject(new Error(`Process exited with code ${code}`));
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
async getSearchResults(query: string): Promise<string> {
|
|
let results = [];
|
|
for (let dir of await this.getWorkspaceDirs()) {
|
|
results.push(await this._searchDir(query, dir));
|
|
}
|
|
|
|
return results.join("\n\n");
|
|
}
|
|
|
|
async getProblems(filepath?: string | undefined): Promise<Problem[]> {
|
|
const uri = filepath
|
|
? vscode.Uri.file(filepath)
|
|
: vscode.window.activeTextEditor?.document.uri;
|
|
if (!uri) {
|
|
return [];
|
|
}
|
|
return vscode.languages.getDiagnostics(uri).map((d) => {
|
|
return {
|
|
filepath: uri.fsPath,
|
|
range: {
|
|
start: {
|
|
line: d.range.start.line,
|
|
character: d.range.start.character,
|
|
},
|
|
end: { line: d.range.end.line, character: d.range.end.character },
|
|
},
|
|
message: d.message,
|
|
};
|
|
});
|
|
}
|
|
|
|
async subprocess(command: string): Promise<[string, string]> {
|
|
return new Promise((resolve, reject) => {
|
|
exec(command, (error, stdout, stderr) => {
|
|
if (error) {
|
|
console.warn(error);
|
|
reject(stderr);
|
|
}
|
|
resolve([stdout, stderr]);
|
|
});
|
|
});
|
|
}
|
|
|
|
async getBranch(dir: string): Promise<string> {
|
|
return this.ideUtils.getBranch(vscode.Uri.file(dir));
|
|
}
|
|
}
|
|
|
|
export { VsCodeIde };
|