diff options
-rw-r--r-- | changelog.md | 7 | ||||
-rw-r--r-- | locale/en-us/script.lua | 2 | ||||
-rw-r--r-- | locale/en-us/setting.lua | 2 | ||||
-rw-r--r-- | locale/pt-br/script.lua | 2 | ||||
-rw-r--r-- | locale/pt-br/setting.lua | 2 | ||||
-rw-r--r-- | locale/zh-cn/script.lua | 2 | ||||
-rw-r--r-- | locale/zh-cn/setting.lua | 2 | ||||
-rw-r--r-- | locale/zh-tw/script.lua | 2 | ||||
-rw-r--r-- | locale/zh-tw/setting.lua | 2 | ||||
-rw-r--r-- | script/config/template.lua | 1 | ||||
-rw-r--r-- | script/core/diagnostics/invisible.lua | 14 | ||||
-rw-r--r-- | script/core/hover/description.lua | 5 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 14 | ||||
-rw-r--r-- | script/vm/visible.lua | 5 | ||||
-rw-r--r-- | test/crossfile/diagnostic.lua | 25 |
15 files changed, 79 insertions, 8 deletions
diff --git a/changelog.md b/changelog.md index 29607ee4..50972610 100644 --- a/changelog.md +++ b/changelog.md @@ -1,13 +1,13 @@ # changelog ## 3.6.0 -* `NEW` supports `private`/`protected`/`public` +* `NEW` supports `private`/`protected`/`public`/`package` * mark in `doc.field` ```lua ---@class unit ---@field private uuid integer ``` - * mark with `---@private` and `---@protected` + * mark with `---@private`, `---@protected`, `---@public` and `---@package` ```lua ---@class unit local mt = {} @@ -20,7 +20,7 @@ function mt:update() end ``` - * mark by settings `Lua.doc.privateName` and `Lua.doc.protectedName` + * mark by settings `Lua.doc.privateName`, `Lua.doc.protectedName` and `Lua.doc.packageName` ```lua ---@class unit ---@field _uuid integer --> treat as private when `Lua.doc.privateName` has `"_*"` @@ -30,6 +30,7 @@ * `Lua.diagnostics.workspaceEvent`: [#1626] set the time to trigger workspace diagnostics. * `Lua.doc.privateName`: treat matched fields as private * `Lua.doc.protectedName`: treat matched fields as protected + * `Lua.doc.packageName`: treat matched fields as package * `NEW` CLI `--doc [path]` to make docs. server will generate `doc.json` and `doc.md` in `LOGPATH`. `doc.md` is generated by `doc.json` by example code `script/cli/doc2md.lua`. diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua index 5aa93a4c..5a6a5c9b 100644 --- a/locale/en-us/script.lua +++ b/locale/en-us/script.lua @@ -148,6 +148,8 @@ DIAG_INVISIBLE_PRIVATE = 'Field `{field}` is private, it can only be accessed in class `{class}`.' DIAG_INVISIBLE_PROTECTED = 'Field `{field}` is protected, it can only be accessed in class `{class}` and its subclasses.' +DIAG_INVISIBLE_PACKAGE = +'Field `{field}` can only be accessed in same file `{uri}`.' MWS_NOT_SUPPORT = '{} does not support multi workspace for now, I may need to restart to support the new workspace ...' diff --git a/locale/en-us/setting.lua b/locale/en-us/setting.lua index ea786117..13334fc3 100644 --- a/locale/en-us/setting.lua +++ b/locale/en-us/setting.lua @@ -299,6 +299,8 @@ config.doc.privateName = '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.' config.doc.protectedName = 'Treat specific field names as protected, e.g. `m_*` means `XXX.m_id` and `XXX.m_type` are protected, witch can only be accessed in the class where the definition is located and its subclasses.' +config.doc.packageName = +'Treat specific field names as package, e.g. `m_*` means `XXX.m_id` and `XXX.m_type` are package, witch can only be accessed in the file where the definition is located.' config.diagnostics['unused-local'] = 'Enable unused local variable diagnostics.' config.diagnostics['unused-function'] = diff --git a/locale/pt-br/script.lua b/locale/pt-br/script.lua index e58dc201..be084abb 100644 --- a/locale/pt-br/script.lua +++ b/locale/pt-br/script.lua @@ -148,6 +148,8 @@ DIAG_INVISIBLE_PRIVATE = -- TODO: need translate! 'Field `{field}` is private, it can only be accessed in class `{class}`.' DIAG_INVISIBLE_PROTECTED = -- TODO: need translate! 'Field `{field}` is protected, it can only be accessed in class `{class}` and its subclasses.' +DIAG_INVISIBLE_PACKAGE = -- TODO: need translate! +'Field `{field}` can only be accessed in same file `{uri}`.' MWS_NOT_SUPPORT = '{} não é suportado múltiplos espaços de trabalho por enquanto, posso precisar reiniciar para estabelecer um novo espaço de trabalho ...' diff --git a/locale/pt-br/setting.lua b/locale/pt-br/setting.lua index 2844d646..8770548f 100644 --- a/locale/pt-br/setting.lua +++ b/locale/pt-br/setting.lua @@ -299,6 +299,8 @@ config.doc.privateName = -- TODO: need translate! '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.' config.doc.protectedName = -- TODO: need translate! 'Treat specific field names as protected, e.g. `m_*` means `XXX.m_id` and `XXX.m_type` are protected, witch can only be accessed in the class where the definition is located and its subclasses.' +config.doc.packageName = -- TODO: need translate! +'Treat specific field names as package, e.g. `m_*` means `XXX.m_id` and `XXX.m_type` are package, witch can only be accessed in the file where the definition is located.' config.diagnostics['unused-local'] = -- TODO: need translate! '未使用的局部变量' config.diagnostics['unused-function'] = -- TODO: need translate! diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua index 02511e3b..532b6908 100644 --- a/locale/zh-cn/script.lua +++ b/locale/zh-cn/script.lua @@ -148,6 +148,8 @@ DIAG_INVISIBLE_PRIVATE = '字段 `{field}` 是私有的,只能在 `{class}` 类中才能访问。' DIAG_INVISIBLE_PROTECTED = '字段 `{field}` 受到保护,只能在 `{class}` 类极其子类中才能访问。' +DIAG_INVISIBLE_PACKAGE = +'字段 `{field}` 只能在相同的文件 `{uri}` 中才能访问。' MWS_NOT_SUPPORT = '{} 目前还不支持多工作目录,我可能需要重启才能支持新的工作目录...' diff --git a/locale/zh-cn/setting.lua b/locale/zh-cn/setting.lua index 3f57f995..2bf5f9a6 100644 --- a/locale/zh-cn/setting.lua +++ b/locale/zh-cn/setting.lua @@ -298,6 +298,8 @@ config.doc.privateName = '将特定名称的字段视为私有,例如 `m_*` 意味着 `XXX.m_id` 与 `XXX.m_type` 是私有字段,只能在定义所在的类中访问。' config.doc.protectedName = '将特定名称的字段视为受保护,例如 `m_*` 意味着 `XXX.m_id` 与 `XXX.m_type` 是受保护的字段,只能在定义所在的类极其子类中访问。' +config.doc.packageName = +'将特定名称的字段视为package,例如 `m_*` 意味着 `XXX.m_id` 与 `XXX.m_type` 只能在定义所在的文件中访问。' config.diagnostics['unused-local'] = '未使用的局部变量' config.diagnostics['unused-function'] = diff --git a/locale/zh-tw/script.lua b/locale/zh-tw/script.lua index b76d2fd1..0f753381 100644 --- a/locale/zh-tw/script.lua +++ b/locale/zh-tw/script.lua @@ -148,6 +148,8 @@ DIAG_INVISIBLE_PRIVATE = -- TODO: need translate! 'Field `{field}` is private, it can only be accessed in class `{class}`.' DIAG_INVISIBLE_PROTECTED = -- TODO: need translate! 'Field `{field}` is protected, it can only be accessed in class `{class}` and its subclasses.' +DIAG_INVISIBLE_PACKAGE = -- TODO: need translate! +'Field `{field}` can only be accessed in same file `{uri}`.' MWS_NOT_SUPPORT = '{} 目前還不支援多工作目錄,我可能需要重新啟動才能支援新的工作目錄...' diff --git a/locale/zh-tw/setting.lua b/locale/zh-tw/setting.lua index cf0c2a4c..a2c34e29 100644 --- a/locale/zh-tw/setting.lua +++ b/locale/zh-tw/setting.lua @@ -298,6 +298,8 @@ config.doc.privateName = -- TODO: need translate! '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.' config.doc.protectedName = -- TODO: need translate! 'Treat specific field names as protected, e.g. `m_*` means `XXX.m_id` and `XXX.m_type` are protected, witch can only be accessed in the class where the definition is located and its subclasses.' +config.doc.packageName = -- TODO: need translate! +'Treat specific field names as package, e.g. `m_*` means `XXX.m_id` and `XXX.m_type` are package, witch can only be accessed in the file where the definition is located.' config.diagnostics['unused-local'] = '未使用的區域變數' config.diagnostics['unused-function'] = diff --git a/script/config/template.lua b/script/config/template.lua index dfdfab56..ea79c2d3 100644 --- a/script/config/template.lua +++ b/script/config/template.lua @@ -392,6 +392,7 @@ local template = { ['Lua.type.weakNilCheck'] = Type.Boolean >> false, ['Lua.doc.privateName'] = Type.Array(Type.String), ['Lua.doc.protectedName'] = Type.Array(Type.String), + ['Lua.doc.packageName'] = Type.Array(Type.String), -- VSCode ['files.associations'] = Type.Hash(Type.String, Type.String), diff --git a/script/core/diagnostics/invisible.lua b/script/core/diagnostics/invisible.lua index 0bd369a4..7172c4a5 100644 --- a/script/core/diagnostics/invisible.lua +++ b/script/core/diagnostics/invisible.lua @@ -37,7 +37,7 @@ return function (uri, callback) class = vm.getParentClass(def):getName(), }), } - else + elseif vm.getVisibleType(def) == 'protected' then callback { start = child.start, finish = child.finish, @@ -47,6 +47,18 @@ return function (uri, callback) class = vm.getParentClass(def):getName(), }), } + elseif vm.getVisibleType(def) == 'package' then + callback { + start = child.start, + finish = child.finish, + uri = uri, + message = lang.script('DIAG_INVISIBLE_PACKAGE', { + field = key, + uri = guide.getUri(def), + }), + } + else + error('Unknown visible type: ' .. vm.getVisibleType(def)) end break end diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index 74720bdf..f8b0694d 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -142,7 +142,10 @@ local function lookUpDocComments(source) for _, doc in ipairs(docGroup) do if doc.type == 'doc.comment' then lines[#lines+1] = normalizeComment(doc.comment.text, uri) - elseif doc.type == 'doc.type' then + elseif doc.type == 'doc.type' + or doc.type == 'doc.public' + or doc.type == 'doc.protected' + or doc.type == 'doc.private' then if doc.comment then lines[#lines+1] = normalizeComment(doc.comment.text, uri) end diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 8a671dbc..0e560b0d 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -992,7 +992,8 @@ local docSwitch = util.switch() if value == 'public' or value == 'protected' or value == 'private' - or value == 'public' then + or value == 'public' + or value == 'package' then result.visible = value result.start = getStart() return true @@ -1470,6 +1471,14 @@ local docSwitch = util.switch() finish = getFinish(), } end) + : case 'package' + : call(function () + return { + type = 'doc.package', + start = getFinish(), + finish = getFinish(), + } + end) local function convertTokens(doc) local tp, text = nextToken() @@ -1688,7 +1697,8 @@ local function bindDoc(source, binded) or doc.type == 'doc.source' or doc.type == 'doc.private' or doc.type == 'doc.protected' - or doc.type == 'doc.public' then + or doc.type == 'doc.public' + or doc.type == 'doc.package' then if source.type == 'function' or isParam then goto CONTINUE diff --git a/script/vm/visible.lua b/script/vm/visible.lua index 1b0726ee..9d667744 100644 --- a/script/vm/visible.lua +++ b/script/vm/visible.lua @@ -4,7 +4,7 @@ local guide = require 'parser.guide' local config = require 'config' local glob = require 'glob' ----@alias parser.visibleType 'public' | 'protected' | 'private' +---@alias parser.visibleType 'public' | 'protected' | 'private' | 'package' ---@class parser.object ---@field public _visibleType? parser.visibleType @@ -128,6 +128,9 @@ function vm.isVisible(parent, field) if visible == 'public' then return true end + if visible == 'package' then + return guide.getUri(parent) == guide.getUri(field) + end local class = vm.getParentClass(field) if not class then return true diff --git a/test/crossfile/diagnostic.lua b/test/crossfile/diagnostic.lua index dd06351f..e574204a 100644 --- a/test/crossfile/diagnostic.lua +++ b/test/crossfile/diagnostic.lua @@ -140,3 +140,28 @@ TEST { content = 'require "f.a"', }, } + +TEST { + { path = 'a.lua', content = [[ + ---@class A + ---@field package x string + + ---@type A + local obj + + print(obj.x) + ]]}, +} + +TEST { + { path = 'a.lua', content = [[ + ---@class A + ---@field package x string + ]]}, + { path = 'b.lua', content = [[ + ---@type A + local obj + + print(obj.<!x!>) + ]]} +} |