|
1 | 1 | use std::collections::HashSet;
|
2 | 2 |
|
3 |
| -use emmylua_code_analysis::{DbIndex, LuaDeclId, LuaDocument, SemanticModel}; |
| 3 | +use super::{EmmyAnnotator, EmmyAnnotatorType}; |
| 4 | +use crate::util::parse_desc; |
| 5 | +use emmylua_code_analysis::{DbIndex, LuaDeclId, LuaDocument, SemanticModel, WorkspaceId}; |
4 | 6 | use emmylua_parser::{
|
5 |
| - LuaAst, LuaAstNode, LuaAstToken, LuaForRangeStat, LuaForStat, LuaLocalFuncStat, LuaLocalStat, |
6 |
| - LuaNameExpr, LuaParamList, |
| 7 | + LuaAst, LuaAstNode, LuaAstToken, LuaDocDescription, LuaForRangeStat, LuaForStat, |
| 8 | + LuaLocalFuncStat, LuaLocalStat, LuaNameExpr, LuaParamList, |
7 | 9 | };
|
| 10 | +use emmylua_parser_desc::DescItemKind; |
8 | 11 | use rowan::TextRange;
|
9 | 12 |
|
10 |
| -use super::{EmmyAnnotator, EmmyAnnotatorType}; |
11 |
| - |
12 | 13 | pub fn build_annotators(semantic: &SemanticModel) -> Vec<EmmyAnnotator> {
|
13 | 14 | let mut result = vec![];
|
14 | 15 | let document = semantic.get_document();
|
@@ -59,6 +60,20 @@ pub fn build_annotators(semantic: &SemanticModel) -> Vec<EmmyAnnotator> {
|
59 | 60 | LuaAst::LuaNameExpr(name_expr) => {
|
60 | 61 | build_name_expr_annotator(&document, &mut use_range_set, &mut result, name_expr);
|
61 | 62 | }
|
| 63 | + LuaAst::LuaDocDescription(description) => { |
| 64 | + if semantic |
| 65 | + .get_emmyrc() |
| 66 | + .semantic_tokens |
| 67 | + .render_documentation_markup |
| 68 | + { |
| 69 | + build_description_annotator( |
| 70 | + &semantic, |
| 71 | + &mut use_range_set, |
| 72 | + &mut result, |
| 73 | + description, |
| 74 | + ); |
| 75 | + } |
| 76 | + } |
62 | 77 | _ => {}
|
63 | 78 | }
|
64 | 79 | }
|
@@ -291,3 +306,53 @@ fn build_local_func_stat_annotator(
|
291 | 306 |
|
292 | 307 | Some(())
|
293 | 308 | }
|
| 309 | + |
| 310 | +fn build_description_annotator( |
| 311 | + semantic_model: &SemanticModel, |
| 312 | + use_range_set: &mut HashSet<TextRange>, |
| 313 | + result: &mut Vec<EmmyAnnotator>, |
| 314 | + description: LuaDocDescription, |
| 315 | +) -> Option<()> { |
| 316 | + let document = semantic_model.get_document(); |
| 317 | + let text = document.get_text(); |
| 318 | + let items = parse_desc( |
| 319 | + semantic_model |
| 320 | + .get_module() |
| 321 | + .map(|m| m.workspace_id) |
| 322 | + .unwrap_or(WorkspaceId::MAIN), |
| 323 | + semantic_model.get_emmyrc(), |
| 324 | + text, |
| 325 | + description, |
| 326 | + None, |
| 327 | + ); |
| 328 | + |
| 329 | + let mut strong = EmmyAnnotator { |
| 330 | + typ: EmmyAnnotatorType::DocStrong, |
| 331 | + ranges: vec![], |
| 332 | + }; |
| 333 | + let mut em = EmmyAnnotator { |
| 334 | + typ: EmmyAnnotatorType::DocEm, |
| 335 | + ranges: vec![], |
| 336 | + }; |
| 337 | + |
| 338 | + for item in items { |
| 339 | + match item.kind { |
| 340 | + DescItemKind::Em => { |
| 341 | + use_range_set.insert(item.range.clone()); |
| 342 | + em.ranges.push(document.to_lsp_range(item.range.clone())?); |
| 343 | + } |
| 344 | + DescItemKind::Strong => { |
| 345 | + use_range_set.insert(item.range.clone()); |
| 346 | + strong |
| 347 | + .ranges |
| 348 | + .push(document.to_lsp_range(item.range.clone())?); |
| 349 | + } |
| 350 | + _ => {} |
| 351 | + } |
| 352 | + } |
| 353 | + |
| 354 | + result.push(em); |
| 355 | + result.push(strong); |
| 356 | + |
| 357 | + Some(()) |
| 358 | +} |
0 commit comments