Skip to content

Commit

Permalink
Support hover documentation for the enums / enum variants / spec item…
Browse files Browse the repository at this point in the history
…s. Add highlighting to the documentation. (#250)

* separate markdown docs tests

* add docs for missing module items, coloring for the documentation

* highlight const initializer

* bug with abilities highlighting

* parameter / value parameter / type parameter docs is monospaced

* docs for schema
  • Loading branch information
mkurnikov authored Nov 23, 2024
1 parent ab8044f commit e76003b
Show file tree
Hide file tree
Showing 16 changed files with 768 additions and 288 deletions.
13 changes: 9 additions & 4 deletions src/main/grammars/MoveParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -325,19 +325,22 @@ SpecFunctionInner ::= Attr* spec fun IDENTIFIER TypeParameterList?
{
pin = 3
elementType = SpecFunction
hooks = [ leftBinder = "ADJACENT_LINE_COMMENTS" ]
}
NativeSpecFunctionInner ::= Attr* spec (native fun) IDENTIFIER TypeParameterList?
FunctionParameterList ReturnType? ';'
{
pin = 3
elementType = SpecFunction
hooks = [ leftBinder = "ADJACENT_LINE_COMMENTS" ]
}

fake SpecInlineFunction ::= Attr* native? fun IDENTIFIER? TypeParameterList?
FunctionParameterList? ReturnType?
(SpecCodeBlock | ';')?
{
implements = [
"org.move.lang.core.psi.MvQualNamedElement"
"org.move.lang.core.psi.MvFunctionLike"
"org.move.lang.core.types.infer.MvInferenceContextOwner"
"org.move.lang.core.psi.ext.MvItemElement"
Expand All @@ -350,17 +353,19 @@ fake SpecInlineFunction ::= Attr* native? fun IDENTIFIER? TypeParameterList?
// | NativeSpecInlineFunctionInner
// | UninterpretedSpecInlineFunctionInner

SpecInlineFunctionInner ::= fun IDENTIFIER TypeParameterList?
SpecInlineFunctionInner ::= Attr* fun IDENTIFIER TypeParameterList?
FunctionParameterList ReturnType? (<<msl SpecCodeBlock>> | ';')
{
pin = 1
pin = 2
elementType = SpecInlineFunction
hooks = [ leftBinder = "ADJACENT_LINE_COMMENTS" ]
}
NativeSpecInlineFunctionInner ::= (native fun) IDENTIFIER TypeParameterList?
NativeSpecInlineFunctionInner ::= Attr* (native fun) IDENTIFIER TypeParameterList?
FunctionParameterList ReturnType? ';'
{
pin = 2
elementType = SpecInlineFunction
pin = 1
hooks = [ leftBinder = "ADJACENT_LINE_COMMENTS" ]
}

SpecInlineFunctionStmt ::= SpecInlineFunctionInner
Expand Down
57 changes: 57 additions & 0 deletions src/main/kotlin/org/move/ide/docs/MvColorUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.move.ide.docs

import com.intellij.lang.documentation.DocumentationSettings
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.openapi.editor.richcopy.HtmlSyntaxInfoUtil
import io.ktor.util.escapeHTML
import org.move.ide.colors.MvColor

@Suppress("UnstableApiUsage")
object MvColorUtils {

val asKeyword get() = loadKey(MvColor.KEYWORD)
val asFunction get() = loadKey(MvColor.FUNCTION)
val asStruct get() = loadKey(MvColor.STRUCT)
val asField get() = loadKey(MvColor.FIELD)
val asEnum get() = loadKey(MvColor.ENUM)
val asEnumVariant get() = loadKey(MvColor.ENUM_VARIANT)
val asConst get() = loadKey(MvColor.CONSTANT)
val asTypeParam get() = loadKey(MvColor.TYPE_PARAMETER)
val asAbility get() = loadKey(MvColor.ABILITY)

val asPrimitiveType get() = loadKey(MvColor.PRIMITIVE_TYPE)
val asBuiltinType get() = loadKey(MvColor.BUILTIN_TYPE)
val asStructType get() = loadKey(MvColor.STRUCT)
val asEnumType get() = loadKey(MvColor.ENUM)
val asEnumVariantType get() = loadKey(MvColor.ENUM_VARIANT)

val asBraces get() = loadKey(MvColor.BRACES)
val asBrackets get() = loadKey(MvColor.BRACKETS)
val asParens get() = loadKey(MvColor.PARENTHESES)
val asComma get() = loadKey(MvColor.COMMA)
val asSemicolon get() = loadKey(MvColor.SEMICOLON)
val asOperator get() = loadKey(MvColor.OPERATORS)

fun StringBuilder.keyword(text: String) = colored(text, asKeyword)
fun StringBuilder.op(text: String) = colored(text, asOperator)
fun StringBuilder.comma() = colored(",", asComma)
fun StringBuilder.semicolon() = colored(";", asSemicolon)

fun StringBuilder.colored(text: String?, color: TextAttributes, noHtml: Boolean = false) {
if (noHtml) {
append(text)
return
}
HtmlSyntaxInfoUtil.appendStyledSpan(
this, color, text?.escapeHTML() ?: "",
DocumentationSettings.getHighlightingSaturation(false)
)
}

private fun loadKey(color: MvColor): TextAttributes = loadKey(color.textAttributesKey)

private fun loadKey(key: TextAttributesKey): TextAttributes =
EditorColorsManager.getInstance().globalScheme.getAttributes(key)!!
}
Loading

0 comments on commit e76003b

Please sign in to comment.