Skip to content

Commit

Permalink
Highlighting for attributes (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
jansorg authored Mar 8, 2021
1 parent d446dc4 commit 4ad870f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added: Support folding for CUE elements (file header, imports, import groups, structs, lists, interpolations, multiline strings, attributes).
- Added: Settings to control the default folding state of CUE elements.
- Fix [#27](https://github.com/nexantic/intellij-cue/issues/27), file starting with attribute raised as invalid
- Added: Highlighting setting for attributes.

## [0.5.0]
- Support variable escape prefix of the language specification.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.psi.PsiElement;
import dev.monogon.cue.lang.highlighter.CueHighlightingColors;
import dev.monogon.cue.lang.psi.CueAttribute;
import dev.monogon.cue.lang.psi.CueLabelName;
import org.jetbrains.annotations.NotNull;

public class CueAnnotator implements Annotator {
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
if (element instanceof CueLabelName && ((CueLabelName)element).getSimpleStringLit() == null) {
CueLabelName label = (CueLabelName)element;
var label = (CueLabelName)element;
if (label.isOptionalFieldName()) {
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
.textAttributes(CueHighlightingColors.FIELD_NAME_OPTIONAL)
Expand All @@ -24,5 +25,11 @@ public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder hold
.create();
}
}
else if (element instanceof CueAttribute) {
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
.range(((CueAttribute)element).getAttributeNameElement())
.textAttributes(CueHighlightingColors.ATTRIBUTE_NAME)
.create();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class CueColorSettingsPage implements ColorSettingsPage {
new AttributesDescriptor(lazyMessage("colorSettings.identifier"), IDENTIFIER),
new AttributesDescriptor(lazyMessage("colorSettings.identifier_predeclared"), IDENTIFIER_PREDECLARED),
new AttributesDescriptor(lazyMessage("colorSettings.keyword"), KEYWORD),
new AttributesDescriptor(lazyMessage("colorSettings.attributeName"), ATTRIBUTE_NAME),

new AttributesDescriptor(lazyMessage("colorSettings.literals.bool"), BOOL_LITERAL),
new AttributesDescriptor(lazyMessage("colorSettings.literals.float"), FLOAT_LITERAL),
Expand Down Expand Up @@ -57,6 +58,7 @@ public class CueColorSettingsPage implements ColorSettingsPage {
static {
ADDITIONAL_DESCRIPTORS.put("field", FIELD_NAME);
ADDITIONAL_DESCRIPTORS.put("field_optional", FIELD_NAME_OPTIONAL);
ADDITIONAL_DESCRIPTORS.put("attr", ATTRIBUTE_NAME);
}

@Override
Expand Down Expand Up @@ -92,7 +94,9 @@ public class CueColorSettingsPage implements ColorSettingsPage {
@Override
public @NonNls
@NotNull String getDemoText() {
return "// Release notes:\n" +
return "@<attr>type</attr>(demo)\n" +
"@<attr>if</attr>(this)\n" +
"// Release notes:\n" +
"// - You can now specify your age and your hobby!\n" +
"#V1: {\n" +
" <field>age</field>: >=0 & <=100\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ public interface CueHighlightingColors {
// annotator highlighting, used in CueAnnotator
TextAttributesKey FIELD_NAME = createTextAttributesKey("cue.field_name", DefaultLanguageHighlighterColors.INSTANCE_FIELD);
TextAttributesKey FIELD_NAME_OPTIONAL = createTextAttributesKey("cue.field_name_optional", FIELD_NAME);

TextAttributesKey ATTRIBUTE_NAME = createTextAttributesKey("cue.attribute_name", DefaultLanguageHighlighterColors.MARKUP_TAG);
}
1 change: 1 addition & 0 deletions src/main/resources/messages/cuelang.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ colorSettings.string_escaped_char=String//Escaped character
colorSettings.byte_value=String//Byte value
colorSettings.field_name=Struct//Field name
colorSettings.field_name_optional=Struct//Optional field name
colorSettings.attributeName=Attribute name
folding.settings.title=CUE
folding.settings.fileComments=File comments
folding.settings.imports=Imports
Expand Down

0 comments on commit 4ad870f

Please sign in to comment.