Skip to content

Commit

Permalink
🐛 Fix #118
Browse files Browse the repository at this point in the history
  • Loading branch information
devkanro committed Jul 29, 2022
1 parent ed4b8a8 commit d30ba2c
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 57 deletions.
21 changes: 17 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@

## [Unreleased]

### Fixed

- Fix group extension field decompile error
- Fix group field annotation always fail
- Fix group extension field range check

### Changed

- Make auto-decompile default as disable

## [1.6.21]
### Fixed
- Fix gRPC request require a proxy
- Fix gRPC request with schema

### Added
### Fixed

- Fix gRPC request require a proxy
- Fix gRPC request with schema

### Added

- Support the grpc-status-bin header

## [1.6.20]
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pluginGroup=io.kanro.idea.plugin.protobuf
pluginName=IntelliJ Protobuf Language Plugin
# SemVer format -> https://semver.org
pluginVersion=1.6.21
pluginVersion=1.6.22
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild=222
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,31 @@ object ProtobufDecompiler {
val stack = Stack<Message>()
stack.add(fileDescriptor)

val groups = mutableSetOf<String>()

fileDescriptor.extensionList.forEach {
if (it.type == DescriptorProtos.FieldDescriptorProto.Type.TYPE_GROUP) {
groups += it.typeName.substringAfterLast('.')
}
}

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

fileDescriptor.serviceList.forEach {
generate(this, stack, it)
}

fileDescriptor.messageTypeList.forEach {
if (it.options.mapEntry) return@forEach
if (it.name in groups) return@forEach
generate(this, stack, it)
}

fileDescriptor.enumTypeList.forEach {
generate(this, stack, it)
}

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

Expand Down Expand Up @@ -138,7 +148,7 @@ object ProtobufDecompiler {
}

findGroup(stack, field)?.let {
block("${stack.label(field)}group ${field.name} = ${field.number}") {
block("${stack.label(field)}group ${it.name} = ${field.number}") {
normalizeStatementLn()
generateBlockOption(this, it.options)
normalizeStatementLn()
Expand Down Expand Up @@ -275,16 +285,12 @@ object ProtobufDecompiler {
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 }
val qName = field.typeName.toQualifiedName()
val subName = qName.subQualifiedName(qName.componentCount - groupLevel, qName.componentCount)
var message = stack.parent<DescriptorProtos.DescriptorProto>() ?: return null
for (component in subName.components) {
message = message.nestedTypeList.firstOrNull {
it.name == component
} ?: return null
return stack.parent<DescriptorProtos.DescriptorProto>()?.nestedTypeList?.firstOrNull {
it.name == qName.lastComponent
} ?: stack.parent<DescriptorProtos.FileDescriptorProto>()?.messageTypeList?.firstOrNull {
it.name == qName.lastComponent
}
return message
}

private fun stackWrapper(stack: Stack<Message>, item: Message, block: () -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import java.awt.event.MouseEvent

class GoDecompileLineMarker : LineMarkerProviderDescriptor() {
override fun getName(): String? {
return null
return "Go Decompile"
}

override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? {
Expand All @@ -26,21 +26,19 @@ class GoDecompileLineMarker : LineMarkerProviderDescriptor() {
val type = compositeLit.type as? GoArrayOrSliceType ?: return null
if (!type.type.textMatches("byte")) return null

return ProtobufDecompileLineMarkerInfo(element)
return LineMarkerInfo(
element, element.textRange, ProtobufIcons.PROTO_DECOMPILE,
{
"Decompile protobuf descriptor"
},
ProtobufDecompileNavigationHandler, GutterIconRenderer.Alignment.CENTER,
{
"Decompile descriptor"
}
)
}
}

class ProtobufDecompileLineMarkerInfo(element: GoVarDefinition) : LineMarkerInfo<GoVarDefinition>(
element, element.textRange, ProtobufIcons.PROTO_DECOMPILE,
{
"Decompile protobuf descriptor"
},
ProtobufDecompileNavigationHandler, GutterIconRenderer.Alignment.CENTER,
{
"Decompile descriptor"
}
)

object ProtobufDecompileNavigationHandler : GutterIconNavigationHandler<GoVarDefinition> {
override fun navigate(e: MouseEvent, element: GoVarDefinition) {
val varSpec = element.parent as? GoVarSpec ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ class ProtobufAnnotator : Annotator {
}

private fun visitExtendItem(o: ProtobufElement) {
if (o.parentOfType<ProtobufGroupDefinition>() != null) return
val extendMessage =
o.parentOfType<ProtobufExtendDefinition>()?.typeName?.reference?.resolve() as? ProtobufMessageDefinition
?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface ProtobufGroupDefinition : ProtobufFieldLike, ProtobufNumberScope, Prot
}

override fun name(): String? {
return identifier()?.text?.let { StringUtil.wordsToBeginFromLowerCase(it) }
return identifier()?.text
}

override fun names(): Set<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ class ProtobufSettings : SimplePersistentStateComponent<ProtobufSettings.State>(
@get:XCollection(propertyElementName = "roots", style = XCollection.Style.v2)
var importRoots by list<ImportRootEntry>()

var autoDecompile by property(true)
var autoDecompile by property(false)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d30ba2c

Please sign in to comment.