Skip to content

Commit

Permalink
feat(util): add isInProject function
Browse files Browse the repository at this point in the history
Add a new function `isInProject` to the `ProjectFileUtil.kt` file. This function checks if a given `VirtualFile` is within the project. It returns a boolean value indicating whether the file is in the project or not. This function will be useful for various operations related to project files.
  • Loading branch information
phodal committed Jan 16, 2024
1 parent 50c2770 commit e806624
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 13 deletions.
@@ -1,5 +1,6 @@
package cc.unitmesh.ide.javascript.util

import cc.unitmesh.devti.util.isInProject
import com.intellij.lang.ecmascript6.psi.ES6ExportDeclaration
import com.intellij.lang.ecmascript6.psi.ES6ExportDefaultAssignment
import com.intellij.lang.javascript.frameworks.commonjs.CommonJSUtil
Expand Down Expand Up @@ -40,7 +41,7 @@ object JSPsiUtil {
val virtualFile = resolved.containingFile?.virtualFile

if (virtualFile == null ||
!ProjectFileIndex.getInstance(node.project).isInProject(virtualFile) ||
!node.project.isInProject(virtualFile) ||
ProjectFileIndex.getInstance(node.project).isInLibrary(virtualFile)
) {
return JSStubBasedPsiTreeUtil.resolveReferenceLocally(node as PsiPolyVariantReference, node.referenceName)
Expand Down
Expand Up @@ -15,9 +15,8 @@ import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.vcs.VcsDataKeys
import com.intellij.openapi.vcs.changes.Change
import com.intellij.openapi.vcs.ui.CommitMessage
import kotlinx.coroutines.flow.cancellable
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.*

class CommitMessageSuggestionAction : ChatBaseAction() {

Expand Down
Expand Up @@ -7,8 +7,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.Task
import com.intellij.psi.PsiNameIdentifierOwner
import kotlinx.coroutines.flow.cancellable
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.runBlocking

class CustomLivingDocTask(
Expand Down
Expand Up @@ -17,7 +17,7 @@ import kotlinx.coroutines.flow.cancellable
import kotlinx.coroutines.runBlocking
import java.nio.file.Path
import kotlin.io.path.Path
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.*

class FileGenerateTask(@JvmField val project: Project, val messages: List<LlmMsg.ChatMessage>, val fileName: String?) :
Task.Backgroundable(project, AutoDevBundle.message("intentions.request.background.process.title")) {
Expand Down
Expand Up @@ -32,8 +32,7 @@ import java.awt.event.ActionListener
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import javax.swing.*
import kotlinx.coroutines.flow.collect

import kotlinx.coroutines.flow.*

class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disposable: Disposable?) :
SimpleToolWindowPanel(true, true),
Expand Down
Expand Up @@ -20,7 +20,7 @@ import kotlinx.coroutines.flow.cancellable
import kotlinx.coroutines.launch
import java.awt.event.KeyEvent
import javax.swing.KeyStroke
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.*

abstract class BaseCompletionTask(private val request: CodeCompletionRequest) :
Task.Backgroundable(request.project, AutoDevBundle.message("intentions.chat.code.complete.name")) {
Expand Down
Expand Up @@ -11,7 +11,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.Task
import com.intellij.psi.PsiNameIdentifierOwner
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.runBlocking

/**
Expand Down
Expand Up @@ -23,8 +23,7 @@ import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.runBlocking

data class TestGenPromptContext(
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/cc/unitmesh/devti/util/ProjectFileUtil.kt
Expand Up @@ -17,4 +17,8 @@ fun isInProject(virtualFile: VirtualFile, project: Project): Boolean {
}

return false
}
}

fun Project.isInProject(virtualFile: VirtualFile): Boolean {
return isInProject(virtualFile, this)
}

0 comments on commit e806624

Please sign in to comment.