make rg executable

This commit is contained in:
Nate 2025-04-23 18:22:42 -07:00
parent 3cb27e43b9
commit 10a264e2c6

View file

@ -42,7 +42,7 @@ class IntelliJIDE(
private val project: Project,
private val continuePluginService: ContinuePluginService,
) : IDE {
) : IDE {
private val gitService = GitService(project, continuePluginService)
@ -57,6 +57,19 @@ class IntelliJIDE(
val os = getOS()
ripgrep =
Paths.get(pluginPath.toString(), "ripgrep", "bin", "rg" + if (os == OS.WINDOWS) ".exe" else "").toString()
// Make ripgrep executable if on Unix-like systems
try {
if (os == OS.LINUX || os == OS.MAC) {
val file = File(ripgrep)
if (!file.canExecute()) {
file.setExecutable(true)
}
}
} catch (e: Throwable) {
e.printStackTrace()
}
}
/**
@ -311,7 +324,7 @@ class IntelliJIDE(
val ideInfo = this.getIdeInfo()
if (ideInfo.remoteName == "local") {
val command = GeneralCommandLine(
ripgrep,
ripgrep,
"--files",
"--iglob",
pattern,
@ -320,37 +333,37 @@ class IntelliJIDE(
"--ignore-file",
".gitignore",
)
command.setWorkDirectory(project.basePath)
val results = ExecUtil.execAndGetOutput(command).stdout
return results.split("\n")
} else {
throw NotImplementedError("Ripgrep not supported, this workspace is remote")
throw NotImplementedError("Ripgrep not supported, this workspace is remote")
// Leaving in here for ideas
// val projectBasePath = project.basePath ?: return emptyList()
// val scope = GlobalSearchScope.projectScope(project)
//
// // Get all ignore patterns from .continueignore files
// val ignorePatterns = mutableSetOf<String>()
// VirtualFileManager.getInstance().findFileByUrl("file://$projectBasePath")?.let { root ->
// VfsUtil.collectChildrenRecursively(root).forEach { file ->
// if (file.name == ".continueignore") {
// file.inputStream.bufferedReader().useLines { lines ->
// ignorePatterns.addAll(lines.filter { it.isNotBlank() && !it.startsWith("#") })
// }
// }
// }
// }
//
// return FilenameIndex.getAllFilesByExt(project, "*", scope)
// .filter { file ->
// val relativePath = file.path.removePrefix("$projectBasePath/")
// // Check if file matches pattern and isn't ignored
// PatternUtil.(relativePath, pattern) &&
// !ignorePatterns.any { PatternUtil.matchesGlob(relativePath, it) }
// }
// .map { it.path.removePrefix("$projectBasePath/") }
// Leaving in here for ideas
// val projectBasePath = project.basePath ?: return emptyList()
// val scope = GlobalSearchScope.projectScope(project)
//
// // Get all ignore patterns from .continueignore files
// val ignorePatterns = mutableSetOf<String>()
// VirtualFileManager.getInstance().findFileByUrl("file://$projectBasePath")?.let { root ->
// VfsUtil.collectChildrenRecursively(root).forEach { file ->
// if (file.name == ".continueignore") {
// file.inputStream.bufferedReader().useLines { lines ->
// ignorePatterns.addAll(lines.filter { it.isNotBlank() && !it.startsWith("#") })
// }
// }
// }
// }
//
// return FilenameIndex.getAllFilesByExt(project, "*", scope)
// .filter { file ->
// val relativePath = file.path.removePrefix("$projectBasePath/")
// // Check if file matches pattern and isn't ignored
// PatternUtil.(relativePath, pattern) &&
// !ignorePatterns.any { PatternUtil.matchesGlob(relativePath, it) }
// }
// .map { it.path.removePrefix("$projectBasePath/") }
}
}
@ -358,20 +371,20 @@ class IntelliJIDE(
val ideInfo = this.getIdeInfo()
if (ideInfo.remoteName == "local") {
val command = GeneralCommandLine(
ripgrep,
"-i",
ripgrep,
"-i",
"--ignore-file",
".continueignore",
"--ignore-file",
".gitignore",
"-C",
"2",
"--heading",
"-e",
query,
".gitignore",
"-C",
"2",
"--heading",
"-e",
query,
"."
)
command.setWorkDirectory(project.basePath)
return ExecUtil.execAndGetOutput(command).stdout
} else {
@ -415,7 +428,7 @@ class IntelliJIDE(
// return searchResults.toString()
}
}
override suspend fun subprocess(command: String, cwd: String?): List<Any> {
val commandList = command.split(" ")