generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix message show details on mouse hover (#24)
* Fix message show details on mouse hover * fix pipeline * fix some qodana issues --------- Co-authored-by: Dan Timofte <dantimofte@proton.me>
- Loading branch information
1 parent
bf57a4c
commit eef9822
Showing
17 changed files
with
24,353 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/ac/quant/quickfixspec/common/FixDataDictionaryService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ac.quant.quickfixspec.common | ||
|
||
import com.intellij.lang.xml.XMLLanguage | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.components.Service | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.psi.PsiFileFactory | ||
import com.intellij.psi.xml.XmlFile | ||
import java.net.URL | ||
|
||
@Service(Service. Level. PROJECT) | ||
class FixDataDictionaryService(private val project: Project) { | ||
|
||
private var fields: FixFields? = null | ||
|
||
init { | ||
loadFixSpecs() | ||
} | ||
|
||
private fun loadFixSpecs() { | ||
val filePath: URL? = this::class.java.getResource("/spec/FIX44.xml") | ||
|
||
val fixSpecs : PsiFile? = PsiFileFactory.getInstance(project).createFileFromText( | ||
"FIX40.xml", | ||
XMLLanguage.INSTANCE, | ||
filePath!!.readText() | ||
) | ||
|
||
fields = getFields(fixSpecs as XmlFile) | ||
} | ||
|
||
private fun getFields(file: XmlFile): FixFields { | ||
val fieldsTag = file.rootTag?.findFirstSubTag("fields") | ||
return FixFields(fieldsTag!!) | ||
} | ||
|
||
fun getTagName(tag: String): String { | ||
return fields?.getTagName(tag) ?: "" | ||
} | ||
|
||
fun getTagValueDefinition(tag: String, value: String): String { | ||
return fields?.getTagValueDefinition(tag, value) ?: "" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package ac.quant.quickfixspec.common | ||
|
||
import com.intellij.psi.xml.XmlTag | ||
import lombok.Getter | ||
|
||
@Getter | ||
class FixField(tag: XmlTag) { | ||
val name: String = parseName(tag) | ||
val number: String = parseNumber(tag) | ||
val fixType: String = parseFixType(tag) | ||
val values: Map<String, String> = parseValues(tag) | ||
|
||
|
||
private fun parseName(tag: XmlTag): String { | ||
return getAttributeValue(tag, "name") | ||
} | ||
|
||
private fun parseNumber(tag: XmlTag): String { | ||
return getAttributeValue(tag, "number") | ||
} | ||
|
||
private fun parseFixType(tag: XmlTag): String { | ||
return getAttributeValue(tag, "type") | ||
} | ||
|
||
private fun parseValues(tag: XmlTag): Map<String, String> { | ||
val valueTags = tag.findSubTags("value") | ||
val valueTagsDict = mutableMapOf<String, String>() | ||
for (valueTag in valueTags) { | ||
try { | ||
val enumValue = getAttributeValue(valueTag, "enum") | ||
val description = getAttributeValue(valueTag, "description") | ||
valueTagsDict[enumValue] = description | ||
} catch (e: Exception) { | ||
println("Error processing value tags. Error: ${e.message}") | ||
} | ||
} | ||
return valueTagsDict | ||
} | ||
|
||
private fun getAttributeValue(tag: XmlTag, attributeName: String): String { | ||
return tag.getAttribute(attributeName)?.value ?: "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ac.quant.quickfixspec.common | ||
|
||
import com.intellij.psi.xml.XmlTag | ||
|
||
class FixFields(fieldsTag: XmlTag) { | ||
private val fieldsByNum: Map<String, FixField> | ||
private val fieldsByName: Map<String, FixField> | ||
|
||
init { | ||
val result = getFields(fieldsTag) | ||
fieldsByNum = result[0] | ||
fieldsByName = result[1] | ||
} | ||
|
||
private fun getFields(fieldsTag: XmlTag): List<MutableMap<String, FixField>> { | ||
val mutableNum = mutableMapOf<String, FixField>() | ||
val mutableName = mutableMapOf<String, FixField>() | ||
try { | ||
for (field in fieldsTag.subTags) { | ||
val fixField = FixField(field) | ||
mutableNum[fixField.number] = fixField | ||
mutableName[fixField.name] = fixField | ||
} | ||
} catch (e: Exception) { | ||
println("Error processing fields. Error: ${e.message}") | ||
} | ||
return listOf(mutableNum, mutableName) | ||
} | ||
|
||
fun getTagName(tagNumber: String): String { | ||
return fieldsByNum[tagNumber]?.name ?: "" | ||
} | ||
|
||
fun getTagValueDefinition(tag: String, value: String): String { | ||
return fieldsByNum[tag]?.values?.get(value) ?: "" | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/kotlin/ac/quant/quickfixspec/documentation/FixMessageDocumentationTarget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ac.quant.quickfixspec.documentation | ||
import ac.quant.quickfixspec.common.FixDataDictionaryService | ||
import com.intellij.model.Pointer | ||
import com.intellij.platform.backend.documentation.DocumentationResult | ||
import com.intellij.platform.backend.documentation.DocumentationTarget | ||
import com.intellij.platform.backend.presentation.TargetPresentation | ||
|
||
@Suppress("UnstableApiUsage") | ||
class FixMessageDocumentationTarget( | ||
private val fixMessage: String, | ||
private val fixDelimiter: String, | ||
private val fixDataDictionaryService: FixDataDictionaryService, | ||
) : DocumentationTarget { | ||
|
||
|
||
override fun createPointer(): Pointer<out DocumentationTarget> { | ||
return Pointer.hardPointer(this) | ||
} | ||
|
||
override fun computePresentation(): TargetPresentation { | ||
return TargetPresentation.builder(fixMessage).presentation() | ||
} | ||
|
||
override fun computeDocumentationHint(): String { | ||
val docHint = computeDocumentation().toString() | ||
return docHint | ||
} | ||
|
||
override fun computeDocumentation(): DocumentationResult { | ||
val componentDetails = getMessageDetails() | ||
return DocumentationResult.documentation(componentDetails) | ||
} | ||
|
||
private fun getMessageDetails(): String { | ||
// split the message by the delimiter | ||
val messageParts = fixMessage.split(fixDelimiter) | ||
// build new string with the tag equals name on each line without the last index | ||
|
||
val formattedMessage = messageParts.subList(0, messageParts.size - 1).joinToString("\n") { | ||
val tagNumber = it.substringBefore("=") | ||
val tagValue = it.substringAfter("=") | ||
val tagName = fixDataDictionaryService.getTagName(tagNumber) | ||
val tagValueDefinition = fixDataDictionaryService.getTagValueDefinition(tagNumber, tagValue) | ||
"<tr><td>$tagNumber</td><td>$tagName</td><td>$tagValue</td><td>$tagValueDefinition</td></tr>" | ||
} | ||
|
||
val displayText = "<html><head><style> table { width: 100%; } td, th { border-bottom: 1px solid; text-align: left; padding: 1px; } </style></head><body><table>$formattedMessage</table></html>" | ||
|
||
return displayText | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.