diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-25 18:21:40 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-25 18:21:40 +0800 |
commit | c848377b107594759492c6ba6566705c9821df32 (patch) | |
tree | 1adec8c9a1d1638bacd23d0658c1c62d6188b72c | |
parent | 0e12a5a4ad223393a76827ffdd39d27ca3db4bd9 (diff) | |
download | lua-language-server-c848377b107594759492c6ba6566705c9821df32.zip |
更新诊断
-rw-r--r-- | script-beta/core/diagnostics/duplicate-doc-field.lua | 34 | ||||
-rw-r--r-- | script-beta/core/diagnostics/undefined-doc-class.lua | 16 | ||||
-rw-r--r-- | script-beta/parser/luadoc.lua | 2 | ||||
-rw-r--r-- | script-beta/proto/define.lua | 1 | ||||
-rw-r--r-- | test-beta/diagnostics/init.lua | 2 | ||||
-rw-r--r-- | test-beta/hover/init.lua | 816 | ||||
-rw-r--r-- | test-beta/rename/init.lua | 40 |
7 files changed, 502 insertions, 409 deletions
diff --git a/script-beta/core/diagnostics/duplicate-doc-field.lua b/script-beta/core/diagnostics/duplicate-doc-field.lua new file mode 100644 index 00000000..b621fd9e --- /dev/null +++ b/script-beta/core/diagnostics/duplicate-doc-field.lua @@ -0,0 +1,34 @@ +local files = require 'files' +local lang = require 'language' + +return function (uri, callback) + local state = files.getAst(uri) + if not state then + return + end + + if not state.ast.docs then + return + end + + local mark + for _, group in ipairs(state.ast.docs.groups) do + for _, doc in ipairs(group) do + if doc.type == 'doc.class' then + mark = {} + elseif doc.type == 'doc.field' then + if mark then + local name = doc.field[1] + if mark[name] then + callback { + start = doc.field.start, + finish = doc.field.finish, + message = lang.script('DIAG_DUPLICATE_DOC_FIELD', name), + } + end + mark[name] = true + end + end + end + end +end diff --git a/script-beta/core/diagnostics/undefined-doc-class.lua b/script-beta/core/diagnostics/undefined-doc-class.lua index bbfdceec..f3381039 100644 --- a/script-beta/core/diagnostics/undefined-doc-class.lua +++ b/script-beta/core/diagnostics/undefined-doc-class.lua @@ -4,6 +4,19 @@ local lang = require 'language' local define = require 'proto.define' local vm = require 'vm' +local builtin = { + ['any'] = true, + ['nil'] = true, + ['boolean'] = true, + ['number'] = true, + ['integer'] = true, + ['thread'] = true, + ['table'] = true, + ['file'] = true, + ['string'] = true, + ['function'] = true, +} + return function (uri, callback) local state = files.getAst(uri) if not state then @@ -22,6 +35,9 @@ return function (uri, callback) goto CONTINUE end local name = ext[1] + if builtin[name] then + goto CONTINUE + end local docs = vm.getDocTypes(name) if cache[name] == nil then cache[name] = false diff --git a/script-beta/parser/luadoc.lua b/script-beta/parser/luadoc.lua index 9c9ea113..c55484cf 100644 --- a/script-beta/parser/luadoc.lua +++ b/script-beta/parser/luadoc.lua @@ -720,6 +720,7 @@ local function bindDocs(state) if not isNextLine(lns, binded, doc) then bindDoc(state, lns, binded) binded = {} + state.ast.docs.groups[#state.ast.docs.groups+1] = binded end binded[#binded+1] = doc end @@ -735,6 +736,7 @@ return function (_, state) ast.docs = { type = 'doc', parent = ast, + groups = {}, } pushError = state.pushError diff --git a/script-beta/proto/define.lua b/script-beta/proto/define.lua index f69660cf..92403518 100644 --- a/script-beta/proto/define.lua +++ b/script-beta/proto/define.lua @@ -137,6 +137,7 @@ m.DiagnosticDefaultSeverity = { ['undefined-doc-param'] = 'Warning', ['duplicate-doc-param'] = 'Warning', ['doc-field-no-class'] = 'Warning', + ['duplicate-doc-field'] = 'Warning', } --- 诊断报告标签 diff --git a/test-beta/diagnostics/init.lua b/test-beta/diagnostics/init.lua index f8cfa39a..b1801083 100644 --- a/test-beta/diagnostics/init.lua +++ b/test-beta/diagnostics/init.lua @@ -714,7 +714,7 @@ TEST [[ TEST [[ ---@class Class ----@field <!x!> Class +---@field x Class ---@field <!x!> Class ]] diff --git a/test-beta/hover/init.lua b/test-beta/hover/init.lua index f06afbfc..182474e0 100644 --- a/test-beta/hover/init.lua +++ b/test-beta/hover/init.lua @@ -842,411 +842,411 @@ local <?x?> <close> = 1 local x <close>: integer = 1 ]] ---TEST[[ ------@class Class ---local <?x?> = class() ---]] ---[[ ---local x: *Class {} ---]] --- ---TEST[[ ------@class Class ---<?x?> = class() ---]] ---[[ ---global x: *Class {} ---]] --- ---TEST[[ ---local t = { --- ---@class Class --- <?x?> = class() ---} ---]] ---[[ ---field x: *Class {} ---]] --- ---TEST[[ ------@type Class ---local <?x?> = class() ---]] ---[[ ---local x: *Class {} ---]] --- ---TEST[[ ------@type Class ---<?x?> = class() ---]] ---[[ ---global x: *Class {} ---]] --- ---TEST[[ ---local t = { --- ---@type Class --- <?x?> = class() ---} ---]] ---[[ ---field x: *Class {} ---]] --- ---TEST[[ ------@type A|B|C ---local <?x?> = class() ---]] ---[[ ---local x: *A|B|C {} ---]] --- ---TEST[[ ------@class Class ---local <?x?> = { --- b = 1 ---} ---]] ---[[ ---local x: *Class { --- b: number = 1, ---} ---]] --- ---TEST [[ ------@class Class ---local mt = {} --- ------@param t Class ---function f(<?t?>) ---end ---]] ---[[ ---local t: *Class {} ---]] --- ---TEST [[ ------@class Class ---local mt = {} --- ------@param t Class ---function f(t) --- print(<?t?>) ---end ---]] ---[[ ---local t: *Class {} ---]] --- ---TEST [[ ------@class Class ---local mt = {} --- ------@param t Class ---function f(t) ---end --- ---f(<?s?>) ---]] ---[[ ---global s: *Class {} ---]] --- ---TEST [[ ------@class Class --- ------@param k Class ---for <?k?> in pairs(t) do ---end ---]] ---[[ ---local k<key>: *Class {} ---]] --- ---TEST [[ ------@class Class --- ------@param v Class ---for k, <?v?> in pairs(t) do ---end ---]] ---[[ ---local v<value>: *Class {} ---]] --- ---TEST [[ ------@return A|B ------@return C ---local function <?f?>() ---end ---]] ---[[ ---function f() --- -> A|B, C ---]] --- ---TEST [[ ------@generic T ------@param x T ------@return T ---local function f(x) ---end --- ---local <?r?> = f(1) ---]] ---[[ ---local r: number ---]] --- ---TEST [[ ------@param x number ------@param y boolean ---local function <?f?>(x, y) ---end ---]] ---[[ ---function f(x: number, y: boolean) ---]] --- ---TEST [[ ------@vararg Class ---local function f(...) --- local _, <?x?> = ... ---end ---f(1, 2, 3) ---]] ---[[ ---local x: *Class = 2 ---]] --- ---TEST [[ ------@vararg Class ---local function f(...) --- local _, <?x?> = ... ---end ---]] ---[[ ---local x: *Class {} ---]] --- ---TEST [[ ------@type string[] ---local <?x?> ---]] ---[[ ---local x: { --- [*integer]: string, ---} ---]] --- ---TEST [[ ------@type (string|boolean)[] ---local <?x?> ---]] ---[[ ---local x: { --- [*integer]: string|boolean, ---} ---]] --- ---TEST [[ ------@type string[] ---local t ---local <?x?> = t[1] ---]] ---[[ ---local x: string ---]] --- ---TEST [[ ------@type string[] ---local t ---for _, <?x?> in ipairs(t) do ---end ---]] ---[[ ---local x: string ---]] --- ---TEST [[ ------@type string[] ---local t ---for _, <?x?> in pairs(t) do ---end ---]] ---[[ ---local x: string ---]] --- ---TEST [[ ------@type string[] ---local t ---for <?k?>, v in pairs(t) do ---end ---]] ---[[ ---local k: integer ---]] --- ---TEST [[ ------@type table<ClassA, ClassB> ---local <?x?> ---]] ---[[ ---local x: { --- [*ClassA]: ClassB, ---} ---]] --- ---TEST [[ ------@type table<ClassA, ClassB> ---local t ---for _, <?x?> in pairs(t) do ---end ---]] ---[[ ---local x: *ClassB ---]] --- ---TEST [[ ------@type table<ClassA, ClassB> ---local t ---for <?k?>, v in pairs(t) do ---end ---]] ---[[ ---local k: *ClassA ---]] --- ---TEST [[ ------@type fun(x: number, y: number):boolean ---local <?f?> ---]] ---[[ ---function f(x: number, y: number) --- -> boolean ---]] --- ---TEST [[ ------@type fun(x: number, y: number):boolean ---local f ---f(<?a?>) ---]] ---[[ ---global a: number ---]] --- ---TEST [[ ------@type fun(x: number, y: number):boolean ---local f ---local <?r?> = f() ---]] ---[[ ---local r: boolean ---]] --- ---TEST [[ ------@param f fun():void ---function t(<?f?>) end ---]] ---[[ ---function () --- -> void ---]] --- ---TEST [[ ------@type fun(a:any, b:any) ---local f ---local t = {f = f} ---t:<?f?>() ---]] ---[[ ---function f(b: any) --- -> any ---]] --- ---TEST [[ ------@param names string[] ---local function f(<?names?>) ---end ---]] ---[[ ---local names: { --- [*integer]: string, ---} ---]] --- ---TEST [[ ------@return any ---function <?f?>() --- ---@type integer --- local a --- return a ---end ---]] ---[[ ---function f() --- -> any ---]] --- ---TEST [[ ------@return any ---function f() --- ---@type integer --- local a --- return a ---end --- ---local <?x?> = f() ---]] ---[[ ---local x: any ---]] --- --- ---TEST [[ ------@param x number {optional = 'after'} ------@param y boolean {optional = 'self'} ------@param z string ---function <?f?>(x, y, z) end ---]] ---[=[ ---function f([x: number [, y: boolean], z: string]) ---]=] --- ---TEST [[ ------@return string {name = 'key'} ------@return string {name = 'value'} ---function <?f?>() end ---]] ---[=[ ---function f() --- -> key: string, value: string ---]=] --- ---TEST [[ ------@return {name = 'x', optional = 'after'} ------@return string {name = 'y', optional = 'self'} ------@return string {name = 'z'} ---function <?f?>() end ---]] ---[=[ ---function f() --- -> [x: any [, y: string], z: string] ---]=] --- ---TEST [[ ------@return {name = 'x', optional = 'after'} ------@return string {name = 'y', optional = 'self'} ------@return string {name = 'z'} ---function f() --- return function (a, b) --- end ---end --- ---<?f2?> = f() ---]] ---[=[ ---function f2(a: any, b: any) ---]=] +TEST[[ +---@class Class +local <?x?> = class() +]] +[[ +local x: Class {} +]] + +TEST[[ +---@class Class +<?x?> = class() +]] +[[ +global x: Class {} +]] + +TEST[[ +local t = { + ---@class Class + <?x?> = class() +} +]] +[[ +field x: Class {} +]] + +TEST[[ +---@type Class +local <?x?> = class() +]] +[[ +local x: Class {} +]] + +TEST[[ +---@type Class +<?x?> = class() +]] +[[ +global x: Class {} +]] + +TEST[[ +local t = { + ---@type Class + <?x?> = class() +} +]] +[[ +field x: Class {} +]] + +TEST[[ +---@type A|B|C +local <?x?> = class() +]] +[[ +local x: A|B|C {} +]] + +TEST[[ +---@class Class +local <?x?> = { + b = 1 +} +]] +[[ +local x: Class { + b: number = 1, +} +]] + +TEST [[ +---@class Class +local mt = {} + +---@param t Class +function f(<?t?>) +end +]] +[[ +local t: Class {} +]] + +TEST [[ +---@class Class +local mt = {} + +---@param t Class +function f(t) + print(<?t?>) +end +]] +[[ +local t: *Class {} +]] + +TEST [[ +---@class Class +local mt = {} + +---@param t Class +function f(t) +end + +f(<?s?>) +]] +[[ +global s: Class {} +]] + +TEST [[ +---@class Class + +---@param k Class +for <?k?> in pairs(t) do +end +]] +[[ +local k<key>: Class {} +]] + +TEST [[ +---@class Class + +---@param v Class +for k, <?v?> in pairs(t) do +end +]] +[[ +local v<value>: *Class {} +]] + +TEST [[ +---@return A|B +---@return C +local function <?f?>() +end +]] +[[ +function f() + -> A|B, C +]] + +TEST [[ +---@generic T +---@param x T +---@return T +local function f(x) +end + +local <?r?> = f(1) +]] +[[ +local r: number +]] + +TEST [[ +---@param x number +---@param y boolean +local function <?f?>(x, y) +end +]] +[[ +function f(x: number, y: boolean) +]] + +TEST [[ +---@vararg Class +local function f(...) + local _, <?x?> = ... +end +f(1, 2, 3) +]] +[[ +local x: *Class = 2 +]] + +TEST [[ +---@vararg Class +local function f(...) + local _, <?x?> = ... +end +]] +[[ +local x: *Class {} +]] + +TEST [[ +---@type string[] +local <?x?> +]] +[[ +local x: { + [*integer]: string, +} +]] + +TEST [[ +---@type (string|boolean)[] +local <?x?> +]] +[[ +local x: { + [*integer]: string|boolean, +} +]] + +TEST [[ +---@type string[] +local t +local <?x?> = t[1] +]] +[[ +local x: string +]] + +TEST [[ +---@type string[] +local t +for _, <?x?> in ipairs(t) do +end +]] +[[ +local x: string +]] + +TEST [[ +---@type string[] +local t +for _, <?x?> in pairs(t) do +end +]] +[[ +local x: string +]] + +TEST [[ +---@type string[] +local t +for <?k?>, v in pairs(t) do +end +]] +[[ +local k: integer +]] + +TEST [[ +---@type table<ClassA, ClassB> +local <?x?> +]] +[[ +local x: { + [*ClassA]: ClassB, +} +]] + +TEST [[ +---@type table<ClassA, ClassB> +local t +for _, <?x?> in pairs(t) do +end +]] +[[ +local x: *ClassB +]] + +TEST [[ +---@type table<ClassA, ClassB> +local t +for <?k?>, v in pairs(t) do +end +]] +[[ +local k: *ClassA +]] + +TEST [[ +---@type fun(x: number, y: number):boolean +local <?f?> +]] +[[ +function f(x: number, y: number) + -> boolean +]] + +TEST [[ +---@type fun(x: number, y: number):boolean +local f +f(<?a?>) +]] +[[ +global a: number +]] + +TEST [[ +---@type fun(x: number, y: number):boolean +local f +local <?r?> = f() +]] +[[ +local r: boolean +]] + +TEST [[ +---@param f fun():void +function t(<?f?>) end +]] +[[ +function () + -> void +]] + +TEST [[ +---@type fun(a:any, b:any) +local f +local t = {f = f} +t:<?f?>() +]] +[[ +function f(b: any) + -> any +]] + +TEST [[ +---@param names string[] +local function f(<?names?>) +end +]] +[[ +local names: { + [*integer]: string, +} +]] + +TEST [[ +---@return any +function <?f?>() + ---@type integer + local a + return a +end +]] +[[ +function f() + -> any +]] + +TEST [[ +---@return any +function f() + ---@type integer + local a + return a +end + +local <?x?> = f() +]] +[[ +local x: any +]] + + +TEST [[ +---@param x number {optional = 'after'} +---@param y boolean {optional = 'self'} +---@param z string +function <?f?>(x, y, z) end +]] +[=[ +function f([x: number [, y: boolean], z: string]) +]=] + +TEST [[ +---@return string {name = 'key'} +---@return string {name = 'value'} +function <?f?>() end +]] +[=[ +function f() + -> key: string, value: string +]=] + +TEST [[ +---@return {name = 'x', optional = 'after'} +---@return string {name = 'y', optional = 'self'} +---@return string {name = 'z'} +function <?f?>() end +]] +[=[ +function f() + -> [x: any [, y: string], z: string] +]=] + +TEST [[ +---@return {name = 'x', optional = 'after'} +---@return string {name = 'y', optional = 'self'} +---@return string {name = 'z'} +function f() + return function (a, b) + end +end + +<?f2?> = f() +]] +[=[ +function f2(a: any, b: any) +]=] diff --git a/test-beta/rename/init.lua b/test-beta/rename/init.lua index a1595d9a..5ca0ca15 100644 --- a/test-beta/rename/init.lua +++ b/test-beta/rename/init.lua @@ -163,3 +163,43 @@ a() function a:b() end a:b() ]] + +-- TODO +do return end +TEST ('class1', 'class2') [[ +---@class1 + +---@type class1 + +---@param x class1 +]] [[ +---@class2 + +---@type class2 + +---@param x class2 +]] + +TEST ('alias1', 'alias2') [[ +---@alias alias1 class + +---@type alias1 + +---@param x alias1 +]] [[ +---@alias alias2 class + +---@type alias2 + +---@param x alias2 +]] + +TEST ('arg1', 'arg2') [[ +---@param arg1 number +function f(arg1) +end +]] [[ +---@param arg2 number +function f(arg2) +end +]] |