feat: better error handling around ripgrep

This commit is contained in:
Patrick Erichsen 2025-05-08 18:56:14 -07:00
parent 587459c007
commit 22f6fdfa1b
4 changed files with 52 additions and 101 deletions

View File

@ -7,8 +7,6 @@ const AdmZip = require("adm-zip");
const RIPGREP_BASE_URL = `https://github.com/BurntSushi/ripgrep/releases/download/${RIPGREP_VERSION}`;
// Mapping from our target triplets to ripgrep release file names is now imported from targets.js
/**
* Downloads a file from a URL to a specified path
*

View File

@ -3,7 +3,7 @@ package com.github.continuedev.continueintellijextension.constants
/**
* Constants related to the Continue plugin.
*/
object PluginConstants {
object ContinueConstants {
/**
* The unique identifier for the Continue plugin.
*/

View File

@ -1,6 +1,6 @@
import com.github.continuedev.continueintellijextension.*
import com.github.continuedev.continueintellijextension.constants.getContinueGlobalPath
import com.github.continuedev.continueintellijextension.constants.PluginConstants
import com.github.continuedev.continueintellijextension.constants.ContinueConstants
import com.github.continuedev.continueintellijextension.`continue`.GitService
import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
@ -68,7 +68,7 @@ class IntelliJIDE(
remoteName = "ssh"
}
val pluginId = PluginConstants.PLUGIN_ID
val pluginId = ContinueConstants.PLUGIN_ID
val plugin = PluginManagerCore.getPlugin(PluginId.getId(pluginId))
val extensionVersion = plugin?.version ?: "Unknown"
@ -307,109 +307,62 @@ class IntelliJIDE(
override suspend fun getFileResults(pattern: String): List<String> {
val ideInfo = this.getIdeInfo()
if (ideInfo.remoteName == "local") {
val command = GeneralCommandLine(
ripgrep,
"--files",
"--iglob",
pattern,
"--ignore-file",
".continueignore",
"--ignore-file",
".gitignore",
)
command.setWorkDirectory(project.basePath)
val results = ExecUtil.execAndGetOutput(command).stdout
return results.split("\n")
try {
val command = GeneralCommandLine(
ripgrep,
"--files",
"--iglob",
pattern,
"--ignore-file",
".continueignore",
"--ignore-file",
".gitignore",
)
command.setWorkDirectory(project.basePath)
val results = ExecUtil.execAndGetOutput(command).stdout
return results.split("\n")
} catch (e: Exception) {
showToast(
ToastType.ERROR,
"Error executing ripgrep: ${e.message}"
)
return emptyList()
}
} else {
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/") }
}
}
override suspend fun getSearchResults(query: String): String {
val ideInfo = this.getIdeInfo()
if (ideInfo.remoteName == "local") {
val command = GeneralCommandLine(
ripgrep,
"-i",
"--ignore-file",
".continueignore",
"--ignore-file",
".gitignore",
"-C",
"2",
"--heading",
"-e",
query,
"."
)
command.setWorkDirectory(project.basePath)
return ExecUtil.execAndGetOutput(command).stdout
try {
val command = GeneralCommandLine(
ripgrep,
"-i",
"--ignore-file",
".continueignore",
"--ignore-file",
".gitignore",
"-C",
"2",
"--heading",
"-e",
query,
"."
)
command.setWorkDirectory(project.basePath)
return ExecUtil.execAndGetOutput(command).stdout
} catch (e: Exception) {
showToast(
ToastType.ERROR,
"Error executing ripgrep: ${e.message}"
)
return "Error: Unable to execute ripgrep command."
}
} else {
throw NotImplementedError("Ripgrep not supported, this workspace is remote")
// For remote workspaces, use JetBrains search functionality
// val searchResults = StringBuilder()
// ApplicationManager.getApplication().invokeAndWait {
// val options = FindModel().apply {
// stringToFind = query
// isCaseSensitive = false
// isRegularExpressions = false
// isWholeWordsOnly = false
// searchContext = FindModel.SearchContext.ANY // or IN_CODE, IN_COMMENTS, IN_STRING_LITERALS, etc.
// isMultiline = true // Allow matching across multiple lines
// }
//
// val progressIndicator = EmptyProgressIndicator()
// val presentation = FindUsagesProcessPresentation(
// UsageViewPresentation()
// )
// val filesToSearch = ProjectFileIndex.getInstance(project)
// .iterateContent(::ArrayList)
// .filterNot { it.isDirectory }
// .toSet()
//
//
// FindInProjectUtil.findUsages(
// options,
// project,
// progressIndicator,
// presentation,
// filesToSearch
// ) { result ->
// val virtualFile = result.virtualFile
// searchResults.append(virtualFile.path).append("\n")
// searchResults.append("${result..trim()}\n")
// true // continue searching
// }
// }
// return searchResults.toString()
}
}

View File

@ -2,7 +2,7 @@ package com.github.continuedev.continueintellijextension.utils
import com.intellij.ide.plugins.PluginManager
import com.intellij.openapi.extensions.PluginId
import com.github.continuedev.continueintellijextension.constants.PluginConstants
import com.github.continuedev.continueintellijextension.constants.ContinueConstants
import java.nio.file.Path
import java.nio.file.Paths
@ -14,7 +14,7 @@ import java.nio.file.Paths
*/
fun getContinuePluginPath(): Path {
val pluginDescriptor =
PluginManager.getPlugin(PluginId.getId(PluginConstants.PLUGIN_ID)) ?: throw Exception("Plugin not found")
PluginManager.getPlugin(PluginId.getId(ContinueConstants.PLUGIN_ID)) ?: throw Exception("Plugin not found")
return pluginDescriptor.pluginPath
}