Skip to content

Commit e76003b

Browse files
authored
Support hover documentation for the enums / enum variants / spec items. 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
1 parent ab8044f commit e76003b

16 files changed

+768
-288
lines changed

src/main/grammars/MoveParser.bnf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,22 @@ SpecFunctionInner ::= Attr* spec fun IDENTIFIER TypeParameterList?
325325
{
326326
pin = 3
327327
elementType = SpecFunction
328+
hooks = [ leftBinder = "ADJACENT_LINE_COMMENTS" ]
328329
}
329330
NativeSpecFunctionInner ::= Attr* spec (native fun) IDENTIFIER TypeParameterList?
330331
FunctionParameterList ReturnType? ';'
331332
{
332333
pin = 3
333334
elementType = SpecFunction
335+
hooks = [ leftBinder = "ADJACENT_LINE_COMMENTS" ]
334336
}
335337

336338
fake SpecInlineFunction ::= Attr* native? fun IDENTIFIER? TypeParameterList?
337339
FunctionParameterList? ReturnType?
338340
(SpecCodeBlock | ';')?
339341
{
340342
implements = [
343+
"org.move.lang.core.psi.MvQualNamedElement"
341344
"org.move.lang.core.psi.MvFunctionLike"
342345
"org.move.lang.core.types.infer.MvInferenceContextOwner"
343346
"org.move.lang.core.psi.ext.MvItemElement"
@@ -350,17 +353,19 @@ fake SpecInlineFunction ::= Attr* native? fun IDENTIFIER? TypeParameterList?
350353
// | NativeSpecInlineFunctionInner
351354
// | UninterpretedSpecInlineFunctionInner
352355

353-
SpecInlineFunctionInner ::= fun IDENTIFIER TypeParameterList?
356+
SpecInlineFunctionInner ::= Attr* fun IDENTIFIER TypeParameterList?
354357
FunctionParameterList ReturnType? (<<msl SpecCodeBlock>> | ';')
355358
{
356-
pin = 1
359+
pin = 2
357360
elementType = SpecInlineFunction
361+
hooks = [ leftBinder = "ADJACENT_LINE_COMMENTS" ]
358362
}
359-
NativeSpecInlineFunctionInner ::= (native fun) IDENTIFIER TypeParameterList?
363+
NativeSpecInlineFunctionInner ::= Attr* (native fun) IDENTIFIER TypeParameterList?
360364
FunctionParameterList ReturnType? ';'
361365
{
366+
pin = 2
362367
elementType = SpecInlineFunction
363-
pin = 1
368+
hooks = [ leftBinder = "ADJACENT_LINE_COMMENTS" ]
364369
}
365370

366371
SpecInlineFunctionStmt ::= SpecInlineFunctionInner
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.move.ide.docs
2+
3+
import com.intellij.lang.documentation.DocumentationSettings
4+
import com.intellij.openapi.editor.colors.EditorColorsManager
5+
import com.intellij.openapi.editor.colors.TextAttributesKey
6+
import com.intellij.openapi.editor.markup.TextAttributes
7+
import com.intellij.openapi.editor.richcopy.HtmlSyntaxInfoUtil
8+
import io.ktor.util.escapeHTML
9+
import org.move.ide.colors.MvColor
10+
11+
@Suppress("UnstableApiUsage")
12+
object MvColorUtils {
13+
14+
val asKeyword get() = loadKey(MvColor.KEYWORD)
15+
val asFunction get() = loadKey(MvColor.FUNCTION)
16+
val asStruct get() = loadKey(MvColor.STRUCT)
17+
val asField get() = loadKey(MvColor.FIELD)
18+
val asEnum get() = loadKey(MvColor.ENUM)
19+
val asEnumVariant get() = loadKey(MvColor.ENUM_VARIANT)
20+
val asConst get() = loadKey(MvColor.CONSTANT)
21+
val asTypeParam get() = loadKey(MvColor.TYPE_PARAMETER)
22+
val asAbility get() = loadKey(MvColor.ABILITY)
23+
24+
val asPrimitiveType get() = loadKey(MvColor.PRIMITIVE_TYPE)
25+
val asBuiltinType get() = loadKey(MvColor.BUILTIN_TYPE)
26+
val asStructType get() = loadKey(MvColor.STRUCT)
27+
val asEnumType get() = loadKey(MvColor.ENUM)
28+
val asEnumVariantType get() = loadKey(MvColor.ENUM_VARIANT)
29+
30+
val asBraces get() = loadKey(MvColor.BRACES)
31+
val asBrackets get() = loadKey(MvColor.BRACKETS)
32+
val asParens get() = loadKey(MvColor.PARENTHESES)
33+
val asComma get() = loadKey(MvColor.COMMA)
34+
val asSemicolon get() = loadKey(MvColor.SEMICOLON)
35+
val asOperator get() = loadKey(MvColor.OPERATORS)
36+
37+
fun StringBuilder.keyword(text: String) = colored(text, asKeyword)
38+
fun StringBuilder.op(text: String) = colored(text, asOperator)
39+
fun StringBuilder.comma() = colored(",", asComma)
40+
fun StringBuilder.semicolon() = colored(";", asSemicolon)
41+
42+
fun StringBuilder.colored(text: String?, color: TextAttributes, noHtml: Boolean = false) {
43+
if (noHtml) {
44+
append(text)
45+
return
46+
}
47+
HtmlSyntaxInfoUtil.appendStyledSpan(
48+
this, color, text?.escapeHTML() ?: "",
49+
DocumentationSettings.getHighlightingSaturation(false)
50+
)
51+
}
52+
53+
private fun loadKey(color: MvColor): TextAttributes = loadKey(color.textAttributesKey)
54+
55+
private fun loadKey(key: TextAttributesKey): TextAttributes =
56+
EditorColorsManager.getInstance().globalScheme.getAttributes(key)!!
57+
}

0 commit comments

Comments
 (0)