Skip to content

Commit 11a4be1

Browse files
committed
fix write file / open file for tools
1 parent bf1ae81 commit 11a4be1

File tree

1 file changed

+47
-40
lines changed
  • extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue

1 file changed

+47
-40
lines changed

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class IntelliJIDE(
4242
private val project: Project,
4343
private val continuePluginService: ContinuePluginService,
4444

45-
) : IDE {
45+
) : IDE {
4646

4747
private val gitService = GitService(project, continuePluginService)
4848

@@ -179,6 +179,7 @@ class IntelliJIDE(
179179

180180
override suspend fun writeFile(path: String, contents: String) {
181181
val file = File(URI(path))
182+
file.parentFile?.mkdirs()
182183
file.writeText(contents)
183184
}
184185

@@ -194,7 +195,13 @@ class IntelliJIDE(
194195
}
195196

196197
override suspend fun openFile(path: String) {
197-
val file = LocalFileSystem.getInstance().findFileByPath(URI(path).path)
198+
// Convert URI path to absolute file path
199+
val filePath = File(URI(path)).absolutePath
200+
// Find the file using the absolute path
201+
val file = withContext(Dispatchers.IO) {
202+
LocalFileSystem.getInstance().refreshAndFindFileByPath(filePath)
203+
}
204+
198205
file?.let {
199206
ApplicationManager.getApplication().invokeLater {
200207
FileEditorManager.getInstance(project).openFile(it, true)
@@ -311,7 +318,7 @@ class IntelliJIDE(
311318
val ideInfo = this.getIdeInfo()
312319
if (ideInfo.remoteName == "local") {
313320
val command = GeneralCommandLine(
314-
ripgrep,
321+
ripgrep,
315322
"--files",
316323
"--iglob",
317324
pattern,
@@ -320,58 +327,58 @@ class IntelliJIDE(
320327
"--ignore-file",
321328
".gitignore",
322329
)
323-
330+
324331
command.setWorkDirectory(project.basePath)
325332
val results = ExecUtil.execAndGetOutput(command).stdout
326333
return results.split("\n")
327334
} else {
328-
throw NotImplementedError("Ripgrep not supported, this workspace is remote")
329-
330-
// Leaving in here for ideas
331-
// val projectBasePath = project.basePath ?: return emptyList()
332-
// val scope = GlobalSearchScope.projectScope(project)
333-
//
334-
// // Get all ignore patterns from .continueignore files
335-
// val ignorePatterns = mutableSetOf<String>()
336-
// VirtualFileManager.getInstance().findFileByUrl("file://$projectBasePath")?.let { root ->
337-
// VfsUtil.collectChildrenRecursively(root).forEach { file ->
338-
// if (file.name == ".continueignore") {
339-
// file.inputStream.bufferedReader().useLines { lines ->
340-
// ignorePatterns.addAll(lines.filter { it.isNotBlank() && !it.startsWith("#") })
341-
// }
342-
// }
343-
// }
344-
// }
345-
//
346-
// return FilenameIndex.getAllFilesByExt(project, "*", scope)
347-
// .filter { file ->
348-
// val relativePath = file.path.removePrefix("$projectBasePath/")
349-
// // Check if file matches pattern and isn't ignored
350-
// PatternUtil.(relativePath, pattern) &&
351-
// !ignorePatterns.any { PatternUtil.matchesGlob(relativePath, it) }
352-
// }
353-
// .map { it.path.removePrefix("$projectBasePath/") }
335+
throw NotImplementedError("Ripgrep not supported, this workspace is remote")
336+
337+
// Leaving in here for ideas
338+
// val projectBasePath = project.basePath ?: return emptyList()
339+
// val scope = GlobalSearchScope.projectScope(project)
340+
//
341+
// // Get all ignore patterns from .continueignore files
342+
// val ignorePatterns = mutableSetOf<String>()
343+
// VirtualFileManager.getInstance().findFileByUrl("file://$projectBasePath")?.let { root ->
344+
// VfsUtil.collectChildrenRecursively(root).forEach { file ->
345+
// if (file.name == ".continueignore") {
346+
// file.inputStream.bufferedReader().useLines { lines ->
347+
// ignorePatterns.addAll(lines.filter { it.isNotBlank() && !it.startsWith("#") })
348+
// }
349+
// }
350+
// }
351+
// }
352+
//
353+
// return FilenameIndex.getAllFilesByExt(project, "*", scope)
354+
// .filter { file ->
355+
// val relativePath = file.path.removePrefix("$projectBasePath/")
356+
// // Check if file matches pattern and isn't ignored
357+
// PatternUtil.(relativePath, pattern) &&
358+
// !ignorePatterns.any { PatternUtil.matchesGlob(relativePath, it) }
359+
// }
360+
// .map { it.path.removePrefix("$projectBasePath/") }
354361
}
355362
}
356363

357364
override suspend fun getSearchResults(query: String): String {
358365
val ideInfo = this.getIdeInfo()
359366
if (ideInfo.remoteName == "local") {
360367
val command = GeneralCommandLine(
361-
ripgrep,
362-
"-i",
368+
ripgrep,
369+
"-i",
363370
"--ignore-file",
364371
".continueignore",
365372
"--ignore-file",
366-
".gitignore",
367-
"-C",
368-
"2",
369-
"--heading",
370-
"-e",
371-
query,
373+
".gitignore",
374+
"-C",
375+
"2",
376+
"--heading",
377+
"-e",
378+
query,
372379
"."
373380
)
374-
381+
375382
command.setWorkDirectory(project.basePath)
376383
return ExecUtil.execAndGetOutput(command).stdout
377384
} else {
@@ -415,7 +422,7 @@ class IntelliJIDE(
415422
// return searchResults.toString()
416423
}
417424
}
418-
425+
419426

420427
override suspend fun subprocess(command: String, cwd: String?): List<Any> {
421428
val commandList = command.split(" ")

0 commit comments

Comments
 (0)