summaryrefslogtreecommitdiff
path: root/server-beta/src
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src')
-rw-r--r--server-beta/src/core/diagnostics/ambiguity-1.lua3
-rw-r--r--server-beta/src/core/diagnostics/duplicate-index.lua3
-rw-r--r--server-beta/src/core/diagnostics/duplicate-method.lua3
-rw-r--r--server-beta/src/core/diagnostics/emmy-lua.lua3
-rw-r--r--server-beta/src/core/diagnostics/empty-block.lua3
-rw-r--r--server-beta/src/core/diagnostics/global-in-nil-env.lua3
-rw-r--r--server-beta/src/core/diagnostics/init.lua29
-rw-r--r--server-beta/src/core/diagnostics/lowercase-global.lua3
-rw-r--r--server-beta/src/core/diagnostics/newfield-call.lua3
-rw-r--r--server-beta/src/core/diagnostics/newline-call.lua3
-rw-r--r--server-beta/src/core/diagnostics/redefined-local.lua3
-rw-r--r--server-beta/src/core/diagnostics/redundant-parameter.lua3
-rw-r--r--server-beta/src/core/diagnostics/redundant-value.lua3
-rw-r--r--server-beta/src/core/diagnostics/set-const.lua3
-rw-r--r--server-beta/src/core/diagnostics/trailing-space.lua3
-rw-r--r--server-beta/src/core/diagnostics/undefined-env-child.lua3
-rw-r--r--server-beta/src/core/diagnostics/undefined-global.lua3
-rw-r--r--server-beta/src/core/diagnostics/unused-function.lua3
-rw-r--r--server-beta/src/core/diagnostics/unused-label.lua3
-rw-r--r--server-beta/src/core/diagnostics/unused-local.lua38
-rw-r--r--server-beta/src/core/diagnostics/unused-vararg.lua3
-rw-r--r--server-beta/src/language.lua7
-rw-r--r--server-beta/src/parser/guide.lua17
-rw-r--r--server-beta/src/proto/define.lua (renamed from server-beta/src/proto/interface.lua)39
-rw-r--r--server-beta/src/proto/provider.lua12
25 files changed, 189 insertions, 10 deletions
diff --git a/server-beta/src/core/diagnostics/ambiguity-1.lua b/server-beta/src/core/diagnostics/ambiguity-1.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/ambiguity-1.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/duplicate-index.lua b/server-beta/src/core/diagnostics/duplicate-index.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/duplicate-index.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/duplicate-method.lua b/server-beta/src/core/diagnostics/duplicate-method.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/duplicate-method.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/emmy-lua.lua b/server-beta/src/core/diagnostics/emmy-lua.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/emmy-lua.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/empty-block.lua b/server-beta/src/core/diagnostics/empty-block.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/empty-block.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/global-in-nil-env.lua b/server-beta/src/core/diagnostics/global-in-nil-env.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/global-in-nil-env.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/init.lua b/server-beta/src/core/diagnostics/init.lua
new file mode 100644
index 00000000..69815003
--- /dev/null
+++ b/server-beta/src/core/diagnostics/init.lua
@@ -0,0 +1,29 @@
+local files = require 'files'
+local define = require 'proto.define'
+local config = require 'config'
+
+local function check(uri, name, level, results)
+ if config.config.diagnostics.disable[name] then
+ return
+ end
+ level = config.config.diagnostics.severity[name] or level
+ require('core.diagnostics.' .. name)(uri, function (result)
+ result.level = level or result.level
+ result.code = name
+ results[#results+1] = result
+ end)
+end
+
+return function (uri)
+ local ast = files.getAst(uri)
+ if not ast then
+ return nil
+ end
+ local results = {}
+
+ for name, level in pairs(define.DiagnosticDefaultSeverity) do
+ check(uri, name, level, results)
+ end
+
+ return results
+end
diff --git a/server-beta/src/core/diagnostics/lowercase-global.lua b/server-beta/src/core/diagnostics/lowercase-global.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/lowercase-global.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/newfield-call.lua b/server-beta/src/core/diagnostics/newfield-call.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/newfield-call.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/newline-call.lua b/server-beta/src/core/diagnostics/newline-call.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/newline-call.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/redefined-local.lua b/server-beta/src/core/diagnostics/redefined-local.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/redefined-local.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/redundant-parameter.lua b/server-beta/src/core/diagnostics/redundant-parameter.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/redundant-parameter.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/redundant-value.lua b/server-beta/src/core/diagnostics/redundant-value.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/redundant-value.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/set-const.lua b/server-beta/src/core/diagnostics/set-const.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/set-const.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/trailing-space.lua b/server-beta/src/core/diagnostics/trailing-space.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/trailing-space.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/undefined-env-child.lua b/server-beta/src/core/diagnostics/undefined-env-child.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/undefined-env-child.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/undefined-global.lua b/server-beta/src/core/diagnostics/undefined-global.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/undefined-global.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/unused-function.lua b/server-beta/src/core/diagnostics/unused-function.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/unused-function.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/unused-label.lua b/server-beta/src/core/diagnostics/unused-label.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/unused-label.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/core/diagnostics/unused-local.lua b/server-beta/src/core/diagnostics/unused-local.lua
new file mode 100644
index 00000000..9b97ca88
--- /dev/null
+++ b/server-beta/src/core/diagnostics/unused-local.lua
@@ -0,0 +1,38 @@
+local files = require 'files'
+local guide = require 'parser.guide'
+local define = require 'proto.define'
+local lang = require 'language'
+
+local function hasGet(loc)
+ if not loc.ref then
+ return false
+ end
+ for _, ref in ipairs(loc.ref) do
+ if ref.type == 'get' then
+ return true
+ end
+ end
+ return false
+end
+
+return function (uri, callback)
+ local ast = files.getAst(uri)
+ if not ast then
+ return
+ end
+ guide.eachSourceType(ast.ast, 'local', function (source)
+ local name = source[1]
+ if name == '_'
+ or name == '_ENV' then
+ return
+ end
+ if not hasGet(source) then
+ callback {
+ start = source.start,
+ finish = source.finish,
+ tags = { define.DiagnosticTag.Unnecessary },
+ message = lang.script('DIAG_UNUSED_LOCAL', name),
+ }
+ end
+ end)
+end
diff --git a/server-beta/src/core/diagnostics/unused-vararg.lua b/server-beta/src/core/diagnostics/unused-vararg.lua
new file mode 100644
index 00000000..b3d19c21
--- /dev/null
+++ b/server-beta/src/core/diagnostics/unused-vararg.lua
@@ -0,0 +1,3 @@
+return function ()
+
+end
diff --git a/server-beta/src/language.lua b/server-beta/src/language.lua
index 3294c5b2..d1a4b4cf 100644
--- a/server-beta/src/language.lua
+++ b/server-beta/src/language.lua
@@ -1,5 +1,6 @@
-local fs = require 'bee.filesystem'
-local lni = require 'lni'
+local fs = require 'bee.filesystem'
+local lni = require 'lni'
+local util = require 'utility'
local function supportLanguage()
local list = {}
@@ -33,7 +34,7 @@ end
local function loadFileByLanguage(name, language)
local path = ROOT / 'locale' / language / (name .. '.lni')
- local buf = io.load(path)
+ local buf = util.loadFile(path:string())
if not buf then
return {}
end
diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua
index 0ca83489..773fb6d5 100644
--- a/server-beta/src/parser/guide.lua
+++ b/server-beta/src/parser/guide.lua
@@ -307,6 +307,23 @@ function m.eachSourceContain(ast, offset, callback)
end
end
+--- 遍历所有指定类型的source
+function m.eachSourceType(ast, type, callback)
+ local cache = ast.typeCache
+ if not cache then
+ cache = {}
+ ast.typeCache = cache
+ m.eachSource(ast, function (source)
+ if source.type == type then
+ cache[#cache+1] = source
+ end
+ end)
+ end
+ for i = 1, #cache do
+ callback(cache[i])
+ end
+end
+
--- 遍历所有的source
function m.eachSource(ast, callback)
local list = { ast }
diff --git a/server-beta/src/proto/interface.lua b/server-beta/src/proto/define.lua
index 6af0c996..9401e9e5 100644
--- a/server-beta/src/proto/interface.lua
+++ b/server-beta/src/proto/define.lua
@@ -2,7 +2,6 @@ local guide = require 'parser.guide'
local m = {}
-
--- 获取 position 对应的光标位置
---@param lines table
---@param text string
@@ -69,4 +68,42 @@ function m.locationLink(uri, range, selection, origin)
}
end
+--- 诊断等级
+m.DiagnosticSeverity = {
+ Error = 1,
+ Warning = 2,
+ Information = 3,
+ Hint = 4,
+}
+
+--- 诊断类型与默认等级
+m.DiagnosticDefaultSeverity = {
+ ['unused-local'] = 'Hint',
+ ['unused-function'] = 'Hint',
+ ['undefined-global'] = 'Warning',
+ ['global-in-nil-env'] = 'Warning',
+ ['unused-label'] = 'Hint',
+ ['unused-vararg'] = 'Hint',
+ ['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',
+}
+
+--- 诊断报告标签
+m.DiagnosticTag = {
+ Unnecessary = 1,
+ Deprecated = 2,
+}
+
return m
diff --git a/server-beta/src/proto/provider.lua b/server-beta/src/proto/provider.lua
index 9f3b5697..1f6f6813 100644
--- a/server-beta/src/proto/provider.lua
+++ b/server-beta/src/proto/provider.lua
@@ -3,7 +3,7 @@ local cap = require 'proto.capability'
local task = require 'task'
local files = require 'files'
local proto = require 'proto.proto'
-local interface = require 'proto.interface'
+local define = require 'proto.define'
local workspace = require 'workspace'
local config = require 'config'
@@ -154,7 +154,7 @@ proto.on('textDocument/definition', function (params)
end
local lines = files.getLines(uri)
local text = files.getText(uri)
- local offset = interface.offset(lines, text, params.position)
+ local offset = define.offset(lines, text, params.position)
local result = core(uri, offset)
if not result then
return nil
@@ -164,10 +164,10 @@ proto.on('textDocument/definition', function (params)
local targetUri = info.uri
local targetLines = files.getLines(targetUri)
local targetText = files.getText(targetUri)
- response[i] = interface.locationLink(targetUri
- , interface.range(targetLines, targetText, info.target.start - 1, info.target.finish)
- , interface.range(targetLines, targetText, info.target.start - 1, info.target.finish)
- , interface.range(lines, text, info.source.start - 1, info.source.finish)
+ response[i] = define.locationLink(targetUri
+ , define.range(targetLines, targetText, info.target.start - 1, info.target.finish)
+ , define.range(targetLines, targetText, info.target.start - 1, info.target.finish)
+ , define.range(lines, text, info.source.start - 1, info.source.finish)
)
end
return response