feat(zig)!: PSI tree and better highlighting

This commit is contained in:
FalsePattern 2023-08-17 15:28:09 +02:00 committed by FalsePattern
parent 649ce7181c
commit cfb4abbe93
Signed by: falsepattern
GPG key ID: FDF7126A9E124447
20 changed files with 1344 additions and 153 deletions

View file

@ -19,9 +19,24 @@ Changelog structure reference:
## [Unreleased] ## [Unreleased]
### Added ### Added
#### LSP
- Separate timeout category for syntax highlighting - Separate timeout category for syntax highlighting
#### Zig
- Basic "dumb" syntax highlighting when LSP is not connected
- Go to usages now works properly
- Color scheme preview now works properly
- Better "smart" syntax highlighting when LSP is connected
### Fixed
#### Code Actions
- IDE no longer freezes when ZLS responds slowly
### Security ### Security
- Updated dependencies - Updated dependencies
- Integrated LSP4IntelliJ directly into ZigBrains - Integrated LSP4IntelliJ directly into ZigBrains

View file

@ -17,8 +17,8 @@ Go to `Settings` -> `Languages & Frameworks` -> `Zig` -> `ZLS path` -> select yo
- Go to definition - Go to definition
- Rename symbol - Rename symbol
- Hover documentation - Hover documentation
- TODO:
- Go to implementations / find usages - Go to implementations / find usages
- TODO:
- Workspace Symbols - Workspace Symbols
### .zon files: ### .zon files:

View file

