add maxResults param to getSearchResults message

This commit is contained in:
Dallin Romney 2025-06-19 17:40:34 -07:00
parent 0d02784f94
commit 5f166b6401
12 changed files with 29 additions and 18 deletions

View file

@ -719,7 +719,7 @@ declare global {
getPinnedFiles(): Promise<string[]>;
getSearchResults(query: string): Promise<string>;
getSearchResults(query: string, maxResults?: number): Promise<string>;
subprocess(command: string, cwd?: string): Promise<[string, string]>;

2
core/index.d.ts vendored
View file

@ -781,7 +781,7 @@ export interface IDE {
getPinnedFiles(): Promise<string[]>;
getSearchResults(query: string): Promise<string>;
getSearchResults(query: string, maxResults?: number): Promise<string>;
getFileResults(pattern: string): Promise<string[]>;

View file

@ -29,7 +29,7 @@ export type ToIdeFromWebviewOrCoreProtocol = {
openFile: [{ path: string }, void];
openUrl: [string, void];
runCommand: [{ command: string; options?: TerminalOptions }, void];
getSearchResults: [{ query: string }, string];
getSearchResults: [{ query: string; maxResults?: number }, string];
getFileResults: [{ pattern: string }, string[]];
subprocess: [{ command: string; cwd?: string }, [string, string]];
saveFile: [{ filepath: string }, void];

View file

@ -185,8 +185,8 @@ export class MessageIde implements IDE {
return this.request("getPinnedFiles", undefined);
}
getSearchResults(query: string): Promise<string> {
return this.request("getSearchResults", { query });
getSearchResults(query: string, maxResults?: number): Promise<string> {
return this.request("getSearchResults", { query, maxResults });
}
getFileResults(pattern: string): Promise<string[]> {

View file

@ -159,7 +159,7 @@ export class ReverseMessageIde {
});
this.on("getSearchResults", (data) => {
return this.ide.getSearchResults(data.query);
return this.ide.getSearchResults(data.query, data.maxResults);
});
this.on("getFileResults", (data) => {

View file

@ -234,7 +234,7 @@ class FileSystemIde implements IDE {
return Promise.resolve([]);
}
async getSearchResults(query: string): Promise<string> {
async getSearchResults(query: string, maxResults?: number): Promise<string> {
return "";
}

View file

@ -356,7 +356,7 @@ class IdeProtocolClient(
dataElement.toString(),
GetSearchResultsParams::class.java
)
val results = ide.getSearchResults(params.query)
val results = ide.getSearchResults(params.query, params.maxResults)
respond(results)
}

View file

@ -344,11 +344,11 @@ class IntelliJIDE(
throw NotImplementedError("Ripgrep not supported, this workspace is remote")
}
}
override suspend fun getSearchResults(query: String): String {
override suspend fun getSearchResults(query: String, maxResults: Int?): String {
val ideInfo = this.getIdeInfo()
if (ideInfo.remoteName == "local") {
try {
val command = GeneralCommandLine(
val commandArgs = mutableListOf(
ripgrep,
"-i",
"--ignore-file",
@ -357,11 +357,21 @@ class IntelliJIDE(
".gitignore",
"-C",
"2",
"--heading",
"-e",
query,
"."
"--heading"
)
// Conditionally add maxResults flag
if (maxResults != null) {
commandArgs.add("-m")
commandArgs.add(maxResults.toString())
}
// Add the search query and path
commandArgs.add("-e")
commandArgs.add(query)
commandArgs.add(".")
val command = GeneralCommandLine(commandArgs)
command.setWorkDirectory(project.basePath)
return ExecUtil.execAndGetOutput(command).stdout

View file

@ -21,7 +21,7 @@ typealias OpenUrlParam = String
typealias getTagsParams = String
data class GetSearchResultsParams(val query: String)
data class GetSearchResultsParams(val query: String, val maxResults: Int?)
data class GetFileResultsParams(val pattern: String)

View file

@ -157,7 +157,7 @@ interface IDE {
suspend fun getPinnedFiles(): List<String>
suspend fun getSearchResults(query: String): String
suspend fun getSearchResults(query: String, maxResults: Int?): String
suspend fun getFileResults(pattern: String): List<String>

View file

@ -524,7 +524,7 @@ class VsCodeIde implements IDE {
}
}
async getSearchResults(query: string): Promise<string> {
async getSearchResults(query: string, maxResults?: number): Promise<string> {
if (vscode.env.remoteName) {
throw new Error("Ripgrep not supported, this workspace is remote");
}
@ -539,6 +539,7 @@ class VsCodeIde implements IDE {
"-C",
"2", // Show 2 lines of context
"--heading", // Only show filepath once per result
...(maxResults ? ["-m", maxResults.toString()] : []),
"-e",
query, // Pattern to search for
".", // Directory to search in

View file

@ -321,7 +321,7 @@ export class VsCodeMessenger {
await ide.runCommand(msg.data.command);
});
this.onWebviewOrCore("getSearchResults", async (msg) => {
return ide.getSearchResults(msg.data.query);
return ide.getSearchResults(msg.data.query, msg.data.maxResults);
});
this.onWebviewOrCore("getFileResults", async (msg) => {
return ide.getFileResults(msg.data.pattern);