diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-23 16:46:35 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-23 16:46:35 +0800 |
commit | 5619f5aec549eb931c1c7727702afc89e6672ad9 (patch) | |
tree | e3f7148622ef95b5816333f61d03d8f0fe44048a | |
parent | 28a21f6f3988c0bb2022748e8f8daae236d80f5c (diff) | |
download | lua-language-server-5619f5aec549eb931c1c7727702afc89e6672ad9.zip |
检测循环class
-rw-r--r-- | script-beta/core/diagnostics/circle-doc-class.lua | 54 | ||||
-rw-r--r-- | script-beta/proto/define.lua | 1 | ||||
-rw-r--r-- | test-beta/diagnostics/init.lua | 2 |
3 files changed, 56 insertions, 1 deletions
diff --git a/script-beta/core/diagnostics/circle-doc-class.lua b/script-beta/core/diagnostics/circle-doc-class.lua new file mode 100644 index 00000000..55179447 --- /dev/null +++ b/script-beta/core/diagnostics/circle-doc-class.lua @@ -0,0 +1,54 @@ +local files = require 'files' +local guide = require 'parser.guide' +local lang = require 'language' +local define = require 'proto.define' +local vm = require 'vm' + +return function (uri, callback) + local state = files.getAst(uri) + if not state then + return + end + + if not state.ast.docs then + return + end + + for _, doc in ipairs(state.ast.docs) do + if doc.type == 'doc.class' then + if not doc.extends then + goto CONTINUE + end + local myName = guide.getName(doc) + local list = { doc } + local mark = {} + for i = 1, 999 do + local current = list[i] + if not current then + goto CONTINUE + end + if current.extends then + local newName = current.extends[1] + if newName == myName then + callback { + start = doc.start, + finish = doc.finish, + message = lang.script('DIAG_CIRCLE_DOC_CLASS', myName) + } + goto CONTINUE + end + if not mark[newName] then + mark[newName] = true + local docs = vm.getDocTypes(newName) + for _, otherDoc in ipairs(docs) do + if otherDoc.type == 'doc.class.name' then + list[#list+1] = otherDoc.parent + end + end + end + end + end + ::CONTINUE:: + end + end +end diff --git a/script-beta/proto/define.lua b/script-beta/proto/define.lua index fdb38c6f..5d737ce1 100644 --- a/script-beta/proto/define.lua +++ b/script-beta/proto/define.lua @@ -132,6 +132,7 @@ m.DiagnosticDefaultSeverity = { ['duplicate-doc-class'] = 'Warning', ['undefined-doc-name'] = 'Warning', + ['circle-doc-class'] = 'Warning', } --- 诊断报告标签 diff --git a/test-beta/diagnostics/init.lua b/test-beta/diagnostics/init.lua index d17aebbb..649a6c9b 100644 --- a/test-beta/diagnostics/init.lua +++ b/test-beta/diagnostics/init.lua @@ -634,13 +634,13 @@ TEST [[ ---@class A : <!B!> ]] -do return end TEST [[ ---@class <!A : B!> ---@class <!B : C!> ---@class <!C : D!> ---@class <!D : A!> ]] +do return end TEST [[ ---@class A : B |