Skip to content

Commit

Permalink
Fix IDE compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
pplam committed Oct 9, 2024
1 parent af2ffe7 commit 352b459
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ai.devchat.common.IDEUtils.foldTextOfLevel
import ai.devchat.common.IDEUtils.runInEdtAndGet
import ai.devchat.common.Log
import ai.devchat.storage.RecentFilesTracker
import com.intellij.openapi.vfs.isFile
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiUtilCore.getPsiFile

Expand Down Expand Up @@ -157,7 +156,7 @@ class ContextBuilder(val file: PsiFile, val offset: Int) {
val project = file.project
return runInEdtAndGet {
project.getService(RecentFilesTracker::class.java).getRecentFiles().asSequence()
.filter { it.isFile && it.path != filepath }
.filter { it.isValid && !it.isDirectory && it.path != filepath }
.map { CodeSnippet(it.path, getPsiFile(project, it).foldTextOfLevel(2)) }
.filter { it.content.lines().count(String::isBlank) <= 50 }
.takeWhile(::checkAndUpdateTokenCount)
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/ai/devchat/storage/RecentFilesTracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.startup.ProjectActivity
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.isFile
import com.intellij.util.messages.MessageBusConnection


Expand All @@ -26,7 +25,7 @@ class RecentFilesTracker(private val project: Project) {
val connection: MessageBusConnection = project.messageBus.connect()
connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, object : FileEditorManagerListener {
override fun fileOpened(source: FileEditorManager, file: VirtualFile) {
if (file.isFile) {
if (file.isValid && !file.isDirectory) {
addRecentFile(file)
}
}
Expand All @@ -37,7 +36,7 @@ class RecentFilesTracker(private val project: Project) {
}

private fun addRecentFile(file: VirtualFile) = runInEdt {
if (file.isFile && projectFileIndex.isInContent(file)) {
if (file.isValid && !file.isDirectory && projectFileIndex.isInContent(file)) {
recentFiles.remove(file)
recentFiles.add(0, file)
if (recentFiles.size > maxSize) {
Expand Down

0 comments on commit 352b459

Please sign in to comment.