Skip to content

Commit e3fde74

Browse files
committed
feat(indexer): add language-specific file name providers for Python and Rust #358
- Implement PythonLangDictProvider for collecting Python file names - Implement RustLangDictProvider for collecting Rust file names - Update plugin XML files to register new providers - Remove unused imports in RustClassContextBuilder
1 parent d0c91b7 commit e3fde74

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cc.unitmesh.python.indexer.provider
2+
3+
import cc.unitmesh.devti.indexer.provider.LangDictProvider
4+
import com.intellij.openapi.application.runReadAction
5+
import com.intellij.openapi.project.Project
6+
import com.intellij.psi.search.FileTypeIndex
7+
import com.intellij.psi.search.ProjectScope
8+
import com.jetbrains.python.PythonFileType
9+
10+
class PythonLangDictProvider : LangDictProvider {
11+
override suspend fun collectFileNames(project: Project): List<String> {
12+
val searchScope = ProjectScope.getProjectScope(project)
13+
val javaFiles = runReadAction {
14+
FileTypeIndex.getFiles(PythonFileType.INSTANCE, searchScope)
15+
}
16+
17+
val filenames = javaFiles.mapNotNull {
18+
it.nameWithoutExtension
19+
}
20+
21+
return filenames
22+
}
23+
}

pycharm/src/main/resources/cc.unitmesh.pycharm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@
3030
<relatedClassProvider
3131
language="Python"
3232
implementationClass="cc.unitmesh.python.provider.PythonRelatedClassProvider"/>
33+
34+
<langDictProvider implementation="cc.unitmesh.python.indexer.provider.PythonLangDictProvider"/>
3335
</extensions>
3436
</idea-plugin>

rust/src/233/main/kotlin/cc/unitmesh/rust/context/RustClassContextBuilder.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import org.rust.lang.core.psi.RsStructItem
1212
import org.rust.lang.core.psi.ext.RsStructOrEnumItemElement
1313
import org.rust.lang.core.psi.ext.expandedFields
1414
import org.rust.lang.core.psi.ext.implementingType
15-
import org.rust.lang.core.types.asTy
16-
import org.rust.lang.core.types.implLookup
1715

1816
class RustClassContextBuilder : ClassContextBuilder {
1917
override fun getClassContext(psiElement: PsiElement, gatherUsages: Boolean): ClassContext? {

rust/src/233/main/resources/cc.unitmesh.rust.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@
2222

2323
<testContextProvider language="Rust" implementation="cc.unitmesh.rust.provider.RustTestService"/>
2424
<codeModifier language="Rust" implementationClass="cc.unitmesh.rust.provider.RustCodeModifier"/>
25+
26+
<langDictProvider implementation="cc.unitmesh.rust.indexer.provider.RustLangDictProvider"/>
2527
</extensions>
2628
</idea-plugin>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cc.unitmesh.rust.indexer.provider
2+
3+
import cc.unitmesh.devti.indexer.provider.LangDictProvider
4+
import com.intellij.openapi.application.runReadAction
5+
import com.intellij.openapi.project.Project
6+
import com.intellij.psi.search.FileTypeIndex
7+
import com.intellij.psi.search.ProjectScope
8+
import org.rust.lang.RsFileType
9+
10+
class RustLangDictProvider : LangDictProvider {
11+
override suspend fun collectFileNames(project: Project): List<String> {
12+
val searchScope = ProjectScope.getProjectScope(project)
13+
val javaFiles = runReadAction {
14+
FileTypeIndex.getFiles(RsFileType, searchScope)
15+
}
16+
17+
val filenames = javaFiles.mapNotNull {
18+
it.nameWithoutExtension
19+
}
20+
21+
return filenames
22+
}
23+
}

0 commit comments

Comments
 (0)