annotation highlighting
This commit is contained in:
1 parent
d285335e1c
commit
834f3118c8
9 files changed
+87
-14
No files matched your search
@@ -243,6 +243,21 @@ class LyngExternalAnnotator : ExternalAnnotator<LyngExternalAnnotator.Input, Lyn
|
||||
if (e is com.intellij.openapi.progress.ProcessCanceledException) throw e
|
||||
}
|
||||
|
||||
// Add annotation coloring using token highlighter (treat @Label as annotation)
|
||||
run {
|
||||
val tokens = try { SimpleLyngHighlighter().highlight(text) } catch (_: Throwable) { emptyList() }
|
||||
for (s in tokens) if (s.kind == HighlightKind.Label) {
|
||||
val start = s.range.start
|
||||
val end = s.range.endExclusive
|
||||
if (start in 0..end && end <= text.length && start < end) {
|
||||
val lexeme = try { text.substring(start, end) } catch (_: Throwable) { null }
|
||||
if (lexeme != null && lexeme.startsWith("@")) {
|
||||
putRange(start, end, LyngHighlighterColors.ANNOTATION)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build spell index payload: identifiers from symbols + references; comments/strings from simple highlighter
|
||||
val idRanges = mutableSetOf<IntRange>()
|
||||
try {
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.intellij.psi.codeStyle.CodeStyleManager
|
||||
import net.sergeych.lyng.format.LyngFormatConfig
|
||||
import net.sergeych.lyng.format.LyngFormatter
|
||||
import net.sergeych.lyng.idea.LyngLanguage
|
||||
import net.sergeych.lyng.idea.settings.LyngFormatterSettings
|
||||
|
||||
class LyngEnterHandler : EnterHandlerDelegate {
|
||||
private val log = Logger.getInstance(LyngEnterHandler::class.java)
|
||||
@@ -82,11 +81,9 @@ class LyngEnterHandler : EnterHandlerDelegate {
|
||||
// consider only code part before // comment
|
||||
val code = trimmed.substringBefore("//").trim()
|
||||
if (code == "}") {
|
||||
// Optionally reindent the enclosed block without manually touching the '}' line.
|
||||
val settings = LyngFormatterSettings.getInstance(project)
|
||||
if (settings.reindentClosedBlockOnEnter) {
|
||||
reindentClosedBlockAroundBrace(project, file, doc, prevLine)
|
||||
}
|
||||
// Previously we reindented the enclosed block on Enter after a lone '}'.
|
||||
// Per new behavior, this action is now bound to typing '}' instead.
|
||||
// Keep Enter flow limited to indenting the new line only.
|
||||
}
|
||||
}
|
||||
// Adjust indent for the current (new) line
|
||||
|
||||
@@ -57,6 +57,7 @@ class LyngColorSettingsPage : ColorSettingsPage {
|
||||
AttributesDescriptor("Identifier", LyngHighlighterColors.IDENTIFIER),
|
||||
AttributesDescriptor("Punctuation", LyngHighlighterColors.PUNCT),
|
||||
// Semantic
|
||||
AttributesDescriptor("Annotation (semantic)", LyngHighlighterColors.ANNOTATION),
|
||||
AttributesDescriptor("Variable (semantic)", LyngHighlighterColors.VARIABLE),
|
||||
AttributesDescriptor("Value (semantic)", LyngHighlighterColors.VALUE),
|
||||
AttributesDescriptor("Function (semantic)", LyngHighlighterColors.FUNCTION),
|
||||
|
||||
@@ -72,4 +72,9 @@ object LyngHighlighterColors {
|
||||
val PARAMETER: TextAttributesKey = TextAttributesKey.createTextAttributesKey(
|
||||
"LYNG_PARAMETER", DefaultLanguageHighlighterColors.PARAMETER
|
||||
)
|
||||
|
||||
// Annotations (@Something) — use Kotlin/Java metadata default color
|
||||
val ANNOTATION: TextAttributesKey = TextAttributesKey.createTextAttributesKey(
|
||||
"LYNG_ANNOTATION", DefaultLanguageHighlighterColors.METADATA
|
||||
)
|
||||
}
|
||||
@@ -81,6 +81,9 @@
|
||||
<!-- Smart Enter handler -->
|
||||
<enterHandlerDelegate implementation="net.sergeych.lyng.idea.editor.LyngEnterHandler"/>
|
||||
|
||||
<!-- Trigger reindent of enclosed block when typing a standalone '}' -->
|
||||
<typedHandler implementation="net.sergeych.lyng.idea.editor.LyngTypedHandler"/>
|
||||
|
||||
<!-- Smart Backspace handler (deferred) -->
|
||||
<!-- <backspaceHandlerDelegate implementation="net.sergeych.lyng.idea.editor.LyngBackspaceHandler"/> -->
|
||||
|
||||
|
||||
Reference in new issue
Block a user