summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/settings.json3
-rw-r--r--script-beta/core/diagnostics/duplicate-doc-class.lua46
-rw-r--r--script-beta/core/diagnostics/emmy-lua.lua3
-rw-r--r--script-beta/core/diagnostics/set-const.lua2
-rw-r--r--script-beta/define/DiagnosticDefaultSeverity.lua5
-rw-r--r--script-beta/parser/guide.lua4
-rw-r--r--script-beta/parser/luadoc.lua6
-rw-r--r--script-beta/proto/define.lua4
-rw-r--r--test-beta/diagnostics/init.lua207
9 files changed, 167 insertions, 113 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 224ccbd0..97694867 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -25,7 +25,8 @@
"locale/",
"libs/",
"3rd",
- ".vscode"
+ ".vscode",
+ "script",
],
"Lua.workspace.library": {
"E:/Github/test" : true,
diff --git a/script-beta/core/diagnostics/duplicate-doc-class.lua b/script-beta/core/diagnostics/duplicate-doc-class.lua
new file mode 100644
index 00000000..8974d215
--- /dev/null
+++ b/script-beta/core/diagnostics/duplicate-doc-class.lua
@@ -0,0 +1,46 @@
+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.focs then
+ return
+ end
+
+ local cache = {}
+ for _, doc in ipairs(state.ast.docs) do
+ if doc.type == 'doc.class'
+ or doc.type == 'doc.alias' then
+ local name = guide.getName(doc)
+ if not cache[name] then
+ local docs = vm.getDocTypes(name)
+ cache[name] = {}
+ for _, otherDoc in ipairs(docs) do
+ if otherDoc.type == 'doc.class'
+ or otherDoc.type == 'doc.alias' then
+ cache[name][#cache[name]+1] = {
+ start = otherDoc.start,
+ finish = otherDoc.finish,
+ uri = guide.getUri(otherDoc),
+ }
+ end
+ end
+ end
+ if #cache[name] > 1 then
+ callback {
+ start = doc.start,
+ finish = doc.finish,
+ related = cache,
+ message = lang.script('DIAG_DUPLICATE_DOC_CLASS', name)
+ }
+ end
+ end
+ end
+end
diff --git a/script-beta/core/diagnostics/emmy-lua.lua b/script-beta/core/diagnostics/emmy-lua.lua
deleted file mode 100644
index b3d19c21..00000000
--- a/script-beta/core/diagnostics/emmy-lua.lua
+++ /dev/null
@@ -1,3 +0,0 @@
-return function ()
-
-end
diff --git a/script-beta/core/diagnostics/set-const.lua b/script-beta/core/diagnostics/set-const.lua
new file mode 100644
index 00000000..62a67b01
--- /dev/null
+++ b/script-beta/core/diagnostics/set-const.lua
@@ -0,0 +1,2 @@
+return function (uri, callback)
+end
diff --git a/script-beta/define/DiagnosticDefaultSeverity.lua b/script-beta/define/DiagnosticDefaultSeverity.lua
index cc26cab2..75cf4a6b 100644
--- a/script-beta/define/DiagnosticDefaultSeverity.lua
+++ b/script-beta/define/DiagnosticDefaultSeverity.lua
@@ -8,14 +8,15 @@ return {
['trailing-space'] = 'Hint',
['redefined-local'] = 'Hint',
['newline-call'] = 'Information',
+ ['newfield-call'] = 'Warning',
['redundant-parameter'] = 'Hint',
['ambiguity-1'] = 'Warning',
['lowercase-global'] = 'Information',
['undefined-env-child'] = 'Information',
['duplicate-index'] = 'Warning',
- ['duplicate-method'] = 'Warning',
['empty-block'] = 'Hint',
['redundant-value'] = 'Hint',
- ['emmy-lua'] = 'Warning',
['set-const'] = 'Error',
+
+ ['duplicate-doc-class'] = 'Warning',
}
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index 1787bdbb..ef4f768c 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -677,6 +677,10 @@ function m.getName(obj)
elseif tp == 'field'
or tp == 'method' then
return obj[1]
+ elseif tp == 'doc.class' then
+ return obj.class[1]
+ elseif tp == 'doc.alias' then
+ return obj.alias[1]
end
return m.getNameOfLiteral(obj)
end
diff --git a/script-beta/parser/luadoc.lua b/script-beta/parser/luadoc.lua
index b0cea88d..469c086f 100644
--- a/script-beta/parser/luadoc.lua
+++ b/script-beta/parser/luadoc.lua
@@ -194,9 +194,9 @@ local function parseClass(parent)
nextToken()
if not checkToken('symbol', ':') then
pushError {
- type = 'LUADOC_MISS_EXTENSION_SYMBOL',
- start = getFinish(),
- finish = getFinish(),
+ type = 'LUADOC_MISS_EXTENDS_SYMBOL',
+ start = result.finish + 1,
+ finish = getStart() - 1,
}
return result
end
diff --git a/script-beta/proto/define.lua b/script-beta/proto/define.lua
index 328cac90..e43b73ef 100644
--- a/script-beta/proto/define.lua
+++ b/script-beta/proto/define.lua
@@ -129,7 +129,9 @@ m.DiagnosticDefaultSeverity = {
['duplicate-index'] = 'Warning',
['empty-block'] = 'Hint',
['redundant-value'] = 'Hint',
- ['emmy-lua'] = 'Warning',
+ ['set-const'] = 'Error',
+
+ ['duplicate-doc-class'] = 'Warning',
}
--- 诊断报告标签
diff --git a/test-beta/diagnostics/init.lua b/test-beta/diagnostics/init.lua
index 49d11dc2..ed850118 100644
--- a/test-beta/diagnostics/init.lua
+++ b/test-beta/diagnostics/init.lua
@@ -576,109 +576,6 @@ print(T6)
print(T7)
]]
---TEST [[
------@class <!Class!>
------@class <!Class!>
---]]
---
---TEST [[
------@class A : <!B!>
---]]
---
---TEST [[
------@class <!A : B!>
------@class <!B : C!>
------@class <!C : D!>
------@class <!D : A!>
---]]
---
---TEST [[
------@class A : B
------@class B : C
------@class C : D
------@class D
---]]
---
---TEST [[
------@type <!A!>
---]]
---
---TEST [[
------@class A
------@type A|<!B!>|<!C!>
---]]
---
---TEST [[
------@class AAA
------@alias B AAA
---
------@type B
---]]
---
---TEST [[
------@alias B <!AAA!>
---]]
---
---TEST [[
------@class <!A!>
------@class B
------@alias <!A B!>
---]]
---
---TEST [[
------@param x <!Class!>
---]]
---
---TEST [[
------@class Class
------@param <!y!> Class
---local function f(x)
--- return x
---end
---f()
---]]
---
---TEST [[
------@class Class
------@param <!y!> Class
---function F(x)
--- return x
---end
---F()
---]]
---
---TEST [[
------@class Class
------@param <!x!> Class
------@param y Class
------@param <!x!> Class
---local function f(x, y)
--- return x, y
---end
---f()
---]]
---
---TEST [[
------@field <!x Class!>
------@class Class
---]]
---
---TEST [[
------@class Class
------@field <!x!> Class
------@field <!x!> Class
---]]
---
---TEST [[
------@class Class : any
---]]
---
---TEST [[
------@type fun(a: integer)
---local f
---f()
---]]
-
TEST [[
local x
x = <!x or 0 + 1!>
@@ -719,3 +616,107 @@ return t
TEST [[
table.insert({}, 1, 2, <!3!>)
]]
+
+do return end
+TEST [[
+---@class <!Class!>
+---@class <!Class!>
+]]
+
+TEST [[
+---@class A : <!B!>
+]]
+
+TEST [[
+---@class <!A : B!>
+---@class <!B : C!>
+---@class <!C : D!>
+---@class <!D : A!>
+]]
+
+TEST [[
+---@class A : B
+---@class B : C
+---@class C : D
+---@class D
+]]
+
+TEST [[
+---@type <!A!>
+]]
+
+TEST [[
+---@class A
+---@type A|<!B!>|<!C!>
+]]
+
+TEST [[
+---@class AAA
+---@alias B AAA
+
+---@type B
+]]
+
+TEST [[
+---@alias B <!AAA!>
+]]
+
+TEST [[
+---@class <!A!>
+---@class B
+---@alias <!A B!>
+]]
+
+TEST [[
+---@param x <!Class!>
+]]
+
+TEST [[
+---@class Class
+---@param <!y!> Class
+local function f(x)
+ return x
+end
+f()
+]]
+
+TEST [[
+---@class Class
+---@param <!y!> Class
+function F(x)
+ return x
+end
+F()
+]]
+
+TEST [[
+---@class Class
+---@param <!x!> Class
+---@param y Class
+---@param <!x!> Class
+local function f(x, y)
+ return x, y
+end
+f()
+]]
+
+TEST [[
+---@field <!x Class!>
+---@class Class
+]]
+
+TEST [[
+---@class Class
+---@field <!x!> Class
+---@field <!x!> Class
+]]
+
+TEST [[
+---@class Class : any
+]]
+
+TEST [[
+---@type fun(a: integer)
+local f
+f()
+]]