Skip to content

Commit a9d58fb

Browse files
committed
update semantic token
1 parent a7b090e commit a9d58fb

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,16 @@ fn build_tokens_semantic_token(
118118
builder.push(token, SemanticTokenType::OPERATOR);
119119
}
120120
LuaTokenKind::TkLeftBrace | LuaTokenKind::TkRightBrace => {
121-
builder.push(token, SemanticTokenType::OPERATOR);
121+
if let Some(parent) = token.parent()
122+
&& !matches!(
123+
parent.kind().into(),
124+
LuaSyntaxKind::TableArrayExpr
125+
| LuaSyntaxKind::TableEmptyExpr
126+
| LuaSyntaxKind::TableFieldAssign
127+
)
128+
{
129+
builder.push(token, SemanticTokenType::OPERATOR);
130+
}
122131
}
123132
LuaTokenKind::TkColon => {
124133
if let Some(parent) = token.parent()
@@ -128,11 +137,27 @@ fn build_tokens_semantic_token(
128137
}
129138
}
130139
// delimiter
131-
LuaTokenKind::TkLeftBracket
132-
| LuaTokenKind::TkRightBracket
133-
| LuaTokenKind::TkLeftParen
134-
| LuaTokenKind::TkRightParen => {
135-
if client_id.is_neovim() {
140+
LuaTokenKind::TkLeftBracket | LuaTokenKind::TkRightBracket => {
141+
if let Some(parent) = token.parent()
142+
&& matches!(
143+
parent.kind().into(),
144+
LuaSyntaxKind::TableFieldAssign | LuaSyntaxKind::IndexExpr
145+
)
146+
{
147+
builder.push(token, CustomSemanticTokenType::DELIMITER);
148+
} else {
149+
builder.push(token, SemanticTokenType::OPERATOR);
150+
}
151+
}
152+
LuaTokenKind::TkLeftParen | LuaTokenKind::TkRightParen => {
153+
if let Some(parent) = token.parent()
154+
&& matches!(
155+
parent.kind().into(),
156+
LuaSyntaxKind::ParamList
157+
| LuaSyntaxKind::CallArgList
158+
| LuaSyntaxKind::ParenExpr
159+
)
160+
{
136161
builder.push(token, CustomSemanticTokenType::DELIMITER);
137162
} else {
138163
builder.push(token, SemanticTokenType::OPERATOR);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use lsp_types::{
1111
SemanticTokensOptions, SemanticTokensParams, SemanticTokensResult,
1212
SemanticTokensServerCapabilities, ServerCapabilities,
1313
};
14-
pub use semantic_token_builder::{SEMANTIC_TOKEN_MODIFIERS, SEMANTIC_TOKEN_TYPES};
14+
#[allow(unused)]
15+
pub use semantic_token_builder::{
16+
CustomSemanticTokenType, SEMANTIC_TOKEN_MODIFIERS, SEMANTIC_TOKEN_TYPES,
17+
};
1518
use tokio_util::sync::CancellationToken;
1619

1720
use super::RegisterCapabilities;

crates/emmylua_ls/src/handlers/test/semantic_token_test.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#[cfg(test)]
22
mod tests {
3-
use crate::handlers::test_lib::{ProviderVirtualWorkspace, VirtualSemanticToken, check};
3+
use crate::handlers::{
4+
semantic_token::CustomSemanticTokenType,
5+
test_lib::{ProviderVirtualWorkspace, VirtualSemanticToken, check},
6+
};
47
use googletest::prelude::*;
58
use lsp_types::{SemanticTokenModifier, SemanticTokenType};
69
use std::collections::HashSet;
@@ -90,7 +93,7 @@ mod tests {
9093
line: 4,
9194
start: 32,
9295
length: 1,
93-
token_type: SemanticTokenType::OPERATOR,
96+
token_type: CustomSemanticTokenType::DELIMITER,
9497
token_modifier: HashSet::new(),
9598
},
9699
VirtualSemanticToken {
@@ -104,7 +107,7 @@ mod tests {
104107
line: 4,
105108
start: 34,
106109
length: 1,
107-
token_type: SemanticTokenType::OPERATOR,
110+
token_type: CustomSemanticTokenType::DELIMITER,
108111
token_modifier: HashSet::new(),
109112
},
110113
VirtualSemanticToken {
@@ -153,7 +156,7 @@ mod tests {
153156
line: 4,
154157
start: 54,
155158
length: 1,
156-
token_type: SemanticTokenType::OPERATOR,
159+
token_type: CustomSemanticTokenType::DELIMITER,
157160
token_modifier: HashSet::new(),
158161
},
159162
VirtualSemanticToken {
@@ -167,7 +170,7 @@ mod tests {
167170
line: 4,
168171
start: 56,
169172
length: 1,
170-
token_type: SemanticTokenType::OPERATOR,
173+
token_type: CustomSemanticTokenType::DELIMITER,
171174
token_modifier: HashSet::new(),
172175
},
173176
],

0 commit comments

Comments
 (0)