Skip to content

Commit 66c5874

Browse files
authored
Merge pull request #665 from taminomara/doc-hl
Support highlighting Markdown/RST in comments
2 parents 93abfc8 + 8d610ec commit 66c5874

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+7706
-305
lines changed

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ members = [
99
# local
1010
emmylua_code_analysis = { path = "crates/emmylua_code_analysis", version = "0.10.0" }
1111
emmylua_parser = { path = "crates/emmylua_parser", version = "0.12.0" }
12+
emmylua_parser_desc = { path = "crates/emmylua_parser_desc", version = "0.12.0" }
1213
emmylua_diagnostic_macro = { path = "crates/emmylua_diagnostic_macro", version = "0.5.0" }
1314

1415
# external
@@ -51,3 +52,4 @@ ansi_term = "0.12.1"
5152
num-traits = { version = "0.2", features = ["std"] }
5253
mimalloc = "0.1.47"
5354
googletest = "0.14.2"
55+
unicode-general-category = "1.0.0"

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@
7979

8080
Our project is meticulously organized into specialized crates, each serving a critical role in the Lua analysis ecosystem:
8181

82-
| Crate | Badge | Description |
83-
| ----- | ----- | ----------- |
84-
| [🔍 **emmylua_parser**](./crates/emmylua_parser) | [![emmylua_parser](https://img.shields.io/crates/v/emmylua_parser.svg?style=flat-square)](https://crates.io/crates/emmylua_parser) | The foundational Rust-based Lua parser engineered for maximum efficiency and accuracy. Powers all downstream analysis tools. |
82+
| Crate | Badge | Description |
83+
|----------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------| ----------- |
84+
| [🔍 **emmylua_parser**](./crates/emmylua_parser) | [![emmylua_parser](https://img.shields.io/crates/v/emmylua_parser.svg?style=flat-square)](https://crates.io/crates/emmylua_parser) | The foundational Rust-based Lua parser engineered for maximum efficiency and accuracy. Powers all downstream analysis tools. |
85+
| [📑 **emmylua_parser_desc**](./crates/emmylua_parser_desc) | [![emmylua_parser_desc](https://img.shields.io/crates/v/emmylua_parser_desc.svg?style=flat-square)](https://crates.io/crates/emmylua_parser_desc) | Extension for EmmyLua-Parser that handles Markdown/RST highlighting in comments. |
8586
| [🧠 **emmylua_code_analysis**](./crates/emmylua_code_analysis) | [![emmylua_code_analysis](https://img.shields.io/crates/v/emmylua_code_analysis.svg?style=flat-square)](https://crates.io/crates/emmylua_code_analysis) | Advanced semantic analysis engine providing deep code understanding, type inference, and cross-reference resolution. |
86-
| [🖥️ **emmylua_ls**](./crates/emmylua_ls) | [![emmylua_ls](https://img.shields.io/crates/v/emmylua_ls.svg?style=flat-square)](https://crates.io/crates/emmylua_ls) | The complete Language Server Protocol implementation offering rich IDE features across all major editors. |
87-
| [📚 **emmylua_doc_cli**](./crates/emmylua_doc_cli/) | [![emmylua_doc_cli](https://img.shields.io/crates/v/emmylua_doc_cli.svg?style=flat-square)](https://crates.io/crates/emmylua_doc_cli) | Professional documentation generator creating beautiful, searchable API docs from your Lua code and annotations. |
88-
| [**emmylua_check**](./crates/emmylua_check) | [![emmylua_check](https://img.shields.io/crates/v/emmylua_check.svg?style=flat-square)](https://crates.io/crates/emmylua_check) | Comprehensive static analysis tool for code quality assurance, catching bugs before they reach production. |
87+
| [🖥️ **emmylua_ls**](./crates/emmylua_ls) | [![emmylua_ls](https://img.shields.io/crates/v/emmylua_ls.svg?style=flat-square)](https://crates.io/crates/emmylua_ls) | The complete Language Server Protocol implementation offering rich IDE features across all major editors. |
88+
| [📚 **emmylua_doc_cli**](./crates/emmylua_doc_cli/) | [![emmylua_doc_cli](https://img.shields.io/crates/v/emmylua_doc_cli.svg?style=flat-square)](https://crates.io/crates/emmylua_doc_cli) | Professional documentation generator creating beautiful, searchable API docs from your Lua code and annotations. |
89+
| [**emmylua_check**](./crates/emmylua_check) | [![emmylua_check](https://img.shields.io/crates/v/emmylua_check.svg?style=flat-square)](https://crates.io/crates/emmylua_check) | Comprehensive static analysis tool for code quality assurance, catching bugs before they reach production. |
8990

9091

9192
---

crates/emmylua_code_analysis/resources/schema.json

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"$ref": "#/$defs/EmmyrcDoc",
5151
"default": {
5252
"knownTags": [],
53-
"privateName": []
53+
"privateName": [],
54+
"syntax": "none"
5455
}
5556
},
5657
"documentColor": {
@@ -123,7 +124,8 @@
123124
"semanticTokens": {
124125
"$ref": "#/$defs/EmmyrcSemanticToken",
125126
"default": {
126-
"enable": true
127+
"enable": true,
128+
"renderDocumentationMarkup": false
127129
}
128130
},
129131
"signature": {
@@ -442,6 +444,15 @@
442444
}
443445
]
444446
},
447+
"DocSyntax": {
448+
"type": "string",
449+
"enum": [
450+
"none",
451+
"md",
452+
"myst",
453+
"rst"
454+
]
455+
},
445456
"EmmyrcCodeAction": {
446457
"type": "object",
447458
"properties": {
@@ -611,6 +622,25 @@
611622
"items": {
612623
"type": "string"
613624
}
625+
},
626+
"rstDefaultRole": {
627+
"description": "When `syntax` is `Myst` or `Rst`, specifies default role used\nwith RST processor.",
628+
"type": [
629+
"string",
630+
"null"
631+
]
632+
},
633+
"rstPrimaryDomain": {
634+
"description": "When `syntax` is `Myst` or `Rst`, specifies primary domain used\nwith RST processor.",
635+
"type": [
636+
"string",
637+
"null"
638+
]
639+
},
640+
"syntax": {
641+
"description": "Syntax for highlighting documentation.",
642+
"$ref": "#/$defs/DocSyntax",
643+
"default": "none"
614644
}
615645
}
616646
},
@@ -934,6 +964,12 @@
934964
"type": "boolean",
935965
"default": true,
936966
"x-vscode-setting": true
967+
},
968+
"renderDocumentationMarkup": {
969+
"description": "Render Markdown/RST in documentation. Set `doc.syntax` for this option to have effect.",
970+
"type": "boolean",
971+
"default": false,
972+
"x-vscode-setting": true
937973
}
938974
}
939975
},

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,52 @@ use serde::{Deserialize, Serialize};
44
#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)]
55
#[serde(rename_all = "camelCase")]
66
pub struct EmmyrcDoc {
7-
#[serde(default)]
87
/// Treat specific field names as private, e.g. `m_*` means `XXX.m_id` and `XXX.m_type` are private, witch can only be accessed in the class where the definition is located.
8+
#[serde(default)]
99
pub private_name: Vec<String>,
1010

1111
/// List of known documentation tags.
1212
#[serde(default)]
1313
pub known_tags: Vec<String>,
14+
15+
/// Syntax for highlighting documentation.
16+
#[serde(default)]
17+
pub syntax: DocSyntax,
18+
19+
/// When `syntax` is `Myst` or `Rst`, specifies primary domain used
20+
/// with RST processor.
21+
#[serde(skip_serializing_if = "Option::is_none")]
22+
pub rst_primary_domain: Option<String>,
23+
24+
/// When `syntax` is `Myst` or `Rst`, specifies default role used
25+
/// with RST processor.
26+
#[serde(skip_serializing_if = "Option::is_none")]
27+
pub rst_default_role: Option<String>,
1428
}
1529

1630
impl Default for EmmyrcDoc {
1731
fn default() -> Self {
1832
Self {
1933
private_name: Default::default(),
2034
known_tags: Default::default(),
35+
syntax: Default::default(),
36+
rst_primary_domain: None,
37+
rst_default_role: None,
2138
}
2239
}
2340
}
41+
42+
#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)]
43+
#[serde(rename_all = "kebab-case")]
44+
pub enum DocSyntax {
45+
None,
46+
Md,
47+
Myst,
48+
Rst,
49+
}
50+
51+
impl Default for DocSyntax {
52+
fn default() -> Self {
53+
DocSyntax::None
54+
}
55+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use code_action::EmmyrcCodeAction;
2020
pub use codelen::EmmyrcCodeLens;
2121
pub use completion::{EmmyrcCompletion, EmmyrcFilenameConvention};
2222
pub use diagnostics::EmmyrcDiagnostic;
23-
pub use doc::EmmyrcDoc;
23+
pub use doc::{DocSyntax, EmmyrcDoc};
2424
pub use document_color::EmmyrcDocumentColor;
2525
pub use hover::EmmyrcHover;
2626
pub use inlayhint::EmmyrcInlayHint;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ pub struct EmmyrcSemanticToken {
88
#[serde(default = "default_true")]
99
#[schemars(extend("x-vscode-setting" = true))]
1010
pub enable: bool,
11+
12+
/// Render Markdown/RST in documentation. Set `doc.syntax` for this option to have effect.
13+
#[serde(default)]
14+
#[schemars(extend("x-vscode-setting" = true))]
15+
pub render_documentation_markup: bool,
1116
}
1217

1318
impl Default for EmmyrcSemanticToken {
1419
fn default() -> Self {
1520
Self {
1621
enable: default_true(),
22+
render_documentation_markup: false,
1723
}
1824
}
1925
}

crates/emmylua_code_analysis/src/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ use std::{
99

1010
pub use crate::config::configs::{EmmyrcExternalTool, EmmyrcReformat};
1111
pub use config_loader::{load_configs, load_configs_raw};
12+
pub use configs::{DocSyntax, EmmyrcFilenameConvention, EmmyrcLuaVersion};
1213
use configs::{
1314
EmmyrcCodeAction, EmmyrcCodeLens, EmmyrcCompletion, EmmyrcDiagnostic, EmmyrcDoc,
1415
EmmyrcDocumentColor, EmmyrcHover, EmmyrcInlayHint, EmmyrcInlineValues, EmmyrcReference,
1516
EmmyrcResource, EmmyrcRuntime, EmmyrcSemanticToken, EmmyrcSignature, EmmyrcStrict,
1617
EmmyrcWorkspace,
1718
};
18-
pub use configs::{EmmyrcFilenameConvention, EmmyrcLuaVersion};
1919
use emmylua_parser::{LuaLanguageLevel, LuaNonStdSymbolSet, ParserConfig, SpecialFunction};
2020
use regex::Regex;
2121
use rowan::NodeCache;

crates/emmylua_code_analysis/src/semantic/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub use visibility::check_export_visibility;
4040
use visibility::check_visibility;
4141

4242
use crate::semantic::member::find_members_with_key;
43-
use crate::{Emmyrc, LuaDocument, LuaSemanticDeclId, db_index::LuaTypeDeclId};
43+
use crate::{Emmyrc, LuaDocument, LuaSemanticDeclId, ModuleInfo, db_index::LuaTypeDeclId};
4444
use crate::{
4545
FileId,
4646
db_index::{DbIndex, LuaType},
@@ -87,6 +87,10 @@ impl<'a> SemanticModel<'a> {
8787
self.db.get_vfs().get_document(&self.file_id).unwrap()
8888
}
8989

90+
pub fn get_module(&self) -> Option<&ModuleInfo> {
91+
self.db.get_module_index().get_module(self.file_id)
92+
}
93+
9094
pub fn get_document_by_file_id(&self, file_id: FileId) -> Option<LuaDocument> {
9195
self.db.get_vfs().get_document(&file_id)
9296
}
@@ -256,6 +260,10 @@ impl<'a> SemanticModel<'a> {
256260
&self.emmyrc
257261
}
258262

263+
pub fn get_emmyrc_arc(&self) -> Arc<Emmyrc> {
264+
self.emmyrc.clone()
265+
}
266+
259267
pub fn get_root(&self) -> &LuaChunk {
260268
&self.root
261269
}

crates/emmylua_ls/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ categories = ["development-tools"]
1414
# local
1515
emmylua_code_analysis.workspace = true
1616
emmylua_parser.workspace = true
17+
emmylua_parser_desc.workspace = true
1718

1819
# external
1920
lsp-server.workspace = true

0 commit comments

Comments
 (0)