Skip to content

Commit d330fbf

Browse files
committed
support codeblock highlight for vim and json, Default open md syntax for highlight
1 parent 05c9b98 commit d330fbf

File tree

22 files changed

+1293
-208
lines changed

22 files changed

+1293
-208
lines changed

crates/emmylua_code_analysis/resources/schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"default": {
5252
"knownTags": [],
5353
"privateName": [],
54-
"syntax": "none"
54+
"syntax": "md"
5555
}
5656
},
5757
"documentColor": {
@@ -125,7 +125,7 @@
125125
"$ref": "#/$defs/EmmyrcSemanticToken",
126126
"default": {
127127
"enable": true,
128-
"renderDocumentationMarkup": false
128+
"renderDocumentationMarkup": true
129129
}
130130
},
131131
"signature": {
@@ -640,7 +640,7 @@
640640
"syntax": {
641641
"description": "Syntax for highlighting documentation.",
642642
"$ref": "#/$defs/DocSyntax",
643-
"default": "none"
643+
"default": "md"
644644
}
645645
}
646646
},

crates/emmylua_code_analysis/src/config/configs/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ pub enum DocSyntax {
5050

5151
impl Default for DocSyntax {
5252
fn default() -> Self {
53-
DocSyntax::None
53+
DocSyntax::Md
5454
}
5555
}

crates/emmylua_code_analysis/src/config/configs/semantictoken.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl Default for EmmyrcSemanticToken {
1919
fn default() -> Self {
2020
Self {
2121
enable: default_true(),
22-
render_documentation_markup: false,
22+
render_documentation_markup: true,
2323
}
2424
}
2525
}

crates/emmylua_ls/src/handlers/configuration/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ pub async fn on_did_change_configuration(
1616
return Some(());
1717
}
1818

19-
if workspace_manager.client_config.client_id.is_vscode() {
19+
let client_id = workspace_manager.client_config.client_id;
20+
if client_id.is_vscode() {
2021
return Some(());
2122
}
22-
let client_id = workspace_manager.client_config.client_id;
23+
2324
drop(workspace_manager);
2425

2526
let supports_config_request = context
@@ -31,11 +32,11 @@ pub async fn on_did_change_configuration(
3132

3233
log::info!("change config client_id: {:?}", client_id);
3334
let new_client_config = get_client_config(&context, client_id, supports_config_request).await;
34-
let mut config_manager = context.workspace_manager.write().await;
35-
config_manager.client_config = new_client_config;
35+
let mut workspace_manager = context.workspace_manager.write().await;
36+
workspace_manager.client_config = new_client_config;
3637

3738
log::info!("reloading workspace folders");
38-
config_manager.reload_workspace().await;
39+
workspace_manager.reload_workspace().await;
3940
Some(())
4041
}
4142

crates/emmylua_ls/src/handlers/semantic_token/build_semantic_tokens.rs

Lines changed: 15 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use emmylua_parser::{
1313
LuaGeneralToken, LuaKind, LuaLiteralToken, LuaNameToken, LuaSyntaxKind, LuaSyntaxNode,
1414
LuaSyntaxToken, LuaTokenKind, LuaVarExpr,
1515
};
16-
use emmylua_parser_desc::{DescItem, DescItemKind};
16+
use emmylua_parser_desc::{CodeBlockHighlightKind, DescItem, DescItemKind};
1717
use lsp_types::{SemanticToken, SemanticTokenModifier, SemanticTokenType};
1818
use rowan::{NodeOrToken, TextRange, TextSize};
1919

@@ -831,63 +831,20 @@ fn render_desc_ranges(
831831
);
832832
pos = item.range.end();
833833
}
834-
DescItemKind::CodeBlockHl(lua_token_kind) => {
835-
let token_type = match lua_token_kind {
836-
LuaTokenKind::TkLongString | LuaTokenKind::TkString => {
837-
SemanticTokenType::STRING
838-
}
839-
LuaTokenKind::TkAnd
840-
| LuaTokenKind::TkBreak
841-
| LuaTokenKind::TkDo
842-
| LuaTokenKind::TkElse
843-
| LuaTokenKind::TkElseIf
844-
| LuaTokenKind::TkEnd
845-
| LuaTokenKind::TkFor
846-
| LuaTokenKind::TkFunction
847-
| LuaTokenKind::TkGoto
848-
| LuaTokenKind::TkIf
849-
| LuaTokenKind::TkIn
850-
| LuaTokenKind::TkNot
851-
| LuaTokenKind::TkOr
852-
| LuaTokenKind::TkRepeat
853-
| LuaTokenKind::TkReturn
854-
| LuaTokenKind::TkThen
855-
| LuaTokenKind::TkUntil
856-
| LuaTokenKind::TkWhile
857-
| LuaTokenKind::TkGlobal
858-
| LuaTokenKind::TkLocal => SemanticTokenType::KEYWORD,
859-
LuaTokenKind::TkPlus
860-
| LuaTokenKind::TkMinus
861-
| LuaTokenKind::TkMul
862-
| LuaTokenKind::TkDiv
863-
| LuaTokenKind::TkIDiv
864-
| LuaTokenKind::TkDot
865-
| LuaTokenKind::TkConcat
866-
| LuaTokenKind::TkEq
867-
| LuaTokenKind::TkGe
868-
| LuaTokenKind::TkLe
869-
| LuaTokenKind::TkNe
870-
| LuaTokenKind::TkShl
871-
| LuaTokenKind::TkShr
872-
| LuaTokenKind::TkLt
873-
| LuaTokenKind::TkGt
874-
| LuaTokenKind::TkMod
875-
| LuaTokenKind::TkPow
876-
| LuaTokenKind::TkLen
877-
| LuaTokenKind::TkBitAnd
878-
| LuaTokenKind::TkBitOr
879-
| LuaTokenKind::TkBitXor
880-
| LuaTokenKind::TkLeftBrace
881-
| LuaTokenKind::TkRightBrace
882-
| LuaTokenKind::TkLeftBracket
883-
| LuaTokenKind::TkRightBracket => SemanticTokenType::OPERATOR,
884-
LuaTokenKind::TkComplex | LuaTokenKind::TkInt | LuaTokenKind::TkFloat => {
885-
SemanticTokenType::NUMBER
886-
}
887-
LuaTokenKind::TkShortComment | LuaTokenKind::TkLongComment => {
888-
SemanticTokenType::COMMENT
889-
}
890-
_ => SemanticTokenType::VARIABLE,
834+
DescItemKind::CodeBlockHl(highlight_kind) => {
835+
let token_type = match highlight_kind {
836+
CodeBlockHighlightKind::Keyword => SemanticTokenType::KEYWORD,
837+
CodeBlockHighlightKind::String => SemanticTokenType::STRING,
838+
CodeBlockHighlightKind::Number => SemanticTokenType::NUMBER,
839+
CodeBlockHighlightKind::Comment => SemanticTokenType::COMMENT,
840+
CodeBlockHighlightKind::Function => SemanticTokenType::FUNCTION,
841+
CodeBlockHighlightKind::Class => SemanticTokenType::CLASS,
842+
CodeBlockHighlightKind::Enum => SemanticTokenType::ENUM,
843+
CodeBlockHighlightKind::Variable => SemanticTokenType::VARIABLE,
844+
CodeBlockHighlightKind::Property => SemanticTokenType::PROPERTY,
845+
CodeBlockHighlightKind::Decorator => SemanticTokenType::DECORATOR,
846+
CodeBlockHighlightKind::Operators => SemanticTokenType::OPERATOR,
847+
_ => continue, // Fallback for other kinds
891848
};
892849
builder.push_at_range(token_text, item.range, token_type, &[]);
893850
pos = item.range.end();

crates/emmylua_ls/src/handlers/semantic_token/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ pub async fn on_semantic_token_handler(
2323
let analysis = context.analysis.read().await;
2424
let file_id = analysis.get_file_id(&uri)?;
2525

26-
let config_manager = context.workspace_manager.read().await;
27-
let client_id = config_manager.client_config.client_id;
28-
let _ = config_manager;
26+
let workspace_manager = context.workspace_manager.read().await;
27+
let client_id = workspace_manager.client_config.client_id;
28+
let _ = workspace_manager;
2929

3030
semantic_token(&analysis, file_id, &context.client_capabilities, client_id)
3131
}

crates/emmylua_parser/src/lexer/lua_lexer.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
use crate::{LuaNonStdSymbol, kind::LuaTokenKind, parser_error::LuaParseError, text::Reader};
1+
use crate::{
2+
LexerState, LuaNonStdSymbol, kind::LuaTokenKind, parser_error::LuaParseError, text::Reader,
3+
};
24

35
use super::{is_name_continue, is_name_start, lexer_config::LexerConfig, token_data::LuaTokenData};
46

57
pub struct LuaLexer<'a> {
68
reader: Reader<'a>,
79
lexer_config: LexerConfig,
810
errors: Option<&'a mut Vec<LuaParseError>>,
9-
state: LuaLexerState,
10-
}
11-
12-
/// This enum allows preserving lexer state between reader resets. This is used
13-
/// when lexer doesn't see the whole input source, and only sees a reader
14-
/// for each individual line. It happens when we're lexing
15-
/// code blocks in comments.
16-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17-
pub enum LuaLexerState {
18-
Normal,
19-
String(char),
20-
LongString(usize),
21-
LongComment(usize),
11+
state: LexerState,
2212
}
2313

2414
impl<'a> LuaLexer<'a> {
@@ -27,12 +17,12 @@ impl<'a> LuaLexer<'a> {
2717
lexer_config: LexerConfig,
2818
errors: Option<&'a mut Vec<LuaParseError>>,
2919
) -> Self {
30-
Self::new_with_state(reader, LuaLexerState::Normal, lexer_config, errors)
20+
Self::new_with_state(reader, LexerState::Normal, lexer_config, errors)
3121
}
3222

3323
pub fn new_with_state(
3424
reader: Reader<'a>,
35-
state: LuaLexerState,
25+
state: LexerState,
3626
lexer_config: LexerConfig,
3727
errors: Option<&'a mut Vec<LuaParseError>>,
3828
) -> Self {
@@ -49,10 +39,10 @@ impl<'a> LuaLexer<'a> {
4939

5040
while !self.reader.is_eof() {
5141
let kind = match self.state {
52-
LuaLexerState::Normal => self.lex(),
53-
LuaLexerState::String(quote) => self.lex_string(quote),
54-
LuaLexerState::LongString(sep) => self.lex_long_string(sep),
55-
LuaLexerState::LongComment(sep) => {
42+
LexerState::Normal => self.lex(),
43+
LexerState::String(quote) => self.lex_string(quote),
44+
LexerState::LongString(sep) => self.lex_long_string(sep),
45+
LexerState::LongComment(sep) => {
5646
self.lex_long_string(sep);
5747
LuaTokenKind::TkLongComment
5848
}
@@ -67,7 +57,7 @@ impl<'a> LuaLexer<'a> {
6757
tokens
6858
}
6959

70-
pub fn get_state(&self) -> LuaLexerState {
60+
pub fn get_state(&self) -> LexerState {
7161
self.state
7262
}
7363

@@ -146,7 +136,7 @@ impl<'a> LuaLexer<'a> {
146136
let sep = self.skip_sep();
147137
if self.reader.current_char() == '[' {
148138
self.reader.bump();
149-
self.state = LuaLexerState::LongComment(sep);
139+
self.state = LexerState::LongComment(sep);
150140
self.lex_long_string(sep);
151141
return LuaTokenKind::TkLongComment;
152142
}
@@ -167,7 +157,7 @@ impl<'a> LuaLexer<'a> {
167157
}
168158

169159
self.reader.bump();
170-
self.state = LuaLexerState::LongString(sep);
160+
self.state = LexerState::LongString(sep);
171161
self.lex_long_string(sep)
172162
}
173163
'=' => {
@@ -253,7 +243,7 @@ impl<'a> LuaLexer<'a> {
253243
}
254244

255245
self.reader.bump();
256-
self.state = LuaLexerState::String(quote);
246+
self.state = LexerState::String(quote);
257247
self.lex_string(quote)
258248
}
259249
'.' => {
@@ -537,7 +527,7 @@ impl<'a> LuaLexer<'a> {
537527
}
538528

539529
if self.reader.current_char() == quote || !self.reader.is_eof() {
540-
self.state = LuaLexerState::Normal;
530+
self.state = LexerState::Normal;
541531
}
542532

543533
if self.reader.current_char() != quote {
@@ -569,7 +559,7 @@ impl<'a> LuaLexer<'a> {
569559
}
570560

571561
if end || !self.reader.is_eof() {
572-
self.state = LuaLexerState::Normal;
562+
self.state = LexerState::Normal;
573563
}
574564

575565
if !end {

crates/emmylua_parser/src/lexer/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod token_data;
66

77
pub use lexer_config::LexerConfig;
88
pub use lua_doc_lexer::{LuaDocLexer, LuaDocLexerState};
9-
pub use lua_lexer::{LuaLexer, LuaLexerState};
9+
pub use lua_lexer::LuaLexer;
1010
pub use token_data::LuaTokenData;
1111

1212
fn is_name_start(ch: char) -> bool {
@@ -16,3 +16,15 @@ fn is_name_start(ch: char) -> bool {
1616
fn is_name_continue(ch: char) -> bool {
1717
ch.is_alphanumeric() || ch == '_'
1818
}
19+
20+
/// This enum allows preserving lexer state between reader resets. This is used
21+
/// when lexer doesn't see the whole input source, and only sees a reader
22+
/// for each individual line. It happens when we're lexing
23+
/// code blocks in comments.
24+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25+
pub enum LexerState {
26+
Normal,
27+
String(char),
28+
LongString(usize),
29+
LongComment(usize),
30+
}

crates/emmylua_parser/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod syntax;
77
mod text;
88

99
pub use kind::*;
10-
pub use lexer::{LexerConfig, LuaLexer, LuaLexerState, LuaTokenData};
10+
pub use lexer::{LexerConfig, LexerState, LuaLexer, LuaTokenData};
1111
pub use parser::{LuaParser, ParserConfig, SpecialFunction};
1212
pub use parser_error::{LuaParseError, LuaParseErrorKind};
1313
pub use syntax::*;

crates/emmylua_parser_desc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ emmylua_parser.workspace = true
1616

1717
# external
1818
rowan.workspace = true
19-
unicode-general-category.workspace = true
19+
unicode-general-category.workspace = true

0 commit comments

Comments
 (0)