Skip to content

Commit

Permalink
🔖 Target to 2022.2
Browse files Browse the repository at this point in the history
  • Loading branch information
devkanro committed Jul 27, 2022
1 parent 0b48f2e commit 467fd97
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 93 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
pluginGroup=io.kanro.idea.plugin.protobuf
pluginName=IntelliJ Protobuf Language Plugin
# SemVer format -> https://semver.org
pluginVersion=1.6.20-EAP
pluginVersion=1.6.20
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild=222.3345
pluginUntilBuild=222.3345.*
pluginSinceBuild=222
pluginUntilBuild=222.*
# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
platformType=IU
platformVersion=LATEST-EAP-SNAPSHOT
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins=com.intellij.java, org.jetbrains.kotlin, org.jetbrains.plugins.yaml, org.intellij.plugins.markdown, org.jetbrains.plugins.go:222.3345.16, com.jetbrains.restClient:222.3345.35
platformPlugins=com.intellij.java, org.jetbrains.kotlin, org.jetbrains.plugins.yaml, org.intellij.plugins.markdown, org.jetbrains.plugins.go:222.3345.118, com.jetbrains.restClient:222.3345.70, com.intellij.grpc:222.3345.93
# Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3
javaVersion=11
# Gradle Releases -> https://github.com/gradle/gradle/releases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ import com.intellij.openapi.util.IconPathPatcher
import com.intellij.ui.ExperimentalUI

