diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2023-11-12 01:34:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-12 01:34:37 +0100 |
| commit | 6216b0f2a35e547791bbfc22fc566bbdb5ea45a7 (patch) | |
| tree | c8868fcdf990604ff2ed8aa4ef654b1104b0d679 | |
| parent | 917ec762e61ff126181e8b518caf40c9a0bfa421 (diff) | |
| parent | 0893d513faed43174e331547429973d135f24dea (diff) | |
Merge pull request #269 from laytan/private-doc-tags
respect //+private and the file/package variant
| -rw-r--r-- | src/common/ast.odin | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/src/common/ast.odin b/src/common/ast.odin index df78041..9adc57c 100644 --- a/src/common/ast.odin +++ b/src/common/ast.odin @@ -198,10 +198,10 @@ collect_value_decl :: proc( skip_private: bool, ) { if value_decl, ok := stmt.derived.(^ast.Value_Decl); ok { - is_deprecated := false + is_deprecated := false is_private_file := false - is_package_file := false - is_builtin := false + is_private_pkg := false + is_builtin := false for attribute in value_decl.attributes { for elem in attribute.elems { @@ -215,10 +215,10 @@ collect_value_decl :: proc( case "\"file\"": is_private_file = true case "package": - is_package_file = true + is_private_pkg = true } } else { - is_package_file = true + is_private_pkg = true } } } @@ -229,7 +229,7 @@ collect_value_decl :: proc( case "builtin": is_builtin = true case "private": - is_package_file = true + is_private_pkg = true } } } @@ -238,6 +238,25 @@ collect_value_decl :: proc( if is_private_file && skip_private { return } + + // If a private status is not explicitly set with an attribute above the declaration + // check the file comment. + if !is_private_file && !is_private_pkg && file.docs != nil { + for comment in file.docs.list { + txt := comment.text + if strings.has_prefix(txt, "//+private") { + txt = strings.trim_prefix(txt, "//+private") + is_private_pkg = true + + if strings.has_prefix(txt, " ") { + txt = strings.trim_space(txt) + if txt == "file" { + is_private_file = true + } + } + } + } + } for name, i in value_decl.names { str := get_ast_node_string(name, file.src) @@ -254,7 +273,7 @@ collect_value_decl :: proc( attributes = value_decl.attributes[:], deprecated = is_deprecated, builtin = is_builtin, - package_private = is_package_file, + package_private = is_private_pkg, }, ) } else { @@ -270,7 +289,7 @@ collect_value_decl :: proc( attributes = value_decl.attributes[:], deprecated = is_deprecated, builtin = is_builtin, - package_private = is_package_file, + package_private = is_private_pkg, }, ) } |