Skip to content

Commit a239e25

Browse files
committed
clean code
1 parent 66c5874 commit a239e25

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

crates/emmylua_ls/src/handlers/emmy_annotator/build_annotator.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ pub fn build_annotators(semantic: &SemanticModel) -> Vec<EmmyAnnotator> {
1616
let root = semantic.get_root();
1717
let db = semantic.get_db();
1818
let mut use_range_set = HashSet::new();
19+
let is_rendering_description = semantic
20+
.get_emmyrc()
21+
.semantic_tokens
22+
.render_documentation_markup;
1923
for node in root.descendants::<LuaAst>() {
2024
match node {
2125
LuaAst::LuaLocalStat(local_stat) => {
@@ -61,11 +65,7 @@ pub fn build_annotators(semantic: &SemanticModel) -> Vec<EmmyAnnotator> {
6165
build_name_expr_annotator(&document, &mut use_range_set, &mut result, name_expr);
6266
}
6367
LuaAst::LuaDocDescription(description) => {
64-
if semantic
65-
.get_emmyrc()
66-
.semantic_tokens
67-
.render_documentation_markup
68-
{
68+
if is_rendering_description {
6969
build_description_annotator(
7070
&semantic,
7171
&mut use_range_set,

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use super::{
44
use crate::context::ClientId;
55
use crate::util::parse_desc;
66
use emmylua_code_analysis::{
7-
LuaDecl, LuaDeclExtra, LuaMemberId, LuaMemberOwner, LuaSemanticDeclId, LuaType, LuaTypeDeclId,
8-
SemanticDeclLevel, SemanticModel, WorkspaceId, check_export_visibility,
7+
Emmyrc, LuaDecl, LuaDeclExtra, LuaMemberId, LuaMemberOwner, LuaSemanticDeclId, LuaType,
8+
LuaTypeDeclId, SemanticDeclLevel, SemanticModel, WorkspaceId, check_export_visibility,
99
parse_require_module_info,
1010
};
1111
use emmylua_parser::{
@@ -21,6 +21,7 @@ pub fn build_semantic_tokens(
2121
semantic_model: &mut SemanticModel,
2222
support_muliline_token: bool,
2323
client_id: ClientId,
24+
emmyrc: &Emmyrc,
2425
) -> Option<Vec<SemanticToken>> {
2526
let root = semantic_model.get_root();
2627
let document = semantic_model.get_document();
@@ -34,10 +35,16 @@ pub fn build_semantic_tokens(
3435
for node_or_token in root.syntax().descendants_with_tokens() {
3536
match node_or_token {
3637
NodeOrToken::Node(node) => {
37-
build_node_semantic_token(semantic_model, &mut builder, node);
38+
build_node_semantic_token(semantic_model, &mut builder, node, emmyrc);
3839
}
3940
NodeOrToken::Token(token) => {
40-
build_tokens_semantic_token(semantic_model, &mut builder, &token, client_id);
41+
build_tokens_semantic_token(
42+
semantic_model,
43+
&mut builder,
44+
&token,
45+
client_id,
46+
emmyrc,
47+
);
4148
}
4249
}
4350
}
@@ -50,6 +57,7 @@ fn build_tokens_semantic_token(
5057
builder: &mut SemanticBuilder,
5158
token: &LuaSyntaxToken,
5259
client_id: ClientId,
60+
emmyrc: &Emmyrc,
5361
) {
5462
match token.kind().into() {
5563
LuaTokenKind::TkLongString | LuaTokenKind::TkString => {
@@ -164,10 +172,7 @@ fn build_tokens_semantic_token(
164172
let rendering_description = token
165173
.parent()
166174
.is_some_and(|parent| parent.kind() == LuaSyntaxKind::DocDescription.into());
167-
let description_parsing_is_enabled = semantic_model
168-
.get_emmyrc()
169-
.semantic_tokens
170-
.render_documentation_markup;
175+
let description_parsing_is_enabled = emmrc.semantic_tokens.render_documentation_markup;
171176

172177
if !(rendering_description && description_parsing_is_enabled) {
173178
builder.push(token, SemanticTokenType::COMMENT);
@@ -232,6 +237,7 @@ fn build_node_semantic_token(
232237
semantic_model: &SemanticModel,
233238
builder: &mut SemanticBuilder,
234239
node: LuaSyntaxNode,
240+
emmyrc: &Emmyrc,
235241
) -> Option<()> {
236242
match LuaAst::cast(node)? {
237243
LuaAst::LuaDocTagClass(doc_class) => {
@@ -590,11 +596,7 @@ fn build_node_semantic_token(
590596
_ => {}
591597
},
592598
LuaAst::LuaDocDescription(description) => {
593-
if !semantic_model
594-
.get_emmyrc()
595-
.semantic_tokens
596-
.render_documentation_markup
597-
{
599+
if !emmyrc.semantic_tokens.render_documentation_markup {
598600
for token in description.tokens::<LuaGeneralToken>() {
599601
if matches!(
600602
token.get_token_kind(),
@@ -614,7 +616,7 @@ fn build_node_semantic_token(
614616
.get_module()
615617
.map(|m| m.workspace_id)
616618
.unwrap_or(WorkspaceId::MAIN),
617-
semantic_model.get_emmyrc(),
619+
emmyrc,
618620
text,
619621
description,
620622
None,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ pub fn semantic_token(
3737
client_id: ClientId,
3838
) -> Option<SemanticTokensResult> {
3939
let mut semantic_model = analysis.compilation.get_semantic_model(file_id)?;
40-
if !semantic_model.get_emmyrc().semantic_tokens.enable {
40+
let emmyrc = semantic_model.get_emmyrc();
41+
if !emmyrc.semantic_tokens.enable {
4142
return None;
4243
}
4344

4445
let result = build_semantic_tokens(
4546
&mut semantic_model,
4647
supports_multiline_tokens(client_capabilities),
4748
client_id,
49+
emmyrc,
4850
)?;
4951

5052
Some(SemanticTokensResult::Tokens(SemanticTokens {

0 commit comments

Comments
 (0)