getFileresults
This commit is contained in:
parent
ed03f5a977
commit
2e9f005baf
12 changed files with 99 additions and 40 deletions
2
core/index.d.ts
vendored
2
core/index.d.ts
vendored
|
|
@ -709,6 +709,8 @@ export interface IDE {
|
|||
|
||||
getSearchResults(query: string): Promise<string>;
|
||||
|
||||
getFileResults(pattern: string): Promise<string[]>;
|
||||
|
||||
subprocess(command: string, cwd?: string): Promise<[string, string]>;
|
||||
|
||||
getProblems(fileUri?: string | undefined): Promise<Problem[]>;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ export type ToIdeFromWebviewOrCoreProtocol = {
|
|||
openUrl: [string, void];
|
||||
runCommand: [{ command: string; options?: TerminalOptions }, void];
|
||||
getSearchResults: [{ query: string }, string];
|
||||
getFileResults: [{ pattern: string }, string[]];
|
||||
subprocess: [{ command: string; cwd?: string }, [string, string]];
|
||||
saveFile: [{ filepath: string }, void];
|
||||
fileExists: [{ filepath: string }, boolean];
|
||||
|
|
|
|||
|
|
@ -187,6 +187,10 @@ export class MessageIde implements IDE {
|
|||
return this.request("getSearchResults", { query });
|
||||
}
|
||||
|
||||
getFileResults(pattern: string): Promise<string[]> {
|
||||
return this.request("getFileResults", { pattern });
|
||||
}
|
||||
|
||||
getProblems(fileUri: string): Promise<Problem[]> {
|
||||
return this.request("getProblems", { filepath: fileUri });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,6 +166,10 @@ export class ReverseMessageIde {
|
|||
return this.ide.getSearchResults(data.query);
|
||||
});
|
||||
|
||||
this.on("getFileResults", (data) => {
|
||||
return this.ide.getFileResults(data.pattern);
|
||||
});
|
||||
|
||||
this.on("getProblems", (data) => {
|
||||
return this.ide.getProblems(data.filepath);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -238,6 +238,10 @@ class FileSystemIde implements IDE {
|
|||
return "";
|
||||
}
|
||||
|
||||
async getFileResults(pattern: string): Promise<string[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
async getProblems(fileUri?: string | undefined): Promise<Problem[]> {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ class MessageTypes {
|
|||
"getCurrentFile",
|
||||
"getPinnedFiles",
|
||||
"getSearchResults",
|
||||
"getFileResults",
|
||||
"getProblems",
|
||||
"subprocess",
|
||||
"getBranch",
|
||||
|
|
|
|||
|
|
@ -347,6 +347,15 @@ class IdeProtocolClient(
|
|||
respond(results)
|
||||
}
|
||||
|
||||
"getFileResults" -> {
|
||||
val params = Gson().fromJson(
|
||||
dataElement.toString(),
|
||||
GetFileResultsParams::class.java
|
||||
)
|
||||
val results = ide.getFileResults(params.pattern)
|
||||
respond(results)
|
||||
}
|
||||
|
||||
"getOpenFiles" -> {
|
||||
val openFiles = ide.getOpenFiles()
|
||||
respond(openFiles)
|
||||
|
|
|
|||
|
|
@ -309,7 +309,34 @@ class IntelliJIDE(
|
|||
return getOpenFiles()
|
||||
}
|
||||
|
||||
override suspend fun getFileResults(pattern: String): List<String> {
|
||||
return listOf("")
|
||||
}
|
||||
|
||||
override suspend fun getSearchResults(query: String): String {
|
||||
// return withContext(Dispatchers.IO) {
|
||||
// val findModel = FindModel().apply {
|
||||
// stringToFind = query
|
||||
// isRegularExpressions = false
|
||||
// isWholeWordsOnly = false
|
||||
// isCaseSensitive = false
|
||||
// searchContext = UsageSearchContext.ANY
|
||||
// }
|
||||
|
||||
// val results = StringBuilder()
|
||||
// runReadAction {
|
||||
// FindInProjectUtil.findUsages(
|
||||
// findModel,
|
||||
// project.baseDir,
|
||||
// {
|
||||
// results.append("${it.file.path}:${it.line + 1}: ${it.lineText}\n")
|
||||
// true
|
||||
// },
|
||||
// null
|
||||
// )
|
||||
// }
|
||||
// results.toString()
|
||||
// }
|
||||
val command = GeneralCommandLine(ripgrep, "-i", "-C", "2", "--heading", "-e", query, ".")
|
||||
command.setWorkDirectory(project.basePath)
|
||||
return ExecUtil.execAndGetOutput(command).stdout
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ typealias getTagsParams = String
|
|||
|
||||
data class GetSearchResultsParams(val query: String)
|
||||
|
||||
data class GetFileResultsParams(val pattern: String)
|
||||
|
||||
data class SaveFileParams(val filepath: String)
|
||||
|
||||
|
|
|
|||
|
|
@ -159,6 +159,8 @@ interface IDE {
|
|||
|
||||
suspend fun getSearchResults(query: String): String
|
||||
|
||||
suspend fun getFileResults(pattern: String): List<String>
|
||||
|
||||
// Note: This should be a `Pair<String, String>` but we use `List<Any>` because the keys of `Pair`
|
||||
// will serialize to `first and `second` rather than `0` and `1` like in JavaScript
|
||||
suspend fun subprocess(command: String, cwd: String? = null): List<Any>
|
||||
|
|
|
|||
|
|
@ -555,50 +555,51 @@ class VsCodeIde implements IDE {
|
|||
.map((t) => (t.input as vscode.TabInputText).uri.toString());
|
||||
}
|
||||
|
||||
private async _searchDir(query: string, dir: string): Promise<string> {
|
||||
const relativeDir = vscode.Uri.parse(dir).fsPath;
|
||||
const ripGrepUri = vscode.Uri.joinPath(
|
||||
getExtensionUri(),
|
||||
"out/node_modules/@vscode/ripgrep/bin/rg",
|
||||
);
|
||||
const p = child_process.spawn(
|
||||
ripGrepUri.fsPath,
|
||||
[
|
||||
"-i", // Case-insensitive search
|
||||
"-C",
|
||||
"2", // Show 2 lines of context
|
||||
"--heading", // Only show filepath once per result
|
||||
"-e",
|
||||
query, // Pattern to search for
|
||||
".", // Directory to search in
|
||||
],
|
||||
{ cwd: relativeDir },
|
||||
);
|
||||
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 if (code === 1) {
|
||||
// No matches
|
||||
resolve("No matches found");
|
||||
} else {
|
||||
reject(new Error(`Process exited with code ${code}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
async getFileResults(pattern: string): Promise<string[]> {
|
||||
vscode.workspace.findFiles("");
|
||||
return [];
|
||||
}
|
||||
|
||||
async getSearchResults(query: string): Promise<string> {
|
||||
const results: string[] = [];
|
||||
for (const dir of await this.getWorkspaceDirs()) {
|
||||
const dirResults = await this._searchDir(query, dir);
|
||||
const relativeDir = vscode.Uri.parse(dir).fsPath;
|
||||
const ripGrepUri = vscode.Uri.joinPath(
|
||||
getExtensionUri(),
|
||||
"out/node_modules/@vscode/ripgrep/bin/rg",
|
||||
);
|
||||
const p = child_process.spawn(
|
||||
ripGrepUri.fsPath,
|
||||
[
|
||||
"-i", // Case-insensitive search
|
||||
"-C",
|
||||
"2", // Show 2 lines of context
|
||||
"--heading", // Only show filepath once per result
|
||||
"-e",
|
||||
query, // Pattern to search for
|
||||
".", // Directory to search in
|
||||
],
|
||||
{ cwd: relativeDir },
|
||||
);
|
||||
let output = "";
|
||||
|
||||
p.stdout.on("data", (data) => {
|
||||
output += data.toString();
|
||||
});
|
||||
|
||||
const dirResults = await new Promise<string>((resolve, reject) => {
|
||||
p.on("error", reject);
|
||||
p.on("close", (code) => {
|
||||
if (code === 0) {
|
||||
resolve(output);
|
||||
} else if (code === 1) {
|
||||
// No matches
|
||||
resolve("No matches found");
|
||||
} else {
|
||||
reject(new Error(`Process exited with code ${code}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const keepLines: string[] = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import { stripImages } from "core/util/messageContent";
|
|||
import { getUriPathBasename } from "core/util/uri";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
import { ILLM } from "core";
|
||||
import { VerticalDiffManager } from "../diff/vertical/manager";
|
||||
import EditDecorationManager from "../quickEdit/EditDecorationManager";
|
||||
import {
|
||||
|
|
@ -28,7 +29,6 @@ import { showTutorial } from "../util/tutorial";
|
|||
import { getExtensionUri } from "../util/vscode";
|
||||
import { VsCodeIde } from "../VsCodeIde";
|
||||
import { VsCodeWebviewProtocol } from "../webviewProtocol";
|
||||
import { ILLM } from "core";
|
||||
|
||||
/**
|
||||
* A shared messenger class between Core and Webview
|
||||
|
|
@ -391,6 +391,9 @@ export class VsCodeMessenger {
|
|||
this.onWebviewOrCore("getSearchResults", async (msg) => {
|
||||
return ide.getSearchResults(msg.data.query);
|
||||
});
|
||||
this.onWebviewOrCore("getFileResults", async (msg) => {
|
||||
return ide.getFileResults(msg.data.pattern);
|
||||
});
|
||||
this.onWebviewOrCore("subprocess", async (msg) => {
|
||||
return ide.subprocess(msg.data.command, msg.data.cwd);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue