Skip to content

Commit 5367a27

Browse files
committed
feat: add internal tag
This commit introduces the `internal` tag to mark items with internal visibility. Note that the usage of `---@field internal xx integer` is not supported, as "internal" is already reserved for field names.
1 parent 6516718 commit 5367a27

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

crates/emmylua_code_analysis/src/db_index/module/mod.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,19 @@ impl LuaModuleIndex {
409409
}
410410

411411
pub fn is_std(&self, file_id: &FileId) -> bool {
412-
self.get_std_file_ids().contains(file_id)
412+
if let Some(module_info) = self.file_module_map.get(file_id) {
413+
return module_info.workspace_id == WorkspaceId::STD;
414+
}
415+
416+
false
417+
}
418+
419+
pub fn is_library(&self, file_id: &FileId) -> bool {
420+
if let Some(module_info) = self.file_module_map.get(file_id) {
421+
return module_info.workspace_id.is_library();
422+
}
423+
424+
false
413425
}
414426

415427
pub fn get_main_workspace_file_ids(&self) -> Vec<FileId> {
@@ -447,6 +459,14 @@ impl LuaModuleIndex {
447459

448460
false
449461
}
462+
463+
pub fn get_workspace_id(&self, file_id: FileId) -> Option<WorkspaceId> {
464+
if let Some(module_info) = self.file_module_map.get(&file_id) {
465+
return Some(module_info.workspace_id);
466+
}
467+
468+
None
469+
}
450470
}
451471

452472
impl LuaIndex for LuaModuleIndex {

crates/emmylua_code_analysis/src/diagnostic/checker/access_invisible.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ fn report_reason(
125125
VisibilityKind::Package => {
126126
t!("The property is package-private and cannot be accessed outside the package.")
127127
}
128+
VisibilityKind::Internal => {
129+
t!("The property is internal and cannot be accessed outside the module.")
130+
}
128131
_ => {
129132
return None;
130133
}

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,32 @@ pub fn check_visibility(
2626

2727
if let Some(visibility) = property.visibility {
2828
match visibility {
29-
VisibilityKind::None |
30-
// this donot use
31-
VisibilityKind::Internal |
32-
VisibilityKind::Public => return Some(true),
33-
VisibilityKind::Protected |
34-
VisibilityKind::Private => {
35-
return Some(check_visibility_by_visibility(db, infer_config, file_id, property_owner, token, visibility).unwrap_or(false));
36-
},
29+
VisibilityKind::None | VisibilityKind::Public => return Some(true),
30+
VisibilityKind::Protected | VisibilityKind::Private => {
31+
return Some(
32+
check_visibility_by_visibility(
33+
db,
34+
infer_config,
35+
file_id,
36+
property_owner,
37+
token,
38+
visibility,
39+
)
40+
.unwrap_or(false),
41+
);
42+
}
3743
VisibilityKind::Package => {
3844
return Some(file_id == property_owner.get_file_id()?);
39-
},
45+
}
46+
VisibilityKind::Internal => {
47+
let property_file_id = property_owner.get_file_id()?;
48+
let property_workspace_id =
49+
db.get_module_index().get_workspace_id(property_file_id)?;
50+
let current_workspace_id = db.get_module_index().get_workspace_id(file_id)?;
51+
if current_workspace_id != property_workspace_id {
52+
return Some(false);
53+
}
54+
}
4055
}
4156
}
4257

crates/emmylua_ls/src/handlers/completion/data/doc_tags.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub const DOC_TAGS: &[&str] = &[
1717
"protected",
1818
"private",
1919
"package",
20+
"internal",
2021
"meta",
2122
"diagnostic",
2223
"version",

crates/emmylua_parser/src/lexer/lua_doc_lexer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,9 @@ fn to_tag(text: &str) -> LuaTokenKind {
555555
"async" => LuaTokenKind::TkTagAsync,
556556
"cast" => LuaTokenKind::TkTagCast,
557557
"deprecated" => LuaTokenKind::TkTagDeprecated,
558-
"private" | "protected" | "public" | "package" => LuaTokenKind::TkTagVisibility,
558+
"private" | "protected" | "public" | "package" | "internal" => {
559+
LuaTokenKind::TkTagVisibility
560+
}
559561
"readonly" => LuaTokenKind::TkTagReadonly,
560562
"diagnostic" => LuaTokenKind::TkTagDiagnostic,
561563
"meta" => LuaTokenKind::TkTagMeta,

0 commit comments

Comments
 (0)