From 10a264e2c6a400164b8e9da8da6df58ff5f2ab62 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 23 Apr 2025 18:22:42 -0700 Subject: [PATCH] make rg executable --- .../continue/IntelliJIde.kt | 89 +++++++++++-------- 1 file changed, 51 insertions(+), 38 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt index 41bcc2941..991c89d86 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt @@ -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() - // 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() + // 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 { val commandList = command.split(" ")