Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation improvements #250

Merged
merged 6 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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