@ -108,11 +108,30 @@ tasks {
purgeOldFiles = true purgeOldFiles = true
} }
register<GenerateLexerTask>("generateZigLexer") {
group = "build setup"
sourceFile = file("src/main/grammar/Zig.flex")
targetDir = "${grammarKitGenDir}/lexer/${rootPackagePath}/zig/lexer"
targetClass = "ZigFlexLexer"
purgeOldFiles = true
}
register<GenerateParserTask>("generateZigParser") {
group = "build setup"
sourceFile = file("src/main/grammar/Zig.bnf")
targetRoot = "${grammarKitGenDir}/parser"
pathToParser = "${rootPackagePath}/zig/psi/ZigParser.java"
pathToPsiRoot = "${rootPackagePath}/zig/psi"
purgeOldFiles = true
}
register<DefaultTask>("generateSources") { register<DefaultTask>("generateSources") {
description = "Generate source code from parser/lexer definitions" description = "Generate source code from parser/lexer definitions"
group = "build setup" group = "build setup"
dependsOn("generateZonLexer") dependsOn("generateZonLexer")
dependsOn("generateZonParser") dependsOn("generateZonParser")
dependsOn("generateZigLexer")
dependsOn("generateZigParser")
} }
compileJava { compileJava {

509
src/main/grammar/Zig.bnf Normal file
View file

@ -0,0 +1,509 @@
/*
* Copyright 2023 FalsePattern
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
{
parserClass="com.falsepattern.zigbrains.zig.parser.ZigParser"
extends="com.intellij.extapi.psi.ASTWrapperPsiElement"
psiClassPrefix="Zig"
psiImplClassSuffix="Impl"
psiPackage="com.falsepattern.zigbrains.zig.psi"
psiImplPackage="com.falsepattern.zigbrains.zig.psi.impl"
elementTypeHolderClass="com.falsepattern.zigbrains.zig.psi.ZigTypes"
elementTypeClass="com.falsepattern.zigbrains.zig.psi.ZigElementType"
tokenTypeClass="com.falsepattern.zigbrains.zig.psi.ZigTokenType"
generateTokenAccessors = true
tokens=[
//Symbols
AMPERSAND='&'
AMPERSANDEQUAL='&='
ASTERISK='*'
ASTERISK2='**'
ASTERISKEQUAL='*='
ASTERISKPERCENT='*%'
ASTERISKPERCENTEQUAL='*%='
ASTERISKPIPE='*|'
ASTERISKPIPEEQUAL='*|='
CARET='^'
CARETEQUAL='^='
COLON=':'
COMMA=','
DOT='.'
DOT2='..'
DOT3='...'
DOTASTERISK='.*'
DOTQUESTIONMARK='.?'
EQUAL='='
EQUALEQUAL='=='
EQUALRARROW='=>'
EXCLAMATIONMARK='!'
EXCLAMATIONMARKEQUAL='!='
LARROW='<'
LARROW2='<<'
LARROW2EQUAL='<<='
LARROW2PIPE='<<|'
LARROW2PIPEEQUAL='<<|='
LARROWEQUAL='<='
LBRACE='{'
LBRACKET='['
LPAREN='('
MINUS='-'
MINUSEQUAL='-='
MINUSPERCENT='-%'
MINUSPERCENTEQUAL='-%='
MINUSPIPE='-|'
MINUSPIPEEQUAL='-|='
MINUSRARROW='->'
PERCENT='%'
PERCENTEQUAL='%='
PIPE='|'
PIPE2='||'
PIPEEQUAL='|='
PLUS='+'
PLUS2='++'
PLUSEQUAL='+='
PLUSPERCENT='+%'
PLUSPERCENTEQUAL='+%='
PLUSPIPE='+|'
PLUSPIPEEQUAL='+|='
QUESTIONMARK='?'
RARROW='>'
RARROW2='>>'
RARROW2EQUAL='>>='
RARROWEQUAL='>='
RBRACE='}'
RBRACKET=']'
RPAREN=')'
SEMICOLON=';'
SLASH='/'
SLASHEQUAL='/='
TILDE='~'
//Keywords
KEYWORD_ADDRSPACE='addrspace'
KEYWORD_ALIGN='align'
KEYWORD_ALLOWZERO='allowzero'
KEYWORD_AND='and'
KEYWORD_ANYFRAME='anyframe'
KEYWORD_ANYTYPE='anytype'
KEYWORD_ASM='asm'
KEYWORD_ASYNC='async'
KEYWORD_AWAIT='await'
KEYWORD_BREAK='break'
KEYWORD_CALLCONV='callconv'
KEYWORD_CATCH='catch'
KEYWORD_COMPTIME='comptime'
KEYWORD_CONST='const'
KEYWORD_CONTINUE='continue'
KEYWORD_DEFER='defer'
KEYWORD_ELSE='else'
KEYWORD_ENUM='enum'
KEYWORD_ERRDEFER='errdefer'
KEYWORD_ERROR='error'
KEYWORD_EXPORT='export'
KEYWORD_EXTERN='extern'
KEYWORD_FN='fn'
KEYWORD_FOR='for'
KEYWORD_IF='if'
KEYWORD_INLINE='inline'
KEYWORD_NOALIAS='noalias'
KEYWORD_NOSUSPEND='nosuspend'
KEYWORD_NOINLINE='noinline'
KEYWORD_OPAQUE='opaque'
KEYWORD_OR='or'
KEYWORD_ORELSE='orelse'
KEYWORD_PACKED='packed'
KEYWORD_PUB='pub'
KEYWORD_RESUME='resume'
KEYWORD_RETURN='return'
KEYWORD_LINKSECTION='linksection'
KEYWORD_STRUCT='struct'
KEYWORD_SUSPEND='suspend'
KEYWORD_SWITCH='switch'
KEYWORD_TEST='test'
KEYWORD_THREADLOCAL='threadlocal'
KEYWORD_TRY='try'
KEYWORD_UNION='union'
KEYWORD_UNREACHABLE='unreachable'
KEYWORD_USINGNAMESPACE='usingnamespace'
KEYWORD_VAR='var'
KEYWORD_VOLATILE='volatile'
KEYWORD_WHILE='while'
CONTAINER_DOC_COMMENT='container doc comment'
DOC_COMMENT='doc comment'
LINE_COMMENT='comment'
CHAR_LITERAL='character literal'
FLOAT='float'
INTEGER='integer'
STRING_LITERAL_SINGLE='quoted string literal'
STRING_LITERAL_MULTI='multiline string literal'
IDENTIFIER='identifier'
BUILTINIDENTIFIER='builtin identifier'
]
}
Root ::= CONTAINER_DOC_COMMENT? ContainerMembers?
// *** Top level ***
private ContainerMembers ::= ContainerDeclaration* (ContainerField COMMA)* (ContainerField | ContainerDeclaration*)?
ContainerDeclaration
::= TestDecl
| ComptimeDecl
| DOC_COMMENT? KEYWORD_PUB? Decl
TestDecl ::= DOC_COMMENT? KEYWORD_TEST (STRING_LITERAL_SINGLE | IDENTIFIER)? Block
ComptimeDecl ::= KEYWORD_COMPTIME Block
Decl
::= (KEYWORD_EXPORT | KEYWORD_EXTERN STRING_LITERAL_SINGLE? | (KEYWORD_INLINE | KEYWORD_NOILINE))? FnProto (SEMICOLON | Block)
| (KEYWORD_EXPORT | KEYWORD_EXTERN STRING_LITERAL_SINGLE?)? KEYWORD_THREADLOCAL? VarDecl
| KEYWORD_USINGNAMESPACE Expr SEMICOLON
FnProto ::= KEYWORD_FN IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? AddrSpace? LinkSection? CallConv? EXCLAMATIONMARK? TypeExpr
VarDecl ::= (KEYWORD_CONST | KEYWORD_VAR) IDENTIFIER (COLON TypeExpr)? ByteAlign? AddrSpace? LinkSection? (EQUAL Expr)? SEMICOLON
ContainerField
::= DOC_COMMENT? KEYWORD_COMPTIME? IDENTIFIER (COLON TypeExpr)? ByteAlign? (EQUAL Expr)?
| DOC_COMMENT? KEYWORD_COMPTIME? (IDENTIFIER COLON)? !KEYWORD_FN TypeExpr ByteAlign? (EQUAL Expr)?
// *** Block Level ***
Statement
::= KEYWORD_COMPTIME? VarDecl
| KEYWORD_COMPTIME BlockExprStatement
| KEYWORD_NOSUSPEND BlockExprStatement
| KEYWORD_DEFER BlockExprStatement
| KEYWORD_ERRDEFER Payload? BlockExprStatement
| IfStatement
| LabeledStatement
| SwitchExpr
| AssignExpr SEMICOLON
IfStatement
::= IfPrefix BlockExpr ( KEYWORD_ELSE Payload? Statement )?
| IfPrefix AssignExpr ( SEMICOLON | KEYWORD_ELSE Payload? Statement )
LabeledStatement ::= BlockLabel? (Block | LoopStatement)
LoopStatement ::= KEYWORD_INLINE? (ForStatement | WhileStatement)
ForStatement
::= ForPrefix BlockExpr ( KEYWORD_ELSE Statement )?
| ForPrefix AssignExpr ( SEMICOLON | KEYWORD_ELSE Statement )
WhileStatement
::= WhilePrefix BlockExpr ( KEYWORD_ELSE Payload? Statement )?
| WhilePrefix AssignExpr ( SEMICOLON | KEYWORD_ELSE Payload? Statement)
BlockExprStatement
::= BlockExpr
| AssignExpr SEMICOLON
BlockExpr ::= BlockLabel? Block
// *** Expression Level ***
AssignExpr ::= Expr (AssignOp Expr)?
Expr ::= BoolOrExpr
BoolOrExpr ::= BoolAndExpr (KEYWORD_OR BoolAndExpr)*
BoolAndExpr ::= CompareExpr (KEYWORD_AND CompareExpr)*
CompareExpr ::= BitwiseExpr (CompareOp BitwiseExpr)?
BitwiseExpr ::= BitShiftExpr (BitwiseOp BitShiftExpr)*
BitShiftExpr ::= AdditionExpr (BitShiftOp AdditionExpr)*
AdditionExpr ::= MultiplyExpr (AdditionOp MultiplyExpr)*
MultiplyExpr ::= PrefixExpr (MultiplyOp PrefixExpr)*
PrefixExpr ::= PrefixOp* PrimaryExpr
PrimaryExpr
::= AsmExpr
| IfExpr
| KEYWORD_BREAK BreakLabel? Expr?
| KEYWORD_COMPTIME Expr
| KEYWORD_NOSUSPEND Expr
| KEYWORD_CONTINUE BreakLabel?
| KEYWORD_RESUME Expr
| KEYWORD_RETURN Expr?
| BlockLabel? LoopExpr
| Block
| CurlySuffixExpr
IfExpr ::= IfPrefix Expr (KEYWORD_ELSE Payload? Expr)?
Block ::= LBRACE Statement* RBRACE
LoopExpr ::= KEYWORD_INLINE? (ForExpr | WhileExpr)
ForExpr ::= ForPrefix Expr (KEYWORD_ELSE Expr)?
WhileExpr ::= WhilePrefix Expr (KEYWORD_ELSE Payload? Expr)?
CurlySuffixExpr ::= TypeExpr InitList?
InitList
::= LBRACE FieldInit (COMMA FieldInit)* COMMA? RBRACE
| LBRACE Expr (COMMA Expr)* COMMA? RBRACE
| LBRACE RBRACE
TypeExpr ::= PrefixTypeOp* ErrorUnionExpr
ErrorUnionExpr ::= SuffixExpr (EXCLAMATIONMARK TypeExpr)?
SuffixExpr
::= KEYWORD_ASYNC PrimaryTypeExpr SuffixOp* FnCallArguments
| PrimaryTypeExpr (SuffixOp | FnCallArguments)*
PrimaryTypeExpr
::= BUILTINIDENTIFIER FnCallArguments
| CHAR_LITERAL
| ContainerDecl
| DOT IDENTIFIER
| DOT InitList
| ErrorSetDecl
| FLOAT
| FnProto
| GroupedExpr
| LabeledTypeExpr
| IDENTIFIER
| IfTypeExpr
| INTEGER
| KEYWORD_COMPTIME TypeExpr
| KEYWORD_ERROR DOT IDENTIFIER
| KEYWORD_ANYFRAME
| KEYWORD_UNREACHABLE
| StringLiteral
| SwitchExpr
ContainerDecl ::= (KEYWORD_EXTERN | KEYWORD_PACKED)? ContainerDeclAuto
ErrorSetDecl ::= KEYWORD_ERROR LBRACE IdentifierList RBRACE
GroupedExpr ::= LPAREN Expr RPAREN
IfTypeExpr ::= IfPrefix TypeExpr (KEYWORD_ELSE Payload? TypeExpr)?
LabeledTypeExpr
::= BlockLabel Block
| BlockLabel? LoopTypeExpr
LoopTypeExpr ::= KEYWORD_INLINE? (ForTypeExpr | WhileTypeExpr)
ForTypeExpr ::= ForPrefix TypeExpr (KEYWORD_ELSE TypeExpr)?
WhileTypeExpr ::= WhilePrefix TypeExpr (KEYWORD_ELSE Payload? TypeExpr)?
SwitchExpr ::= KEYWORD_SWITCH LPAREN Expr RPAREN LBRACE SwitchProngList RBRACE
// *** Assembly ***
AsmExpr ::= KEYWORD_ASM KEYWORD_VOLATILE? LPAREN Expr AsmOutput? RPAREN
AsmOutput ::= COLON AsmOutputList AsmInput?
AsmOutputItem ::= LBRACKET IDENTIFIER RBRACKET StringLiteral LPAREN (MINUSRARROW TypeExpr | IDENTIFIER) RPAREN
AsmInput ::= COLON AsmInputList AsmClobbers?
AsmInputItem ::= LBRACKET IDENTIFIER RBRACKET StringLiteral LPAREN Expr RPAREN
AsmClobbers ::= COLON StringList
// *** Helper grammar ***
BreakLabel ::= COLON IDENTIFIER
BlockLabel ::= IDENTIFIER COLON
FieldInit ::= DOT IDENTIFIER EQUAL Expr
WhileContinueExpr ::= COLON LPAREN AssignExpr RPAREN
LinkSection ::= KEYWORD_LINKSECTION LPAREN Expr RPAREN
AddrSpace ::= KEYWORD_ADDRSPACE LPAREN Expr RPAREN
// Fn specific
CallConv ::= KEYWORD_CALLCONV LPAREN Expr RPAREN
ParamDecl
::= DOC_COMMENT? (KEYWORD_NOALIAS | KEYWORD_COMPTIME)? (IDENTIFIER COLON)? ParamType
| DOT3
ParamType
::= KEYWORD_ANYTYPE
| TypeExpr
// Control flow prefixes
IfPrefix ::= KEYWORD_IF LPAREN Expr RPAREN PtrPayload?
WhilePrefix ::= KEYWORD_WHILE LPAREN Expr RPAREN PtrPayload? WhileContinueExpr?
ForPrefix ::= KEYWORD_FOR LPAREN Expr RPAREN PtrIndexPayload
// Payloads
Payload ::= PIPE IDENTIFIER PIPE
PtrPayload ::= PIPE ASTERISK? IDENTIFIER PIPE
PtrIndexPayload ::= PIPE ASTERISK? IDENTIFIER (COMMA IDENTIFIER)? PIPE
// Switch specific
SwitchProng ::= KEYWORD_INLINE? SwitchCase EQUALRARROW PtrIndexPayload? AssignExpr
SwitchCase
::= SwitchItem (COMMA SwitchItem)* COMMA?
| KEYWORD_ELSE
SwitchItem ::= Expr (DOT3 Expr)?
// Operators
AssignOp
::= ASTERISKEQUAL
| ASTERISKPIPEEQUAL
| SLASHEQUAL
| PERCENTEQUAL
| PLUSEQUAL
| PLUSPIPEEQUAL
| MINUSEQUAL
| MINUSPIPEEQUAL
| LARROW2EQUAL
| LARROW2PIPEEQUAL
| RARROW2EQUAL
| AMPERSANDEQUAL
| CARETEQUAL
| PIPEEQUAL
| ASTERISKPERCENTEQUAL
| PLUSPERCENTEQUAL
| MINUSPERCENTEQUAL
| EQUAL
CompareOp
::= EQUALEQUAL
| EXCLAMATIONMARKEQUAL
| LARROW
| RARROW
| LARROWEQUAL
| RARROWEQUAL
BitwiseOp
::= AMPERSAND
| CARET
| PIPE
| KEYWORD_ORELSE
| KEYWORD_CATCH Payload?
BitShiftOp
::= LARROW2
| RARROW2
| LARROW2PIPE
AdditionOp
::= PLUS
| MINUS
| PLUS2
| PLUSPERCENT
| MINUSPERCENT
| PLUSPIPE
| MINUSPIPE
MultiplyOp
::= PIPE2
| ASTERISK
| SLASH
| PERCENT
| ASTERISK2
| ASTERISKPERCENT
| ASTERISKPIPE
PrefixOp
::= EXCLAMATIONMARK
| MINUS
| TILDE
| MINUSPERCENT
| AMPERSAND
| KEYWORD_TRY
| KEYWORD_AWAIT
PrefixTypeOp
::= QUESTIONMARK
| KEYWORD_ANYFRAME MINUSRARROW
| SliceTypeStart (ByteAlign | AddrSpace | KEYWORD_CONST | KEYWORD_VOLATILE | KEYWORD_ALLOWZERO)*
| PtrTypeStart (AddrSpace | KEYWORD_ALIGN LPAREN Expr (COLON Expr COLON Expr)? RPAREN | KEYWORD_CONST | KEYWORD_VOLATILE | KEYWORD_ALLOWZERO)*
| ArrayTypeStart
SuffixOp
::= LBRACKET Expr (DOT2 (Expr? (COLON Expr)?)?)? RBRACKET
| DOT IDENTIFIER
| DOTASTERISK
| DOTQUESTIONMARK
FnCallArguments ::= LPAREN ExprList RPAREN
// Ptr specific
SliceTypeStart ::= LBRACKET (COLON Expr)? RBRACKET
PtrTypeStart
::= ASTERISK
| ASTERISK2
| LBRACKET ASTERISK ("c" | COLON Expr)? RBRACKET
ArrayTypeStart ::= LBRACKET Expr (COLON Expr)? RBRACKET
// ContainerDecl specific
ContainerDeclAuto ::= ContainerDeclType LBRACE CONTAINER_DOC_COMMENT? ContainerMembers RBRACE
ContainerDeclType
::= KEYWORD_STRUCT (LPAREN Expr RPAREN)?
| KEYWORD_OPAQUE
| KEYWORD_ENUM (LPAREN Expr RPAREN)?
| KEYWORD_UNION (LPAREN (KEYWORD_ENUM (LPAREN Expr RPAREN)? | Expr) RPAREN)?
// Alignment
ByteAlign ::= KEYWORD_ALIGN LPAREN Expr RPAREN
// Lists
IdentifierList ::= (DOC_COMMENT? IDENTIFIER COMMA)* (DOC_COMMENT? IDENTIFIER)?
SwitchProngList ::= (SwitchProng COMMA)* SwitchProng?
AsmOutputList ::= (AsmOutputItem COMMA)* AsmOutputItem?
AsmInputList ::= (AsmInputItem COMMA)* AsmInputItem?
StringList ::= (StringLiteral COMMA)* StringLiteral?
ParamDeclList ::= (ParamDecl COMMA)* ParamDecl?
ExprList ::= (Expr COMMA)* Expr?
StringLiteral ::= STRING_LITERAL_SINGLE | STRING_LITERAL_MULTI

277
src/main/grammar/Zig.flex Normal file
View file

@ -0,0 +1,277 @@
/*
* Copyright 2023 FalsePattern
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.falsepattern.zigbrains.zig.lexer;
import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
import static com.intellij.psi.TokenType.WHITE_SPACE;
import static com.intellij.psi.TokenType.BAD_CHARACTER;
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.*;
%%
%class ZigFlexLexer
%implements FlexLexer
%function advance
%type IElementType
CRLF=\R
WHITE_SPACE=[\s]+
bin=[01]
bin_="_"? {bin}
oct=[0-7]
oct_="_"? {oct}
hex=[0-9a-fA-F]
hex_="_"? {hex}
dec=[0-9]
dec_="_"? {dec}
bin_int={bin} {bin_}*
oct_int={oct} {oct_}*
dec_int={dec} {dec_}*
hex_int={hex} {hex_}*
ox80_oxBF=[\200-\277]
oxF4=\364
ox80_ox8F=[\200-\217]
oxF1_oxF3=[\361-\363]
oxF0=\360
ox90_0xBF=[\220-\277]
oxEE_oxEF=[\356-\357]
oxED=\355
ox80_ox9F=[\200-\237]
oxE1_oxEC=[\341-\354]
oxE0=\340
oxA0_oxBF=[\240-\277]
oxC2_oxDF=[\302-\337]
// From https://lemire.me/blog/2018/05/09/how-quickly-can-you-check-that-a-string-is-valid-unicode-utf-8/
// First Byte Second Byte Third Byte Fourth Byte
// [0x00,0x7F]
// [0xC2,0xDF] [0x80,0xBF]
// 0xE0 [0xA0,0xBF] [0x80,0xBF]
// [0xE1,0xEC] [0x80,0xBF] [0x80,0xBF]
// 0xED [0x80,0x9F] [0x80,0xBF]
// [0xEE,0xEF] [0x80,0xBF] [0x80,0xBF]
// 0xF0 [0x90,0xBF] [0x80,0xBF] [0x80,0xBF]
// [0xF1,0xF3] [0x80,0xBF] [0x80,0xBF] [0x80,0xBF]
// 0xF4 [0x80,0x8F] [0x80,0xBF] [0x80,0xBF]
mb_utf8_literal= {oxF4} {ox80_ox8F} {ox80_oxBF} {ox80_oxBF}
| {oxF1_oxF3} {ox80_oxBF} {ox80_oxBF} {ox80_oxBF}
| {oxF0} {ox90_0xBF} {ox80_oxBF} {ox80_oxBF}
| {oxEE_oxEF} {ox80_oxBF} {ox80_oxBF}
| {oxED} {ox80_ox9F} {ox80_oxBF}
| {oxE1_oxEC} {ox80_oxBF} {ox80_oxBF}
| {oxE0} {oxA0_oxBF} {ox80_oxBF}
| {oxC2_oxDF} {ox80_oxBF}
ascii_char_not_nl_slash_squote=[\000-\011\013-\046\050-\133\135-\177]
char_escape= "\\x" {hex} {hex}
| "\\u{" {hex}+ "}"
| "\\" [nr\\t'\"]
char_char= {mb_utf8_literal}
| {char_escape}
| {ascii_char_not_nl_slash_squote}
string_char= {char_escape}
| [^\\\"\n]
CONTAINER_DOC_COMMENT=("//!" [^\n]* [ \n]*)+
DOC_COMMENT=("///" [^\n]* [ \n]*)+
LINE_COMMENT="//" [^\n]* | "////" [^\n]*
line_string=("\\\\" [^\n]* [ \n]*)+
FLOAT= "0x" {hex_int} "." {hex_int} ([pP] [-+]? {dec_int})?
| {dec_int} "." {dec_int} ([eE] [-+]? {dec_int})?
| "0x" {hex_int} [pP] [-+]? {dec_int}
| {dec_int} [eE] [-+]? {dec_int}
INTEGER= "0b" {bin_int}
| "0o" {oct_int}
| "0x" {hex_int}
| {dec_int}
IDENTIFIER_PLAIN=[A-Za-z_][A-Za-z0-9_]*
BUILTINIDENTIFIER="@"[A-Za-z_][A-Za-z0-9_]*
%state STR_LIT
%state CHAR_LIT
%state ID_QUOT
%state UNT_QUOT
%state CDOC_CMT
%state DOC_CMT
%state LINE_CMT
%%
//Comments
<YYINITIAL> "//!" { yypushback(3); yybegin(CDOC_CMT); }
<CDOC_CMT> {CONTAINER_DOC_COMMENT} { yybegin(YYINITIAL); return CONTAINER_DOC_COMMENT; }
<YYINITIAL> "///" { yypushback(3); yybegin(DOC_CMT); }
<DOC_CMT> {DOC_COMMENT} { yybegin(YYINITIAL); return DOC_COMMENT; }
<YYINITIAL> "//" { yypushback(2); yybegin(LINE_CMT); }
<LINE_CMT> {LINE_COMMENT} { yybegin(YYINITIAL); return LINE_COMMENT; }
//Symbols
<YYINITIAL> "&" { return AMPERSAND; }
<YYINITIAL> "&=" { return AMPERSANDEQUAL; }
<YYINITIAL> "*" { return ASTERISK; }
<YYINITIAL> "**" { return ASTERISK2; }
<YYINITIAL> "*=" { return ASTERISKEQUAL; }
<YYINITIAL> "*%" { return ASTERISKPERCENT; }
<YYINITIAL> "*%=" { return ASTERISKPERCENTEQUAL; }
<YYINITIAL> "*|" { return ASTERISKPIPE; }
<YYINITIAL> "*|=" { return ASTERISKPIPEEQUAL; }
<YYINITIAL> "^" { return CARET; }
<YYINITIAL> "^=" { return CARETEQUAL; }
<YYINITIAL> ":" { return COLON; }
<YYINITIAL> "," { return COMMA; }
<YYINITIAL> "." { return DOT; }
<YYINITIAL> ".." { return DOT2; }
<YYINITIAL> "..." { return DOT3; }
<YYINITIAL> ".*" { return DOTASTERISK; }
<YYINITIAL> ".?" { return DOTQUESTIONMARK; }
<YYINITIAL> "=" { return EQUAL; }
<YYINITIAL> "==" { return EQUALEQUAL; }
<YYINITIAL> "=>" { return EQUALRARROW; }
<YYINITIAL> "!" { return EXCLAMATIONMARK; }
<YYINITIAL> "!=" { return EXCLAMATIONMARKEQUAL; }
<YYINITIAL> "<" { return LARROW; }
<YYINITIAL> "<<" { return LARROW2; }
<YYINITIAL> "<<=" { return LARROW2EQUAL; }
<YYINITIAL> "<<|" { return LARROW2PIPE; }
<YYINITIAL> "<<|=" { return LARROW2PIPEEQUAL; }
<YYINITIAL> "<=" { return LARROWEQUAL; }
<YYINITIAL> "{" { return LBRACE; }
<YYINITIAL> "[" { return LBRACKET; }
<YYINITIAL> "(" { return LPAREN; }
<YYINITIAL> "-" { return MINUS; }
<YYINITIAL> "-=" { return MINUSEQUAL; }
<YYINITIAL> "-%" { return MINUSPERCENT; }
<YYINITIAL> "-%=" { return MINUSPERCENTEQUAL; }
<YYINITIAL> "-|" { return MINUSPIPE; }
<YYINITIAL> "-|=" { return MINUSPIPEEQUAL; }
<YYINITIAL> "->" { return MINUSRARROW; }
<YYINITIAL> "%" { return PERCENT; }
<YYINITIAL> "%=" { return PERCENTEQUAL; }
<YYINITIAL> "|" { return PIPE; }
<YYINITIAL> "||" { return PIPE2; }
<YYINITIAL> "|=" { return PIPEEQUAL; }
<YYINITIAL> "+" { return PLUS; }
<YYINITIAL> "++" { return PLUS2; }
<YYINITIAL> "+=" { return PLUSEQUAL; }
<YYINITIAL> "+%" { return PLUSPERCENT; }
<YYINITIAL> "+%=" { return PLUSPERCENTEQUAL; }
<YYINITIAL> "+|" { return PLUSPIPE; }
<YYINITIAL> "+|=" { return PLUSPIPEEQUAL; }
//This one is directly in the tokenizer, because it conflicts with identifiers without context
//<YYINITIAL> "c" { return LETTERC; }
<YYINITIAL> "?" { return QUESTIONMARK; }
<YYINITIAL> ">" { return RARROW; }
<YYINITIAL> ">>" { return RARROW2; }
<YYINITIAL> ">>=" { return RARROW2EQUAL; }
<YYINITIAL> ">=" { return RARROWEQUAL; }
<YYINITIAL> "}" { return RBRACE; }
<YYINITIAL> "]" { return RBRACKET; }
<YYINITIAL> ")" { return RPAREN; }
<YYINITIAL> ";" { return SEMICOLON; }
<YYINITIAL> "/" { return SLASH; }
<YYINITIAL> "/=" { return SLASHEQUAL; }
<YYINITIAL> "~" { return TILDE; }
// keywords
<YYINITIAL> "addrspace" { return KEYWORD_ADDRSPACE; }
<YYINITIAL> "align" { return KEYWORD_ALIGN; }
<YYINITIAL> "allowzero" { return KEYWORD_ALLOWZERO; }
<YYINITIAL> "and" { return KEYWORD_AND; }
<YYINITIAL> "anyframe" { return KEYWORD_ANYFRAME; }
<YYINITIAL> "anytype" { return KEYWORD_ANYTYPE; }
<YYINITIAL> "asm" { return KEYWORD_ASM; }
<YYINITIAL> "async" { return KEYWORD_ASYNC; }
<YYINITIAL> "await" { return KEYWORD_AWAIT; }
<YYINITIAL> "break" { return KEYWORD_BREAK; }
<YYINITIAL> "callconv" { return KEYWORD_CALLCONV; }
<YYINITIAL> "catch" { return KEYWORD_CATCH; }
<YYINITIAL> "comptime" { return KEYWORD_COMPTIME; }
<YYINITIAL> "const" { return KEYWORD_CONST; }
<YYINITIAL> "continue" { return KEYWORD_CONTINUE; }
<YYINITIAL> "defer" { return KEYWORD_DEFER; }
<YYINITIAL> "else" { return KEYWORD_ELSE; }
<YYINITIAL> "enum" { return KEYWORD_ENUM; }
<YYINITIAL> "errdefer" { return KEYWORD_ERRDEFER; }
<YYINITIAL> "error" { return KEYWORD_ERROR; }
<YYINITIAL> "export" { return KEYWORD_EXPORT; }
<YYINITIAL> "extern" { return KEYWORD_EXTERN; }
<YYINITIAL> "fn" { return KEYWORD_FN; }
<YYINITIAL> "for" { return KEYWORD_FOR; }
<YYINITIAL> "if" { return KEYWORD_IF; }
<YYINITIAL> "inline" { return KEYWORD_INLINE; }
<YYINITIAL> "noalias" { return KEYWORD_NOALIAS; }
<YYINITIAL> "nosuspend" { return KEYWORD_NOSUSPEND; }
<YYINITIAL> "noinline" { return KEYWORD_NOINLINE; }
<YYINITIAL> "opaque" { return KEYWORD_OPAQUE; }
<YYINITIAL> "or" { return KEYWORD_OR; }
<YYINITIAL> "orelse" { return KEYWORD_ORELSE; }
<YYINITIAL> "packed" { return KEYWORD_PACKED; }
<YYINITIAL> "pub" { return KEYWORD_PUB; }
<YYINITIAL> "resume" { return KEYWORD_RESUME; }
<YYINITIAL> "return" { return KEYWORD_RETURN; }
<YYINITIAL> "linksection" { return KEYWORD_LINKSECTION; }
<YYINITIAL> "struct" { return KEYWORD_STRUCT; }
<YYINITIAL> "suspend" { return KEYWORD_SUSPEND; }
<YYINITIAL> "switch" { return KEYWORD_SWITCH; }
<YYINITIAL> "test" { return KEYWORD_TEST; }
<YYINITIAL> "threadlocal" { return KEYWORD_THREADLOCAL; }
<YYINITIAL> "try" { return KEYWORD_TRY; }
<YYINITIAL> "union" { return KEYWORD_UNION; }
<YYINITIAL> "unreachable" { return KEYWORD_UNREACHABLE; }
<YYINITIAL> "usingnamespace" { return KEYWORD_USINGNAMESPACE; }
<YYINITIAL> "var" { return KEYWORD_VAR; }
<YYINITIAL> "volatile" { return KEYWORD_VOLATILE; }
<YYINITIAL> "while" { return KEYWORD_WHILE; }
<YYINITIAL> "'" { yybegin(CHAR_LIT); }
<CHAR_LIT> {char_char}"'" { yybegin(YYINITIAL); return CHAR_LITERAL; }
<CHAR_LIT> [^] { yypushback(1); yybegin(UNT_QUOT); }
<YYINITIAL> {FLOAT} { return FLOAT; }
<YYINITIAL> {INTEGER} { return INTEGER; }
<YYINITIAL> "\"" { yybegin(STR_LIT); }
<STR_LIT> {string_char}*"\"" { yybegin(YYINITIAL); return STRING_LITERAL_SINGLE; }
<STR_LIT> [^] { yypushback(1); yybegin(UNT_QUOT); }
<YYINITIAL> {line_string}+ { return STRING_LITERAL_MULTI; }
<YYINITIAL> {IDENTIFIER_PLAIN} { return IDENTIFIER; }
<YYINITIAL> "@\"" { yybegin(ID_QUOT); }
<ID_QUOT> {string_char}*"\"" { yybegin(YYINITIAL); return IDENTIFIER; }
<ID_QUOT> [^] { yypushback(1); yybegin(UNT_QUOT); }
<YYINITIAL> {BUILTINIDENTIFIER} { return BUILTINIDENTIFIER; }
<UNT_QUOT> [^\n]*{CRLF} { yybegin(YYINITIAL); return BAD_CHARACTER; }
<YYINITIAL> {WHITE_SPACE} { return WHITE_SPACE; }
[^] { return BAD_CHARACTER; }

View file

@ -145,7 +145,6 @@ public class LanguageServerWrapper {
private InitializeResult initializeResult; private InitializeResult initializeResult;
private Future<?> launcherFuture; private Future<?> launcherFuture;
private CompletableFuture<InitializeResult> initializeFuture; private CompletableFuture<InitializeResult> initializeFuture;
private boolean capabilitiesAlreadyRequested = false;
private int crashCount = 0; private int crashCount = 0;
private volatile boolean alreadyShownTimeout = false; private volatile boolean alreadyShownTimeout = false;
private volatile boolean alreadyShownCrash = false; private volatile boolean alreadyShownCrash = false;
@ -228,7 +227,7 @@ public class LanguageServerWrapper {
try { try {
start(); start();
if (initializeFuture != null) { if (initializeFuture != null) {
initializeFuture.get((capabilitiesAlreadyRequested ? 0 : Timeout.getTimeout(Timeouts.INIT)), TimeUnit.MILLISECONDS); initializeFuture.get(Timeout.getTimeout(Timeouts.INIT), TimeUnit.MILLISECONDS);
notifySuccess(Timeouts.INIT); notifySuccess(Timeouts.INIT);
} }
} catch (TimeoutException e) { } catch (TimeoutException e) {
@ -248,7 +247,6 @@ public class LanguageServerWrapper {
stop(false); stop(false);
} }
} }
capabilitiesAlreadyRequested = true;
return initializeResult != null ? initializeResult.getCapabilities() : null; return initializeResult != null ? initializeResult.getCapabilities() : null;
} }
@ -467,7 +465,6 @@ public class LanguageServerWrapper {
uriToEditorManagers.clear(); uriToEditorManagers.clear();
urisUnderLspControl.clear(); urisUnderLspControl.clear();
launcherFuture = null; launcherFuture = null;
capabilitiesAlreadyRequested = false;
initializeResult = null; initializeResult = null;
initializeFuture = null; initializeFuture = null;
languageServer = null; languageServer = null;

View file

@ -1400,11 +1400,18 @@ public class EditorEventManager {
// sends code action request. // sends code action request.
int caretPos = editor.getCaretModel().getCurrentCaret().getOffset(); int caretPos = editor.getCaretModel().getCurrentCaret().getOffset();
pool(() -> {
if (editor.isDisposed()) {
return;
}
List<Either<Command, CodeAction>> codeActionResp = codeAction(caretPos); List<Either<Command, CodeAction>> codeActionResp = codeAction(caretPos);
if (codeActionResp == null || codeActionResp.isEmpty()) { if (codeActionResp == null || codeActionResp.isEmpty()) {
return; return;
} }
invokeLater(() -> {
if (editor.isDisposed()) {
return;
}
codeActionResp.forEach(element -> { codeActionResp.forEach(element -> {
if (element == null) { if (element == null) {
return; return;
@ -1463,6 +1470,8 @@ public class EditorEventManager {
updateErrorAnnotations(); updateErrorAnnotations();
} }
}); });
});
});
} }
/** /**

View file

@ -20,8 +20,10 @@ import com.intellij.openapi.project.NoAccessDuringPsiEvents;
import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Condition;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class ApplicationUtils { public class ApplicationUtils {
@ -49,7 +51,15 @@ public class ApplicationUtils {
} }
static public <T> T computableReadAction(Computable<T> computable) { static public <T> T computableReadAction(Computable<T> computable) {
if (ApplicationManager.getApplication().isDispatchThread()) {
return ApplicationManager.getApplication().runReadAction(computable); return ApplicationManager.getApplication().runReadAction(computable);
} else {
var result = new Object() {
T value = null;
};
ApplicationManager.getApplication().invokeAndWait(() -> result.value = ApplicationManager.getApplication().runReadAction(computable));
return result.value;
}
} }
static public void writeAction(Runnable runnable) { static public void writeAction(Runnable runnable) {

View file

@ -0,0 +1,169 @@
/*
* Copyright 2023 FalsePattern
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.falsepattern.zigbrains.zig.highlighter;
import com.falsepattern.zigbrains.common.Icons;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.ColorDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.Icon;
import java.util.HashMap;
import java.util.Map;
public class ZigColorSettingsPage implements ColorSettingsPage {
private static final AttributesDescriptor[] DESCRIPTORS =
new AttributesDescriptor[]{
new AttributesDescriptor("Bad character", ZigSyntaxHighlighter.BAD_CHAR),
new AttributesDescriptor("Builtin", ZigSyntaxHighlighter.BUILTIN),
new AttributesDescriptor("Character literal", ZigSyntaxHighlighter.CHAR),
new AttributesDescriptor("Comment//Regular", ZigSyntaxHighlighter.COMMENT),
new AttributesDescriptor("Comment//Documentation", ZigSyntaxHighlighter.COMMENT_DOC),
new AttributesDescriptor("Enum//Reference", ZigSyntaxHighlighter.ENUM_REF),
new AttributesDescriptor("Enum//Declaration", ZigSyntaxHighlighter.ENUM_DECL),
new AttributesDescriptor("Enum//Member", ZigSyntaxHighlighter.ENUM_MEMBER),
new AttributesDescriptor("Error tag", ZigSyntaxHighlighter.ERROR_TAG),
new AttributesDescriptor("Function//Declaration", ZigSyntaxHighlighter.FUNCTION_DECL),
new AttributesDescriptor("Function//Declaration//Generic", ZigSyntaxHighlighter.FUNCTION_DECL_GEN),
new AttributesDescriptor("Function//Reference", ZigSyntaxHighlighter.FUNCTION_REF),
new AttributesDescriptor("Function//Reference//Generic", ZigSyntaxHighlighter.FUNCTION_REF_GEN),
new AttributesDescriptor("Keyword", ZigSyntaxHighlighter.KEYWORD),
new AttributesDescriptor("Label//Declaration", ZigSyntaxHighlighter.LABEL_REF),
new AttributesDescriptor("Label//Reference", ZigSyntaxHighlighter.LABEL_REF),
new AttributesDescriptor("Namespace//Declaration", ZigSyntaxHighlighter.NAMESPACE_DECL),
new AttributesDescriptor("Namespace//Reference", ZigSyntaxHighlighter.NAMESPACE_REF),
new AttributesDescriptor("Number", ZigSyntaxHighlighter.NUMBER),
new AttributesDescriptor("Operator", ZigSyntaxHighlighter.OPERATOR),
new AttributesDescriptor("Parameter", ZigSyntaxHighlighter.PARAMETER),
new AttributesDescriptor("Property", ZigSyntaxHighlighter.PROPERTY),
new AttributesDescriptor("String", ZigSyntaxHighlighter.STRING),
new AttributesDescriptor("Struct//Declaration", ZigSyntaxHighlighter.STRUCT_DECL),
new AttributesDescriptor("Struct//Reference", ZigSyntaxHighlighter.STRUCT_REF),
new AttributesDescriptor("Type//Declaration", ZigSyntaxHighlighter.TYPE_DECL),
new AttributesDescriptor("Type//Declaration//Generic", ZigSyntaxHighlighter.TYPE_DECL_GEN),
new AttributesDescriptor("Type//Reference", ZigSyntaxHighlighter.TYPE_REF),
new AttributesDescriptor("Type//Reference//Generic", ZigSyntaxHighlighter.TYPE_REF_GEN),
new AttributesDescriptor("Variable//Declaration", ZigSyntaxHighlighter.VARIABLE_DECL),
new AttributesDescriptor("Variable//Reference", ZigSyntaxHighlighter.VARIABLE_REF),
};
@Nullable
@Override
public Icon getIcon() {
return Icons.ZIG;
}
@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
return new ZigSyntaxHighlighter();
}
@NotNull
@Override
public String getDemoText() {
return """
///This is a documentation comment
const <ns>std</ns> = @import("std");
const <enumDecl>AnEnum</enumDecl> = enum {
<enumMember>A</enumMember>,
<enumMember>B</enumMember>,
<enumMember>C</enumMember>,
};
const <structDecl>AStruct</structDecl> = struct {
<property>fieldA</property>: <type>u32</type>,
<property>fieldB</property>: <type>u16</type>
};
const <typeDecl>AnErrorType</typeDecl> = error {
<etag>SomeError</etag>
};
pub fn <fn>main</fn>() <type>AnError</type>.SomeError!<type>void</type> {
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
<ns>std</ns>.<ns>debug</ns>.<fn>print</fn>("All your {s} are belong to us.\\n", .{"codebase"});
// stdout is for the actual output of your application, for example if you
// are implementing gzip, then only the compressed bytes should be sent to
// stdout, not any debugging messages.
const <varDecl>stdout_file</varDecl> = <ns>std</ns>.<ns>io</ns>.<fn>getStdOut</fn>().<fn>writer</fn>();
var <varDecl>bw</varDecl> = <ns>std</ns>.<ns>io</ns>.<fn>bufferedWriter</fn>(<var>stdout_file</var>);
const <varDecl>stdout</varDecl> = <var>bw</var>.<fn>writer</fn>();
try <var>stdout</var>.<fn>print</fn>(\\\\Run `zig build test` to run the tests.
\\\\
, .{});
_ = <enum>AnEnum</enum>.<enumMember>A</enumMember>;
try <var>bw</var>.<fn>flush</fn>(); // don't forget to flush!
}
test "simple test" {
var <varDecl>list</varDecl> = <ns>std</ns>.<type>ArrayList</type>(<type>i32</type>).<fn>init</fn>(<ns>std</ns>.<ns>testing</ns>.<type>allocator</type>);
defer <var>list</var>.<fn>deinit</fn>(); // try commenting this out and see if zig detects the memory leak!
try <var>list</var>.<fn>append</fn>(42);
try <ns>std</ns>.<ns>testing</ns>.<fn>expectEqual</fn>(@as(i32, 42), <var>list</var>.<fn>pop</fn>());
}
""";
}
private static final Map<String, TextAttributesKey> ADD_HIGHLIGHT = new HashMap<>();
static {
ADD_HIGHLIGHT.put("typeDecl", ZigSyntaxHighlighter.TYPE_DECL);
ADD_HIGHLIGHT.put("etag", ZigSyntaxHighlighter.ERROR_TAG);
ADD_HIGHLIGHT.put("struct", ZigSyntaxHighlighter.STRUCT_REF);
ADD_HIGHLIGHT.put("enum", ZigSyntaxHighlighter.ENUM_REF);
ADD_HIGHLIGHT.put("enumDecl", ZigSyntaxHighlighter.ENUM_DECL);
ADD_HIGHLIGHT.put("enumMember", ZigSyntaxHighlighter.ENUM_MEMBER);
ADD_HIGHLIGHT.put("varDecl", ZigSyntaxHighlighter.VARIABLE_DECL);
ADD_HIGHLIGHT.put("property", ZigSyntaxHighlighter.PROPERTY);
ADD_HIGHLIGHT.put("var", ZigSyntaxHighlighter.VARIABLE_REF);
ADD_HIGHLIGHT.put("ns", ZigSyntaxHighlighter.NAMESPACE_REF);
ADD_HIGHLIGHT.put("type", ZigSyntaxHighlighter.TYPE_REF);
ADD_HIGHLIGHT.put("fn", ZigSyntaxHighlighter.FUNCTION_REF);
}
@Nullable
@Override
public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() {
return ADD_HIGHLIGHT;
}
@Override
public AttributesDescriptor @NotNull [] getAttributeDescriptors() {
return DESCRIPTORS;
}
@Override
public ColorDescriptor @NotNull [] getColorDescriptors() {
return ColorDescriptor.EMPTY_ARRAY;
}
@NotNull
@Override
public String getDisplayName() {
return "Zig";
}
}

View file

@ -0,0 +1,120 @@
/*
* Copyright 2023 FalsePattern
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.falsepattern.zigbrains.zig.highlighter;
import com.falsepattern.zigbrains.zig.lexer.ZigLexerAdapter;
import com.falsepattern.zigbrains.zig.psi.ZigTypes;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.TokenType;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class ZigSyntaxHighlighter extends SyntaxHighlighterBase {
// @formatter:off
public static final TextAttributesKey
BAD_CHAR = createKey("BAD_CHARACTER" , HighlighterColors.BAD_CHARACTER ),
BUILTIN = createKey("BUILTIN" , DefaultLanguageHighlighterColors.STATIC_METHOD ),
CHAR = createKey("CHAR" , DefaultLanguageHighlighterColors.NUMBER ),
COMMENT = createKey("COMMENT" , DefaultLanguageHighlighterColors.LINE_COMMENT ),
COMMENT_DOC = createKey("COMMENT_DOC" , DefaultLanguageHighlighterColors.DOC_COMMENT ),
ENUM_DECL = createKey("ENUM_DECL" , DefaultLanguageHighlighterColors.CLASS_NAME ),
ENUM_REF = createKey("ENUM" , DefaultLanguageHighlighterColors.CLASS_REFERENCE ),
ENUM_MEMBER = createKey("ENUM_MEMBER" , DefaultLanguageHighlighterColors.STATIC_FIELD ),
ERROR_TAG = createKey("ERROR_TAG" , DefaultLanguageHighlighterColors.STATIC_FIELD ),
PROPERTY = createKey("PROPERTY" , DefaultLanguageHighlighterColors.INSTANCE_FIELD ),
FUNCTION_DECL = createKey("FUNCTION_DECL" , DefaultLanguageHighlighterColors.FUNCTION_DECLARATION),
FUNCTION_DECL_GEN = createKey("FUNCTION_DECL_GEN" , FUNCTION_DECL ),
FUNCTION_REF = createKey("FUNCTION" , DefaultLanguageHighlighterColors.FUNCTION_CALL ),
FUNCTION_REF_GEN = createKey("FUNCTION_GEN" , FUNCTION_REF ),
KEYWORD = createKey("KEYWORD" , DefaultLanguageHighlighterColors.KEYWORD ),
LABEL_DECL = createKey("LABEL_DECL" , DefaultLanguageHighlighterColors.LABEL ),
LABEL_REF = createKey("LABEL" , LABEL_DECL ),
NAMESPACE_DECL = createKey("NAMESPACE_DECL" , DefaultLanguageHighlighterColors.CLASS_REFERENCE ),
NAMESPACE_REF = createKey("NAMESPACE" , DefaultLanguageHighlighterColors.CLASS_NAME ),
NUMBER = createKey("NUMBER" , DefaultLanguageHighlighterColors.NUMBER ),
OPERATOR = createKey("OPERATOR" , DefaultLanguageHighlighterColors.OPERATION_SIGN ),
PARAMETER = createKey("PARAMETER" , DefaultLanguageHighlighterColors.PARAMETER ),
STRING = createKey("STRING" , DefaultLanguageHighlighterColors.STRING ),
STRUCT_DECL = createKey("STRUCT_DECL" , DefaultLanguageHighlighterColors.CLASS_NAME ),
STRUCT_REF = createKey("STRUCT" , DefaultLanguageHighlighterColors.CLASS_REFERENCE ),
TYPE_DECL = createKey("TYPE_DECL" , DefaultLanguageHighlighterColors.CLASS_NAME ),
TYPE_DECL_GEN = createKey("TYPE_DECL_GEN" , TYPE_DECL ),
TYPE_REF = createKey("TYPE" , DefaultLanguageHighlighterColors.CLASS_REFERENCE ),
TYPE_REF_GEN = createKey("TYPE_GEN" , TYPE_REF ),
VARIABLE_DECL = createKey("VARIABLE_DECL" , DefaultLanguageHighlighterColors.LOCAL_VARIABLE ),
VARIABLE_REF = createKey("VARIABLE" , VARIABLE_DECL );
// @formatter:on
private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0];
private static final Map<IElementType, TextAttributesKey[]> KEYMAP = new HashMap<>();
static {
// @formatter:off
addMapping(COMMENT, ZigTypes.LINE_COMMENT, ZigTypes.DOC_COMMENT, ZigTypes.CONTAINER_DOC_COMMENT);
//Keywords
{
var kws = new ArrayList<IElementType>();
for (var field: ZigTypes.class.getFields()) {
try {
if (field.getName().startsWith("KEYWORD_")) {
kws.add((IElementType) field.get(null));
}
} catch (Exception e) {
e.printStackTrace();
}
}
addMapping(KEYWORD, kws.toArray(IElementType[]::new));
}
addMapping(BUILTIN, ZigTypes.BUILTINIDENTIFIER);
addMapping(STRING, ZigTypes.STRING_LITERAL_SINGLE, ZigTypes.STRING_LITERAL_MULTI);
addMapping(BAD_CHAR, TokenType.BAD_CHARACTER);
addMapping(NUMBER, ZigTypes.INTEGER, ZigTypes.FLOAT);
addMapping(CHAR, ZigTypes.CHAR_LITERAL);
// @formatter:on
}
private static void addMapping(TextAttributesKey key, IElementType... types) {
for (var type : types) {
KEYMAP.put(type, new TextAttributesKey[]{key});
}
}
private static TextAttributesKey createKey(String name, TextAttributesKey fallback) {
return TextAttributesKey.createTextAttributesKey("ZIG_" + name, fallback);
}
@Override
public @NotNull Lexer getHighlightingLexer() {
return new ZigLexerAdapter();
}
@Override
public TextAttributesKey @NotNull [] getTokenHighlights(IElementType tokenType) {
if (KEYMAP.containsKey(tokenType)) {
return KEYMAP.get(tokenType);
}
return EMPTY_KEYS;
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright 2023 FalsePattern
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.falsepattern.zigbrains.zig.highlighter;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ZigSyntaxHighlighterFactory extends SyntaxHighlighterFactory {
@Override
public @NotNull SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile) {
return new ZigSyntaxHighlighter();
}
}

View file

@ -21,44 +21,71 @@ import org.jetbrains.annotations.Unmodifiable;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.CLASS_NAME; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.BAD_CHAR;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.CLASS_REFERENCE; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.COMMENT_DOC;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.FUNCTION_DECLARATION; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.ENUM_DECL;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.GLOBAL_VARIABLE; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.LABEL_DECL;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.KEYWORD; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.NAMESPACE_DECL;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.LABEL; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.PROPERTY;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.LINE_COMMENT; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.STRUCT_DECL;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.LOCAL_VARIABLE; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.TYPE_DECL;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.NUMBER; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.TYPE_DECL_GEN;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.OPERATION_SIGN; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.TYPE_REF;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.PARAMETER; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.PARAMETER;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.STATIC_FIELD; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.TYPE_REF_GEN;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.STATIC_METHOD; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.VARIABLE_DECL;
import static com.intellij.openapi.editor.DefaultLanguageHighlighterColors.STRING; import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.VARIABLE_REF;
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.ENUM_REF;
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.ENUM_MEMBER;
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.ERROR_TAG;
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.FUNCTION_REF;
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.KEYWORD;
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.COMMENT;
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.STRING;
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.NUMBER;
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.OPERATOR;
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.BUILTIN;
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.LABEL_REF;
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.NAMESPACE_REF;
import static com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.STRUCT_REF;
public enum ZigAttributes { public enum ZigAttributes {
Type(CLASS_NAME), Builtin(BUILTIN),
Parameter(PARAMETER), Comment_Doc(COMMENT_DOC, "documentation"),
Variable(LOCAL_VARIABLE), Comment(COMMENT),
Enum(GLOBAL_VARIABLE), Enum_Decl(ENUM_DECL, "declaration"),
EnumMember(GLOBAL_VARIABLE), Enum(ENUM_REF),
Field(STATIC_FIELD), EnumMember(ENUM_MEMBER),
ErrorTag(CLASS_REFERENCE), ErrorTag(ERROR_TAG),
Function(FUNCTION_DECLARATION), Property(PROPERTY),
Function_Decl_Gen(FUNCTION_REF, "declaration", "generic"),
Function_Decl(FUNCTION_REF, "declaration"),
Function_Gen(FUNCTION_REF, "generic"),
Function(FUNCTION_REF),
Keyword(KEYWORD), Keyword(KEYWORD),
Comment(LINE_COMMENT), KeywordLiteral(KEYWORD),
String(STRING), Label_Decl(LABEL_DECL, "declaration"),
Label(LABEL_REF),
Namespace_Decl(NAMESPACE_DECL, "declaration"),
Namespace(NAMESPACE_REF),
Number(NUMBER), Number(NUMBER),
Operator(OPERATION_SIGN), Operator(OPERATOR),
Builtin(STATIC_METHOD), Parameter_Decl(PARAMETER, "declaration"),
Label(LABEL), Parameter(PARAMETER),
KeywordLiteral(Keyword.KEY), String(STRING),
Namespace(CLASS_NAME), Struct_Decl(STRUCT_DECL, "declaration"),
Struct(CLASS_NAME); Struct(STRUCT_REF),
Type_Decl_Gen(TYPE_DECL_GEN, "declaration", "generic"),
Type_Decl(TYPE_DECL, "declaration"),
Type_Gen(TYPE_REF_GEN, "generic"),
Type(TYPE_REF),
Variable_Decl(VARIABLE_DECL, "declaration"),
Variable(VARIABLE_REF),
;
public final TextAttributesKey KEY; public final TextAttributesKey KEY;
public final String type; public final String type;
public final @Unmodifiable Set<String> modifiers; public final @Unmodifiable Set<String> modifiers;
@ -66,8 +93,8 @@ public enum ZigAttributes {
ZigAttributes(TextAttributesKey defaultKey, String... modifiers) { ZigAttributes(TextAttributesKey defaultKey, String... modifiers) {
var name = name(); var name = name();
int underscoreIndex = name.indexOf('_'); int underscoreIndex = name.indexOf('_');
type = (underscoreIndex >= 0 ? name.substring(0, underscoreIndex) : name).toLowerCase(Locale.ROOT); type = Character.toLowerCase(name.charAt(0)) + (underscoreIndex > 0 ? name.substring(1, underscoreIndex) : name.substring(1));
KEY = TextAttributesKey.createTextAttributesKey("ZIG_" + name.toUpperCase(Locale.ROOT), defaultKey); KEY = defaultKey;
this.modifiers = new HashSet<>(List.of(modifiers)); this.modifiers = new HashSet<>(List.of(modifiers));
} }
@ -81,9 +108,6 @@ public enum ZigAttributes {
return Optional.of(known.KEY); return Optional.of(known.KEY);
} }
} }
if (modifiers != null && modifiers.size() > 0) {
System.out.println(type + ": " + modifiers);
}
return Optional.empty(); return Optional.empty();
} }
} }

View file

@ -1,93 +0,0 @@
/*
* Copyright 2023 FalsePattern
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.falsepattern.zigbrains.zig.ide;
import com.falsepattern.zigbrains.common.Icons;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.PlainSyntaxHighlighter;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.ColorDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.Icon;
import java.util.Map;
public class ZigColorSettingsPage implements ColorSettingsPage {
private static final AttributesDescriptor[] DESCRIPTORS =
new AttributesDescriptor[]{new AttributesDescriptor("Builtin", ZigAttributes.Builtin.KEY),
new AttributesDescriptor("Comment", ZigAttributes.Comment.KEY),
new AttributesDescriptor("Enum", ZigAttributes.Enum.KEY),
new AttributesDescriptor("Enum member", ZigAttributes.EnumMember.KEY),
new AttributesDescriptor("Error tag", ZigAttributes.ErrorTag.KEY),
new AttributesDescriptor("Field", ZigAttributes.Field.KEY),
new AttributesDescriptor("Function", ZigAttributes.Function.KEY),
new AttributesDescriptor("Keyword//Regular", ZigAttributes.Keyword.KEY),
new AttributesDescriptor("Keyword//Literal", ZigAttributes.KeywordLiteral.KEY),
new AttributesDescriptor("Label", ZigAttributes.Label.KEY),
new AttributesDescriptor("Namespace", ZigAttributes.Namespace.KEY),
new AttributesDescriptor("Number", ZigAttributes.Number.KEY),
new AttributesDescriptor("Operator", ZigAttributes.Operator.KEY),
new AttributesDescriptor("Parameter", ZigAttributes.Parameter.KEY),
new AttributesDescriptor("String", ZigAttributes.String.KEY),
new AttributesDescriptor("Struct", ZigAttributes.Struct.KEY),
new AttributesDescriptor("Type", ZigAttributes.Type.KEY),
new AttributesDescriptor("Variable", ZigAttributes.Variable.KEY)};
@Nullable
@Override
public Icon getIcon() {
return Icons.ZIG;
}
@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
return new PlainSyntaxHighlighter();
}
@NotNull
@Override
public String getDemoText() {
return "Preview not yet implemented :/";
}
@Nullable
@Override
public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() {
return null;
}
@Override
public AttributesDescriptor @NotNull [] getAttributeDescriptors() {
return DESCRIPTORS;
}
@Override
public ColorDescriptor @NotNull [] getColorDescriptors() {
return ColorDescriptor.EMPTY_ARRAY;
}
@NotNull
@Override
public String getDisplayName() {
return "Zig";
}
}

View file

@ -0,0 +1,27 @@
/*
* Copyright 2023 FalsePattern
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.falsepattern.zigbrains.zig.lexer;
import com.intellij.lexer.FlexAdapter;
import com.intellij.lexer.FlexLexer;
import org.jetbrains.annotations.NotNull;
public class ZigLexerAdapter extends FlexAdapter {
public ZigLexerAdapter() {
super(new ZigFlexLexer(null));
}
}

View file

@ -17,48 +17,41 @@
package com.falsepattern.zigbrains.zig.parser; package com.falsepattern.zigbrains.zig.parser;
import com.falsepattern.zigbrains.zig.ZigLanguage; import com.falsepattern.zigbrains.zig.ZigLanguage;
import com.intellij.lang.ASTFactory; import com.falsepattern.zigbrains.zig.lexer.ZigLexerAdapter;
import com.falsepattern.zigbrains.zig.psi.ZigTypes;
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode;
import com.intellij.lang.ParserDefinition; import com.intellij.lang.ParserDefinition;
import com.intellij.lang.PsiParser; import com.intellij.lang.PsiParser;
import com.intellij.lexer.DummyLexer;
import com.intellij.lexer.Lexer; import com.intellij.lexer.Lexer;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.FileViewProvider; import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PlainTextTokenTypes;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.IFileElementType; import com.intellij.psi.tree.IFileElementType;
import com.intellij.psi.tree.TokenSet; import com.intellij.psi.tree.TokenSet;
import com.intellij.psi.util.PsiUtilCore;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class ZigParserDefinition implements ParserDefinition { public class ZigParserDefinition implements ParserDefinition {
public static final IFileElementType FILE = new IFileElementType(ZigLanguage.INSTANCE) { public static final IFileElementType FILE = new IFileElementType(ZigLanguage.INSTANCE);
public ASTNode parseContents(@NotNull ASTNode chameleon) {
final CharSequence chars = chameleon.getChars();
return ASTFactory.leaf(PlainTextTokenTypes.PLAIN_TEXT, chars);
}
};
@Override @Override
public @NotNull Lexer createLexer(Project project) { public @NotNull Lexer createLexer(Project project) {
return new DummyLexer(FILE); return new ZigLexerAdapter();
} }
@Override @Override
public @NotNull TokenSet getCommentTokens() { public @NotNull TokenSet getCommentTokens() {
return TokenSet.EMPTY; return ZigTokenSets.COMMENTS;
} }
@Override @Override
public @NotNull TokenSet getStringLiteralElements() { public @NotNull TokenSet getStringLiteralElements() {
return TokenSet.EMPTY; return ZigTokenSets.STRINGS;
} }
@Override @Override
public @NotNull PsiParser createParser(Project project) { public @NotNull PsiParser createParser(Project project) {
throw new UnsupportedOperationException("Not Supported"); return new ZigParser();
} }
@Override @Override
@ -73,6 +66,6 @@ public class ZigParserDefinition implements ParserDefinition {
@Override @Override
public @NotNull PsiElement createElement(ASTNode node) { public @NotNull PsiElement createElement(ASTNode node) {
return PsiUtilCore.NULL_PSI_ELEMENT; return ZigTypes.Factory.createElement(node);
} }
} }

View file

@ -0,0 +1,25 @@
/*
* Copyright 2023 FalsePattern
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.falsepattern.zigbrains.zig.parser;
import com.falsepattern.zigbrains.zig.psi.ZigTypes;
import com.intellij.psi.tree.TokenSet;
public interface ZigTokenSets {
TokenSet COMMENTS = TokenSet.create(ZigTypes.LINE_COMMENT, ZigTypes.DOC_COMMENT, ZigTypes.CONTAINER_DOC_COMMENT);
TokenSet STRINGS = TokenSet.create(ZigTypes.STRING_LITERAL);
}

View file

@ -0,0 +1,28 @@
/*
* Copyright 2023 FalsePattern
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.falsepattern.zigbrains.zig.psi;
import com.falsepattern.zigbrains.zig.ZigLanguage;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
public class ZigElementType extends IElementType {
public ZigElementType(@NonNls @NotNull String debugName) {
super(debugName, ZigLanguage.INSTANCE);
}
}

View file

@ -0,0 +1,28 @@
/*
* Copyright 2023 FalsePattern
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.falsepattern.zigbrains.zig.psi;
import com.falsepattern.zigbrains.zig.ZigLanguage;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
public class ZigTokenType extends IElementType {
public ZigTokenType(@NonNls @NotNull String debugName) {
super(debugName, ZigLanguage.INSTANCE);
}
}

View file

@ -90,7 +90,7 @@ public class HighlightingUtil {
if (end > documentLength - 1) { if (end > documentLength - 1) {
end = documentLength - 1; end = documentLength - 1;
} }
markup.addRangeHighlighter(edit.color(), edit.start(), end, HighlighterLayer.SYNTAX, markup.addRangeHighlighter(edit.color(), edit.start(), end, HighlighterLayer.ADDITIONAL_SYNTAX,
HighlighterTargetArea.EXACT_RANGE); HighlighterTargetArea.EXACT_RANGE);
} }
} }

View file

@ -69,7 +69,10 @@
<lang.parserDefinition language="Zig" <lang.parserDefinition language="Zig"
implementationClass="com.falsepattern.zigbrains.zig.parser.ZigParserDefinition"/> implementationClass="com.falsepattern.zigbrains.zig.parser.ZigParserDefinition"/>
<colorSettingsPage implementation="com.falsepattern.zigbrains.zig.ide.ZigColorSettingsPage"/> <colorSettingsPage implementation="com.falsepattern.zigbrains.zig.highlighter.ZigColorSettingsPage"/>
<lang.syntaxHighlighterFactory language="Zig"
implementationClass="com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighterFactory"/>
<applicationConfigurable parentId="language" <applicationConfigurable parentId="language"
instance="com.falsepattern.zigbrains.zig.settings.AppSettingsConfigurable" instance="com.falsepattern.zigbrains.zig.settings.AppSettingsConfigurable"