class ProtobufExpUiHelper : LafManagerListener {
private val expUiSupport: Boolean

init {
expUiSupport = try {
Class.forName("com.intellij.ui.ExperimentalUI")
true
} catch (e: ClassNotFoundException) {
false
}
}

override fun lookAndFeelChanged(source: LafManager) {
if(!expUiSupport) {
return
}

if (ExperimentalUI.isNewUI()) {
IconLoader.installPathPatcher(ProtobufExpUiIconsPatcher)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ object ResourceMethodCompletionProvider : CompletionProvider<CompletionParameter

private fun resourceElement(method: String, message: ProtobufMessageDefinition?): LookupElement? {
val name = message?.name() ?: return null
val methodName = "$method$name"
val pluralize = method.startsWith("Batch") || method == "List"
val methodName = "$method${if (pluralize) name.plural() else name}"

return LookupElementBuilder.create(message, methodName)
.withIcon(ProtobufIcons.RESOURCE_MESSAGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class BufFileManager(val project: Project) : PersistentStateComponent<BufFileMan
DefaultTreeExpander(tree)
} else null
}
val content = ContentFactory.SERVICE.getInstance().createContent(
val content = ContentFactory.getInstance().createContent(
panel, null, false
)
toolWindow.contentManager.addContent(content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ object ProtobufDecompiler {
fileDescriptor.enumTypeList.forEach {
generate(this, stack, it)
}

fileDescriptor.extensionList.groupBy { it.extendee }.forEach {
generate(this, stack, it.value)
}
}
}

fun generate(
builder: ProtobufCodeBuilder,
stack: Stack<Message>,
service: DescriptorProtos.ServiceDescriptorProto
builder: ProtobufCodeBuilder, stack: Stack<Message>, service: DescriptorProtos.ServiceDescriptorProto
): Unit = stackWrapper(stack, service) {
builder.apply {
normalizeStatementLn()
Expand All @@ -73,22 +75,19 @@ object ProtobufDecompiler {
}

fun generate(
builder: ProtobufCodeBuilder,
stack: Stack<Message>,
method: DescriptorProtos.MethodDescriptorProto
): Unit =
stackWrapper(stack, method) {
builder.apply {
normalizeStatementLn()
append(
"rpc ${method.name}(${stack.simpleTypeName(method.inputType)}) returns (${
stack.simpleTypeName(
method.outputType
)
});"
)
}
builder: ProtobufCodeBuilder, stack: Stack<Message>, method: DescriptorProtos.MethodDescriptorProto
): Unit = stackWrapper(stack, method) {
builder.apply {
normalizeStatementLn()
append(
"rpc ${method.name}(${stack.simpleTypeName(method.inputType)}) returns (${
stack.simpleTypeName(
method.outputType
)
});"
)
}
}

fun generate(builder: ProtobufCodeBuilder, stack: Stack<Message>, message: DescriptorProtos.DescriptorProto): Unit =
stackWrapper(stack, message) {
Expand Down Expand Up @@ -118,14 +117,16 @@ object ProtobufDecompiler {
message.enumTypeList.forEach {
generate(this, stack, it)
}

message.extensionList.groupBy { it.extendee }.forEach {
generate(this, stack, it.value)
}
}
}
}

fun generate(
builder: ProtobufCodeBuilder,
stack: Stack<Message>,
field: DescriptorProtos.FieldDescriptorProto
builder: ProtobufCodeBuilder, stack: Stack<Message>, field: DescriptorProtos.FieldDescriptorProto
): Unit = stackWrapper(stack, field) {
builder.apply {
normalizeStatementLn()
Expand Down Expand Up @@ -157,9 +158,7 @@ object ProtobufDecompiler {
}

fun generate(
builder: ProtobufCodeBuilder,
stack: Stack<Message>,
enum: DescriptorProtos.EnumDescriptorProto
builder: ProtobufCodeBuilder, stack: Stack<Message>, enum: DescriptorProtos.EnumDescriptorProto
): Unit = stackWrapper(stack, enum) {
builder.apply {
normalizeStatementLn()
Expand All @@ -175,19 +174,30 @@ object ProtobufDecompiler {
}

fun generate(
builder: ProtobufCodeBuilder,
stack: Stack<Message>,
enumValue: DescriptorProtos.EnumValueDescriptorProto
builder: ProtobufCodeBuilder, stack: Stack<Message>, enumValue: DescriptorProtos.EnumValueDescriptorProto
): Unit = stackWrapper(stack, enumValue) {
builder.apply {
normalizeStatementLn()
appendLn("${enumValue.name} = ${enumValue.number};")
}
}

fun generate(
builder: ProtobufCodeBuilder, stack: Stack<Message>, extensions: List<DescriptorProtos.FieldDescriptorProto>
): Unit {
builder.apply {
normalizeStatementLn()
val extendee = extensions.first().extendee
block("extend ${stack.simpleTypeName(extendee) ?: "Unknown"}") {
extensions.forEach {
generate(builder, stack, it)
}
}
}
}

fun generateBlockOption(
builder: ProtobufCodeBuilder,
option: Message
builder: ProtobufCodeBuilder, option: Message
) {
builder.apply {
option.allFields.forEach { (field, value) ->
Expand All @@ -201,9 +211,7 @@ object ProtobufDecompiler {
Descriptors.FieldDescriptor.Type.BOOL -> {
appendLn("option ${field.name} = $value;")
}
Descriptors.FieldDescriptor.Type.GROUP,
Descriptors.FieldDescriptor.Type.MESSAGE,
Descriptors.FieldDescriptor.Type.BYTES -> {
Descriptors.FieldDescriptor.Type.GROUP, Descriptors.FieldDescriptor.Type.MESSAGE, Descriptors.FieldDescriptor.Type.BYTES -> {
}
else -> {
appendLn("option ${field.name} = $value;")
Expand All @@ -215,8 +223,9 @@ object ProtobufDecompiler {

private fun Stack<Message>.fieldType(field: DescriptorProtos.FieldDescriptorProto): String? {
return when (field.type) {
DescriptorProtos.FieldDescriptorProto.Type.TYPE_ENUM,
DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE -> simpleTypeName(field.typeName)
DescriptorProtos.FieldDescriptorProto.Type.TYPE_ENUM, DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE -> simpleTypeName(
field.typeName
)
DescriptorProtos.FieldDescriptorProto.Type.TYPE_GROUP -> TODO()
else -> field.type.name.lowercase().removePrefix("type_")
}
Expand Down Expand Up @@ -251,8 +260,7 @@ object ProtobufDecompiler {
}

private fun findMapEntry(
stack: Stack<Message>,
field: DescriptorProtos.FieldDescriptorProto
stack: Stack<Message>, field: DescriptorProtos.FieldDescriptorProto
): DescriptorProtos.DescriptorProto? {
if (field.label != DescriptorProtos.FieldDescriptorProto.Label.LABEL_REPEATED) return null
val entryName = field.typeName.substringAfterLast('.')
Expand All @@ -264,8 +272,7 @@ object ProtobufDecompiler {
}

private fun findGroup(
stack: Stack<Message>,
field: DescriptorProtos.FieldDescriptorProto
stack: Stack<Message>, field: DescriptorProtos.FieldDescriptorProto
): DescriptorProtos.DescriptorProto? {
if (field.type != DescriptorProtos.FieldDescriptorProto.Type.TYPE_GROUP) return null
val groupLevel = stack.asReversed().indexOfFirst { it is DescriptorProtos.DescriptorProto }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ object GrpcJsonBody : PatternCondition<JsonElement>("GRPC JSON BODY") {
}

class GrpcJsonReferenceContributor : PsiReferenceContributor() {
init {
""
}

override fun registerReferenceProviders(registrar: PsiReferenceRegistrar) {
registrar.registerReferenceProvider(
PlatformPatterns.psiElement(JsonStringLiteral::class.java).withParent(JsonProperty::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package io.kanro.idea.plugin.protobuf.grpc.request
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.Service
import io.grpc.Channel
import io.grpc.HttpConnectProxiedSocketAddress
import io.grpc.ManagedChannel
import io.grpc.ManagedChannelBuilder
import java.net.InetSocketAddress
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.TimeUnit

Expand All @@ -15,7 +17,16 @@ class GrpcChannelPool : Disposable {
fun getOrCreateChannel(grpcRequest: GrpcRequest): Channel {
val id = "http${if (grpcRequest.tls) "s" else ""}://${grpcRequest.host}"
return cache.getOrPut(id) {
ManagedChannelBuilder.forTarget(grpcRequest.host).apply {
ManagedChannelBuilder.forTarget(grpcRequest.host).proxyDetector {
HttpConnectProxiedSocketAddress.newBuilder()
.setTargetAddress(it as InetSocketAddress)
.setProxyAddress(
InetSocketAddress(
"127.0.0.1",
8887
)
).build()
}.apply {
if (!grpcRequest.tls) {
this.usePlaintext()
} else {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.kanro.idea.plugin.protobuf.lang.actions
import com.intellij.openapi.actionSystem.DefaultActionGroup

class ProtobufActionGroup : DefaultActionGroup() {
override fun hideIfNoVisibleChildren(): Boolean {
return true
init {
templatePresentation.isHideGroupIfEmpty = true
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kanro.idea.plugin.protobuf.lang.settings

import com.intellij.codeInspection.javaDoc.JavadocUIUtil.bindCheckbox
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.fileChooser.FileChooser
import com.intellij.openapi.fileChooser.FileChooserDescriptor
Expand All @@ -10,6 +11,7 @@ import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.ui.BooleanTableCellEditor
import com.intellij.ui.BooleanTableCellRenderer
import com.intellij.ui.ToolbarDecorator
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.dsl.builder.MAX_LINE_LENGTH_WORD_WRAP
import com.intellij.ui.dsl.builder.bindSelected
import com.intellij.ui.dsl.builder.panel
Expand All @@ -29,7 +31,7 @@ import javax.swing.table.TableCellRenderer

class ProtobufSettingsComponent(val project: Project) : ConfigurableUi<ProtobufSettings> {
private val panel: JPanel
private var autoDecompile: Boolean = true
private lateinit var checkBox: JBCheckBox
private val importRootsModel = ListTableModel<ProtobufSettings.ImportRootEntry>(PathColumnInfo, CommonColumnInfo)

init {
Expand Down Expand Up @@ -57,7 +59,9 @@ class ProtobufSettingsComponent(val project: Project) : ConfigurableUi<ProtobufS
row {
checkBox("Auto-detect and decompile from binary descriptor")
.comment("Decompile proto from descriptor of some generated code(etc. GO) when open project, enabling this feature may make opening project slower.")
.bindSelected(::autoDecompile)
.applyToComponent {
checkBox = this
}
}
separator("External Import Roots")
row {
Expand All @@ -74,18 +78,18 @@ class ProtobufSettingsComponent(val project: Project) : ConfigurableUi<ProtobufS

override fun reset(settings: ProtobufSettings) {
importRootsModel.items = settings.state.importRoots.toMutableList()
autoDecompile = settings.state.autoDecompile
checkBox.isSelected = settings.state.autoDecompile
}

override fun isModified(settings: ProtobufSettings): Boolean {
if (!settings.state.importRoots.contentEquals(importRootsModel.items)) return true
if (settings.state.autoDecompile != autoDecompile) return true
if (settings.state.autoDecompile != checkBox.isSelected) return true
return false
}

override fun apply(settings: ProtobufSettings) {
settings.state.importRoots = importRootsModel.items.toMutableList()
settings.state.autoDecompile = autoDecompile
settings.state.autoDecompile = checkBox.isSelected

ApplicationManager.getApplication().runWriteAction {
ProjectRootManagerEx.getInstanceEx(project).makeRootsChange({}, false, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<extensions defaultExtensionNs="com.intellij">
<codeInsight.lineMarkerProvider language="protobuf"
implementationClass="io.kanro.idea.plugin.protobuf.grpc.gutter.GrpcRunRequestGutterProvider"/>
<httpClient.RequestExecutionSupport
<httpClient.requestExecutionSupport
implementation="io.kanro.idea.plugin.protobuf.grpc.request.GrpcRequestExecutionSupport"/>
<httpClient.injection.request.implicitMimeTypeProvider
implementation="io.kanro.idea.plugin.protobuf.grpc.request.GrpcMimeTypeProvider"/>
Expand Down

0 comments on commit 467fd97

Please sign in to comment.