Skip to content

Commit

Permalink
feat(variables): add support for similar code search
Browse files Browse the repository at this point in the history
Add support for searching recently 20 files with similar code based on tf-idf search in variable context.
  • Loading branch information
phodal committed Jul 3, 2024
1 parent c3aeeb0 commit 5fe7f8f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ enum class PsiContextVariable(val variableName: String, val description: String?
METHOD_CALLER("methodCaller", "The method that initiates the current call"),

CALLED_METHOD("calledMethod", "The method that is being called by the current method"),

SIMILAR_CODE("similarCode", "Recently 20 files similar code based on the tf-idf search")
;

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.phodal.shirecore.provider.context.ToolchainPrepareContext
import com.phodal.shirecore.provider.variable.impl.CodeSmellBuilder
import com.phodal.shirecore.provider.variable.model.PsiContextVariable
import com.phodal.shirecore.provider.variable.PsiContextVariableProvider
import com.phodal.shirecore.search.SimilarChunksSearch
import com.phodal.shirelang.java.util.JavaTestHelper
import com.phodal.shirelang.java.util.getContainingClass
import com.phodal.shirelang.java.variable.provider.JavaRelatedClassesProvider
Expand Down Expand Up @@ -67,6 +68,8 @@ class JavaPsiContextVariableProvider : PsiContextVariableProvider {
if (psiElement !is PsiMethod) return ""
return JavaTestHelper.findCallees(psiElement).joinToString("\n") { it.text }
}

PsiContextVariable.SIMILAR_CODE -> return SimilarChunksSearch.createQuery(psiElement) ?: ""
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.phodal.shirelang.actions.vcs

import com.intellij.ide.DataManager

Check warning on line 3 in shirelang/src/main/kotlin/com/phodal/shirelang/actions/vcs/ShireVcsActionGroup.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
Expand Down

0 comments on commit 5fe7f8f

Please sign in to comment.