From 6fbe91e3e338508b144d796359ba370ba461f5ac Mon Sep 17 00:00:00 2001 From: Kanro Date: Wed, 24 Jan 2024 00:26:39 +0800 Subject: [PATCH] Support Protobuf plugin by kanro (#166) This PR make buf plugin support the [IntelliJ Protobuf Plugin](https://github.com/devkanro/intellij-protobuf-plugin) by @devkanro, hereafter referred to as the Protobuf plugin. The buf plugin previously only supported the Protobuf plugin provided by JetBrains, hereafter referred to as the official plugin. This Protobuf plugin is more feature rich than the official plugin, please see the [GitHub home page](https://github.com/devkanro/intellij-protobuf-plugin) for details.. I make both the deps of official plugin and protobuf plugin be optional, the buf plugin will work fine with anyone for them. Resolve - https://github.com/devkanro/intellij-protobuf-plugin/discussions/214 --------- Co-authored-by: Philip K. Warren Co-authored-by: Nick Snyder --- CHANGELOG.md | 1 + build.gradle.kts | 26 ++++++- gradle.properties | 4 +- .../BufAnalyzeModificationTracker.kt | 10 ++- .../buf/intellij/annotator/BufAnalyzePass.kt | 14 ++-- .../buf/intellij/annotator/BufAnalyzeUtils.kt | 4 +- .../intellij/fixes/IgnoreBufIssueQuickFix.kt | 4 +- .../intellij/formatter/BufFormatterService.kt | 4 +- .../inspections/BufAnalyzeInspection.kt | 4 +- .../inspections/BufNotInstalledInspection.kt | 4 +- .../kotlin/build/buf/intellij/vendor/Utils.kt | 60 ++++++++++++++++ .../jetbrains}/BufProtoFileResolver.kt | 3 +- .../vendor/kanro/BufProtoFileResolver.kt | 71 +++++++++++++++++++ .../kanro-protobuf-plugin-support.xml | 5 ++ .../official-protobuf-plugin-support.xml | 5 ++ src/main/resources/META-INF/plugin.xml | 6 +- 16 files changed, 196 insertions(+), 29 deletions(-) create mode 100644 src/main/kotlin/build/buf/intellij/vendor/Utils.kt rename src/main/kotlin/build/buf/intellij/{resolve => vendor/jetbrains}/BufProtoFileResolver.kt (97%) create mode 100644 src/main/kotlin/build/buf/intellij/vendor/kanro/BufProtoFileResolver.kt create mode 100644 src/main/resources/META-INF/kanro-protobuf-plugin-support.xml create mode 100644 src/main/resources/META-INF/official-protobuf-plugin-support.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 9024c15a..504e5ec2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased +- Support [Protobuf plugin](https://github.com/devkanro/intellij-protobuf-plugin) by devkanro ## 0.2.1 - 2023-08-18 - Migrate to Kotlin UI DSL v2 in https://github.com/bufbuild/intellij-buf/pull/138 diff --git a/build.gradle.kts b/build.gradle.kts index 5224e0d4..a85a2486 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,7 @@ import org.jetbrains.changelog.Changelog import org.jetbrains.changelog.markdownToHTML +import org.jetbrains.intellij.tasks.PrepareSandboxTask +import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated fun properties(key: String) = providers.gradleProperty(key) fun environment(key: String) = providers.environmentVariable(key) @@ -189,13 +191,35 @@ tasks { password = environment("PRIVATE_KEY_PASSWORD") } + withType { + val vendor = project.findProperty("buf.protobuf.vendor")?.toString() + ?: System.getenv("BUF_PROTOBUF_VENDOR") ?: "official" + logger.info("Current Protobuf Plugin vendor: $vendor") + val disabledPluginsFile = project.layout.buildDirectory.dir(configDir).get().file("disabled_plugins.txt").asFile + + doLast { + disabledPluginsFile.ensureParentDirsCreated() + disabledPluginsFile.writeText( + buildString { + if (vendor == "devkanro") { + appendLine("idea.plugin.protoeditor") + appendLine("com.intellij.grpc") + } else { + appendLine("io.kanro.idea.plugin.protobuf") + } + }, + ) + } + } + publishPlugin { dependsOn("patchChangelog") token = environment("PUBLISH_TOKEN") // The pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3 // Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more: // https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel - channels = properties("pluginVersion").map { listOf(it.split('-').getOrElse(1) { "default" }.split('.').first()) } + channels = + properties("pluginVersion").map { listOf(it.split('-').getOrElse(1) { "default" }.split('.').first()) } } runPluginVerifier { diff --git a/gradle.properties b/gradle.properties index a2794588..eb6047a1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,10 +11,10 @@ pluginSinceBuild=223 pluginUntilBuild=999.* # IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties platformType=IU -platformVersion=2022.3.3 +platformVersion=2022.3 # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 -platformPlugins=idea.plugin.protoeditor, org.jetbrains.plugins.yaml +platformPlugins=idea.plugin.protoeditor, io.kanro.idea.plugin.protobuf:1.6.32, org.jetbrains.plugins.yaml # Gradle Releases -> https://github.com/gradle/gradle/releases gradleVersion=8.4 # Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib diff --git a/src/main/kotlin/build/buf/intellij/annotator/BufAnalyzeModificationTracker.kt b/src/main/kotlin/build/buf/intellij/annotator/BufAnalyzeModificationTracker.kt index 5dd6f0ef..af8fea33 100644 --- a/src/main/kotlin/build/buf/intellij/annotator/BufAnalyzeModificationTracker.kt +++ b/src/main/kotlin/build/buf/intellij/annotator/BufAnalyzeModificationTracker.kt @@ -16,12 +16,12 @@ package build.buf.intellij.annotator import build.buf.intellij.config.BufConfig import build.buf.intellij.settings.BufProjectSettingsService +import build.buf.intellij.vendor.protobufLanguage import com.intellij.openapi.application.runReadAction import com.intellij.openapi.components.Service import com.intellij.openapi.components.service import com.intellij.openapi.project.Project import com.intellij.openapi.util.ModificationTracker -import com.intellij.protobuf.lang.PbLanguage import com.intellij.psi.search.FilenameIndex import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.util.PsiModificationTracker @@ -32,10 +32,14 @@ import com.intellij.psi.util.PsiModificationTracker */ @Service(Service.Level.PROJECT) class BufAnalyzeModificationTracker(private val project: Project) : ModificationTracker { - private val protoModificationTracker = PsiModificationTracker.getInstance(project).forLanguage(PbLanguage.INSTANCE) + private val protoModificationTracker = protobufLanguage()?.let { + PsiModificationTracker.getInstance(project).forLanguage(it) + } + override fun getModificationCount(): Long { - var modificationCount : Long = protoModificationTracker.modificationCount + var modificationCount: Long = + protoModificationTracker?.modificationCount ?: 0 runReadAction { for (configFile in BufConfig.CONFIG_FILES) { FilenameIndex.getVirtualFilesByName(configFile, GlobalSearchScope.projectScope(project)).forEach { diff --git a/src/main/kotlin/build/buf/intellij/annotator/BufAnalyzePass.kt b/src/main/kotlin/build/buf/intellij/annotator/BufAnalyzePass.kt index c7f49756..738a6f85 100644 --- a/src/main/kotlin/build/buf/intellij/annotator/BufAnalyzePass.kt +++ b/src/main/kotlin/build/buf/intellij/annotator/BufAnalyzePass.kt @@ -18,6 +18,7 @@ import build.buf.intellij.BufPluginService import build.buf.intellij.fixes.IgnoreBufIssueQuickFix import build.buf.intellij.model.BufIssue import build.buf.intellij.settings.bufSettings +import build.buf.intellij.vendor.isProtobufFile import com.intellij.codeHighlighting.DirtyScopeTrackingHighlightingPassFactory import com.intellij.codeHighlighting.MainHighlightingPassFactory import com.intellij.codeHighlighting.TextEditorHighlightingPass @@ -46,7 +47,6 @@ import com.intellij.openapi.roots.ProjectFileIndex import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.Key import com.intellij.openapi.util.TextRange -import com.intellij.protobuf.lang.psi.PbFile import com.intellij.psi.PsiFile import com.intellij.psi.impl.AnyPsiChangeListener import com.intellij.psi.impl.PsiManagerImpl @@ -75,7 +75,7 @@ class BufAnalyzePass( override fun doCollectInformation(progress: ProgressIndicator) { annotationHolder.clear() - if (file !is PbFile) return + if (!file.isProtobufFile()) return if (!myProject.bufSettings.state.backgroundLintingEnabled && !myProject.bufSettings.state.backgroundBreakingEnabled) return val contentRootForFile = ProjectFileIndex.getInstance(myProject) @@ -101,7 +101,7 @@ class BufAnalyzePass( } override fun doApplyInformationToEditor() { - if (file !is PbFile) return + if (!file.isProtobufFile()) return if (annotationInfo == null) { disposable = appService @@ -126,8 +126,6 @@ class BufAnalyzePass( } }) } - - override fun canEat(update: Update?): Boolean = true } if (isUnitTestMode) { @@ -138,7 +136,7 @@ class BufAnalyzePass( } private fun doApply(annotationResult: BufAnalyzeResult) { - if (file !is PbFile || !file.isValid) return + if (!file.isProtobufFile() || !file.isValid) return try { @Suppress("UnstableApiUsage") annotationHolder.runAnnotatorWithContext(file) { _, holder -> @@ -226,7 +224,7 @@ class BufAnalyzePassFactory( val LAST_ANALYZE_MOD_COUNT = Key.create("build.buf.analyze.mod_count") fun shouldRunPass(file: PsiFile): Boolean { - if (file !is PbFile) { + if (!file.isProtobufFile()) { return false } val analyzeModTracker = file.project.service() @@ -255,7 +253,7 @@ fun MessageBus.createDisposableOnAnyPsiChange(): Disposable { } fun AnnotationHolder.createAnnotationsForFile( - file: PbFile, + file: PsiFile, annotationResult: BufAnalyzeResult ) { val doc = file.viewProvider.document diff --git a/src/main/kotlin/build/buf/intellij/annotator/BufAnalyzeUtils.kt b/src/main/kotlin/build/buf/intellij/annotator/BufAnalyzeUtils.kt index aa522dba..99af971b 100644 --- a/src/main/kotlin/build/buf/intellij/annotator/BufAnalyzeUtils.kt +++ b/src/main/kotlin/build/buf/intellij/annotator/BufAnalyzeUtils.kt @@ -21,6 +21,7 @@ import build.buf.intellij.model.BufIssue import build.buf.intellij.settings.BufCLIUtils import build.buf.intellij.settings.bufSettings import build.buf.intellij.status.BufCLIWidget +import build.buf.intellij.vendor.isProtobufFile import com.intellij.execution.process.ProcessAdapter import com.intellij.execution.process.ProcessEvent import com.intellij.execution.process.ProcessOutputType @@ -40,7 +41,6 @@ import com.intellij.openapi.progress.ProgressManager import com.intellij.openapi.progress.Task import com.intellij.openapi.project.Project import com.intellij.openapi.wm.WindowManager -import com.intellij.protobuf.lang.psi.PbFile import com.intellij.psi.PsiDocumentManager import com.intellij.psi.util.PsiModificationTracker import kotlinx.coroutines.Dispatchers @@ -94,7 +94,7 @@ object BufAnalyzeUtils { FileDocumentManager.getInstance() .saveDocuments { document -> val psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document) ?: return@saveDocuments false - psiFile is PbFile || BufConfig.CONFIG_FILES.contains(psiFile.name) + psiFile.isProtobufFile() || BufConfig.CONFIG_FILES.contains(psiFile.name) } val statusBar = WindowManager.getInstance().getStatusBar(project) statusBar?.getWidget(BufCLIWidget.ID) as? BufCLIWidget diff --git a/src/main/kotlin/build/buf/intellij/fixes/IgnoreBufIssueQuickFix.kt b/src/main/kotlin/build/buf/intellij/fixes/IgnoreBufIssueQuickFix.kt index cc1b9ec9..2e16dce7 100644 --- a/src/main/kotlin/build/buf/intellij/fixes/IgnoreBufIssueQuickFix.kt +++ b/src/main/kotlin/build/buf/intellij/fixes/IgnoreBufIssueQuickFix.kt @@ -16,10 +16,10 @@ package build.buf.intellij.fixes import build.buf.intellij.BufBundle import build.buf.intellij.config.BufConfig +import build.buf.intellij.vendor.isProtobufFile import com.intellij.codeInsight.intention.impl.BaseIntentionAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project -import com.intellij.protobuf.lang.psi.PbFile import com.intellij.psi.PsiFile import com.intellij.psi.PsiFileFactory import com.intellij.psi.PsiManager @@ -33,7 +33,7 @@ class IgnoreBufIssueQuickFix(private val type: String) : BaseIntentionAction() { override fun getText(): String = BufBundle.getMessage("buf.quickfix.ignore.issue") - override fun isAvailable(project: Project, editor: Editor, file: PsiFile): Boolean = file is PbFile + override fun isAvailable(project: Project, editor: Editor, file: PsiFile): Boolean = file.isProtobufFile() override fun startInWriteAction(): Boolean = true diff --git a/src/main/kotlin/build/buf/intellij/formatter/BufFormatterService.kt b/src/main/kotlin/build/buf/intellij/formatter/BufFormatterService.kt index a3af0165..bf41309b 100644 --- a/src/main/kotlin/build/buf/intellij/formatter/BufFormatterService.kt +++ b/src/main/kotlin/build/buf/intellij/formatter/BufFormatterService.kt @@ -17,6 +17,7 @@ package build.buf.intellij.formatter import build.buf.intellij.BufBundle import build.buf.intellij.annotator.BufAnalyzeUtils import build.buf.intellij.settings.bufSettings +import build.buf.intellij.vendor.isProtobufFile import com.intellij.codeInsight.actions.ReformatCodeProcessor import com.intellij.formatting.service.AsyncDocumentFormattingService import com.intellij.formatting.service.AsyncFormattingRequest @@ -25,7 +26,6 @@ import com.intellij.openapi.command.CommandProcessor import com.intellij.openapi.roots.ProjectFileIndex import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.VfsUtil -import com.intellij.protobuf.lang.psi.PbFile import com.intellij.psi.PsiFile import com.intellij.psi.formatter.FormatterUtil import kotlinx.coroutines.runBlocking @@ -34,7 +34,7 @@ class BufFormatterService : AsyncDocumentFormattingService() { override fun getFeatures(): Set = emptySet() override fun canFormat(file: PsiFile): Boolean = - file is PbFile && file.project.bufSettings.state.useBufFormatter && getFormattingReason() == FormattingReason.ReformatCode + file.isProtobufFile() && file.project.bufSettings.state.useBufFormatter && getFormattingReason() == FormattingReason.ReformatCode override fun createFormattingTask(request: AsyncFormattingRequest): FormattingTask? { val context = request.context diff --git a/src/main/kotlin/build/buf/intellij/inspections/BufAnalyzeInspection.kt b/src/main/kotlin/build/buf/intellij/inspections/BufAnalyzeInspection.kt index c4d91223..3ed1d9f0 100644 --- a/src/main/kotlin/build/buf/intellij/inspections/BufAnalyzeInspection.kt +++ b/src/main/kotlin/build/buf/intellij/inspections/BufAnalyzeInspection.kt @@ -17,6 +17,7 @@ package build.buf.intellij.inspections import build.buf.intellij.BufBundle import build.buf.intellij.BufPluginService import build.buf.intellij.annotator.* +import build.buf.intellij.vendor.isProtobufFile import com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl import com.intellij.codeInspection.* import com.intellij.lang.annotation.AnnotationSession @@ -25,7 +26,6 @@ import com.intellij.openapi.application.runReadAction import com.intellij.openapi.components.service import com.intellij.openapi.roots.ProjectFileIndex import com.intellij.openapi.util.Disposer -import com.intellij.protobuf.lang.psi.PbFile import com.intellij.psi.PsiFile class BufAnalyzeInspection : GlobalSimpleInspectionTool() { @@ -48,7 +48,7 @@ class BufAnalyzeInspection : GlobalSimpleInspectionTool() { globalContext: GlobalInspectionContext, problemDescriptionsProcessor: ProblemDescriptionsProcessor ) { - if (file !is PbFile) return + if (!file.isProtobufFile()) return val project = manager.project val disposable = project.messageBus.createDisposableOnAnyPsiChange() .also { Disposer.register(appService, it) } diff --git a/src/main/kotlin/build/buf/intellij/inspections/BufNotInstalledInspection.kt b/src/main/kotlin/build/buf/intellij/inspections/BufNotInstalledInspection.kt index 086b743b..f0a308c4 100644 --- a/src/main/kotlin/build/buf/intellij/inspections/BufNotInstalledInspection.kt +++ b/src/main/kotlin/build/buf/intellij/inspections/BufNotInstalledInspection.kt @@ -16,11 +16,11 @@ package build.buf.intellij.inspections import build.buf.intellij.BufBundle import build.buf.intellij.settings.BufCLIUtils +import build.buf.intellij.vendor.isProtobufFile import com.intellij.codeInspection.InspectionManager import com.intellij.codeInspection.LocalInspectionTool import com.intellij.codeInspection.ProblemDescriptor import com.intellij.codeInspection.ProblemHighlightType -import com.intellij.protobuf.lang.psi.PbFile import com.intellij.psi.PsiFile import org.jetbrains.annotations.NotNull @@ -37,7 +37,7 @@ class BufNotInstalledInspection : LocalInspectionTool() { } override fun checkFile(file: PsiFile, manager: InspectionManager, isOnTheFly: Boolean): Array? { - if (file !is PbFile) return null + if (!file.isProtobufFile()) return null val bufExecutable = BufCLIUtils.getConfiguredBufExecutable(file.project) if (bufExecutable != null) return null return arrayOf( diff --git a/src/main/kotlin/build/buf/intellij/vendor/Utils.kt b/src/main/kotlin/build/buf/intellij/vendor/Utils.kt new file mode 100644 index 00000000..ae276c85 --- /dev/null +++ b/src/main/kotlin/build/buf/intellij/vendor/Utils.kt @@ -0,0 +1,60 @@ +// Copyright 2022-2023 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package build.buf.intellij.vendor + +import com.intellij.lang.Language +import com.intellij.psi.PsiFile + +private val officialProtobufFile by lazy { + try { + Class.forName("com.intellij.protobuf.lang.psi.PbFile") + } catch (e: ClassNotFoundException) { + null + } +} + +private val officialProtobufLanguage: Language? by lazy { + try { + val clazz = Class.forName("com.intellij.protobuf.lang.PbLanguage") + clazz.getField("INSTANCE").get(null) as Language + } catch (e: ClassNotFoundException) { + null + } +} + +private val kanroProtobufFile by lazy { + try { + Class.forName("io.kanro.idea.plugin.protobuf.lang.psi.ProtobufFile") + } catch (e: ClassNotFoundException) { + null + } +} + +private val kanroProtobufLanguage: Language? by lazy { + try { + val clazz = Class.forName("io.kanro.idea.plugin.protobuf.lang.ProtobufLanguage") + clazz.kotlin.objectInstance as Language + } catch (e: ClassNotFoundException) { + null + } +} + +fun PsiFile.isProtobufFile(): Boolean { + return ((officialProtobufFile?.isInstance(this) ?: false || kanroProtobufFile?.isInstance(this) ?: false)) +} + +fun protobufLanguage(): Language? { + return officialProtobufLanguage ?: kanroProtobufLanguage +} diff --git a/src/main/kotlin/build/buf/intellij/resolve/BufProtoFileResolver.kt b/src/main/kotlin/build/buf/intellij/vendor/jetbrains/BufProtoFileResolver.kt similarity index 97% rename from src/main/kotlin/build/buf/intellij/resolve/BufProtoFileResolver.kt rename to src/main/kotlin/build/buf/intellij/vendor/jetbrains/BufProtoFileResolver.kt index 4319ca2e..58e321ca 100644 --- a/src/main/kotlin/build/buf/intellij/resolve/BufProtoFileResolver.kt +++ b/src/main/kotlin/build/buf/intellij/vendor/jetbrains/BufProtoFileResolver.kt @@ -12,10 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -package build.buf.intellij.resolve +package build.buf.intellij.vendor.jetbrains import build.buf.intellij.config.BufConfig import build.buf.intellij.index.BufModuleIndex +import build.buf.intellij.resolve.BufRootsProvider import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VfsUtil import com.intellij.openapi.vfs.VirtualFile diff --git a/src/main/kotlin/build/buf/intellij/vendor/kanro/BufProtoFileResolver.kt b/src/main/kotlin/build/buf/intellij/vendor/kanro/BufProtoFileResolver.kt new file mode 100644 index 00000000..d849b745 --- /dev/null +++ b/src/main/kotlin/build/buf/intellij/vendor/kanro/BufProtoFileResolver.kt @@ -0,0 +1,71 @@ +// Copyright 2022-2023 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package build.buf.intellij.vendor.kanro + +import build.buf.intellij.config.BufConfig +import build.buf.intellij.index.BufModuleIndex +import build.buf.intellij.resolve.BufRootsProvider +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.PsiElement +import com.intellij.psi.search.FilenameIndex +import com.intellij.psi.search.GlobalSearchScope +import com.intellij.psi.search.GlobalSearchScopesCore +import com.intellij.psi.search.ProjectScope +import io.kanro.idea.plugin.protobuf.lang.root.ProtobufRoot +import io.kanro.idea.plugin.protobuf.lang.root.ProtobufRootProvider + +class BufProtoRootProvider : ProtobufRootProvider { + override fun id(): String = "bufRoot2" + + override fun roots(context: PsiElement): List { + val project = context.project + val roots = mutableListOf() + for (bufConfig in FilenameIndex.getVirtualFilesByName( + BufConfig.BUF_YAML, ProjectScope.getProjectScope(project) + )) { + val parent = bufConfig.parent ?: continue + roots.add(ProtobufRoot("bufCurrentModule", parent)) + } + for (mod in BufModuleIndex.getAllProjectModules(project)) { + val modName = "${mod.remote}/${mod.owner}/${mod.repository}:${mod.commit}" + val modFolderV2Path = BufRootsProvider.getOrCreateModuleCacheFolderV2(mod) + if (modFolderV2Path != null) { + roots.add(ProtobufRoot(modName, modFolderV2Path)) + continue + } + val modFolder = BufRootsProvider.findModuleCacheFolderV1(mod) ?: continue + roots.add(ProtobufRoot(modName, modFolder)) + } + return roots + } + + override fun searchScope(context: PsiElement): GlobalSearchScope { + val project = context.project + val roots = ArrayList() + for (mod in BufModuleIndex.getAllProjectModules(project)) { + val v2Root = BufRootsProvider.getOrCreateModuleCacheFolderV2(mod) + if (v2Root != null) { + roots.add(v2Root) + continue + } + BufRootsProvider.findModuleCacheFolderV1(mod)?.let { roots.add(it) } + } + return if (roots.isNotEmpty()) { + GlobalSearchScopesCore.directoriesScope(project, true, *roots.toTypedArray()) + } else { + GlobalSearchScope.allScope(project) + } + } +} diff --git a/src/main/resources/META-INF/kanro-protobuf-plugin-support.xml b/src/main/resources/META-INF/kanro-protobuf-plugin-support.xml new file mode 100644 index 00000000..18de99d1 --- /dev/null +++ b/src/main/resources/META-INF/kanro-protobuf-plugin-support.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/META-INF/official-protobuf-plugin-support.xml b/src/main/resources/META-INF/official-protobuf-plugin-support.xml new file mode 100644 index 00000000..3059f222 --- /dev/null +++ b/src/main/resources/META-INF/official-protobuf-plugin-support.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index c5a20c20..a926a342 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -5,8 +5,9 @@ Buf com.intellij.modules.platform - idea.plugin.protoeditor org.jetbrains.plugins.yaml + idea.plugin.protoeditor + io.kanro.idea.plugin.protobuf @@ -40,7 +41,4 @@ - - -