Skip to content

Commit 8fe6a1b

Browse files
committed
add config: doc.privateName
1 parent 2faff7f commit 8fe6a1b

File tree

6 files changed

+90
-1
lines changed

6 files changed

+90
-1
lines changed

crates/emmylua_code_analysis/resources/schema.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
"severity": {}
4747
}
4848
},
49+
"doc": {
50+
"$ref": "#/$defs/EmmyrcDoc",
51+
"default": {
52+
"privateName": []
53+
}
54+
},
4955
"documentColor": {
5056
"$ref": "#/$defs/EmmyrcDocumentColor",
5157
"default": {
@@ -542,6 +548,19 @@
542548
}
543549
}
544550
},
551+
"EmmyrcDoc": {
552+
"type": "object",
553+
"properties": {
554+
"privateName": {
555+
"description": "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.",
556+
"type": "array",
557+
"default": [],
558+
"items": {
559+
"type": "string"
560+
}
561+
}
562+
}
563+
},
545564
"EmmyrcDocumentColor": {
546565
"type": "object",
547566
"properties": {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use schemars::JsonSchema;
2+
use serde::{Deserialize, Serialize};
3+
4+
#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)]
5+
#[serde(rename_all = "camelCase")]
6+
pub struct EmmyrcDoc {
7+
#[serde(default)]
8+
/// 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.
9+
pub private_name: Vec<String>,
10+
}
11+
12+
impl Default for EmmyrcDoc {
13+
fn default() -> Self {
14+
Self {
15+
private_name: Default::default(),
16+
}
17+
}
18+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mod semantictoken;
1313
mod signature;
1414
mod strict;
1515
mod workspace;
16+
mod doc;
1617

1718
pub use code_action::EmmyrcCodeAction;
1819
pub use codelen::EmmyrcCodeLen;
@@ -29,3 +30,4 @@ pub use semantictoken::EmmyrcSemanticToken;
2930
pub use signature::EmmyrcSignature;
3031
pub use strict::EmmyrcStrict;
3132
pub use workspace::EmmyrcWorkspace;
33+
pub use doc::EmmyrcDoc;

crates/emmylua_code_analysis/src/config/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub use configs::EmmyrcFilenameConvention;
1212
pub use configs::EmmyrcLuaVersion;
1313
use configs::{EmmyrcCodeAction, EmmyrcDocumentColor};
1414
use configs::{
15-
EmmyrcCodeLen, EmmyrcCompletion, EmmyrcDiagnostic, EmmyrcHover, EmmyrcInlayHint,
15+
EmmyrcCodeLen, EmmyrcCompletion, EmmyrcDiagnostic, EmmyrcDoc, EmmyrcHover, EmmyrcInlayHint,
1616
EmmyrcInlineValues, EmmyrcReference, EmmyrcResource, EmmyrcRuntime, EmmyrcSemanticToken,
1717
EmmyrcSignature, EmmyrcStrict, EmmyrcWorkspace,
1818
};
@@ -58,6 +58,8 @@ pub struct Emmyrc {
5858
pub code_action: EmmyrcCodeAction,
5959
#[serde(default)]
6060
pub inline_values: EmmyrcInlineValues,
61+
#[serde(default)]
62+
pub doc: EmmyrcDoc,
6163
}
6264

6365
impl Emmyrc {

crates/emmylua_code_analysis/src/semantic/visibility/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,36 @@ pub fn check_visibility(
5959
}
6060
}
6161

62+
if let LuaSemanticDeclId::Member(member_id) = property_owner {
63+
if let Some(member) = db.get_member_index().get_member(&member_id) {
64+
if let Some(name) = member.get_key().get_name() {
65+
let config = emmyrc;
66+
for pattern in &config.doc.private_name {
67+
let is_match = if let Some(prefix) = pattern.strip_suffix('*') {
68+
name.starts_with(prefix)
69+
} else if let Some(suffix) = pattern.strip_prefix('*') {
70+
name.ends_with(suffix)
71+
} else {
72+
name == pattern
73+
};
74+
if is_match {
75+
return Some(
76+
check_visibility_by_visibility(
77+
db,
78+
infer_config,
79+
file_id,
80+
property_owner,
81+
token,
82+
VisibilityKind::Private,
83+
)
84+
.unwrap_or(false),
85+
);
86+
}
87+
}
88+
}
89+
}
90+
}
91+
6292
Some(true)
6393
}
6494

crates/emmylua_ls/src/handlers/inlay_hint/build_function_hint.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ fn get_type_location(semantic_model: &SemanticModel, typ: &LuaType) -> Option<Lo
160160
let lsp_range = document.to_lsp_range(location.range)?;
161161
Some(Location::new(document.get_uri(), lsp_range))
162162
}
163+
LuaType::Generic(generic) => {
164+
let base_type_id = generic.get_base_type_id();
165+
get_type_location(semantic_model, &LuaType::Ref(base_type_id))
166+
}
163167
LuaType::Array(base) => get_type_location(semantic_model, base),
164168
LuaType::Any => get_base_type_location(semantic_model, "any"),
165169
LuaType::Nil => get_base_type_location(semantic_model, "nil"),
@@ -207,6 +211,20 @@ fn hint_humanize_type(semantic_model: &SemanticModel, typ: &LuaType, level: Rend
207211
id.get_name().to_string()
208212
}
209213
}
214+
LuaType::Generic(generic) => {
215+
let base_type_id = generic.get_base_type_id();
216+
let base_type_name =
217+
hint_humanize_type(semantic_model, &LuaType::Ref(base_type_id), level);
218+
219+
let generic_params = generic
220+
.get_params()
221+
.iter()
222+
.map(|ty| hint_humanize_type(semantic_model, ty, level.next_level()))
223+
.collect::<Vec<_>>()
224+
.join(",");
225+
226+
format!("{}<{}>", base_type_name, generic_params)
227+
}
210228
LuaType::Union(union) => hint_humanize_union_type(semantic_model, union, level),
211229
_ => humanize_type(semantic_model.get_db(), typ, level),
212230
}

0 commit comments

Comments
 (0)