summaryrefslogtreecommitdiff
path: root/server-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-08 11:44:04 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-08 11:44:04 +0800
commit444851fc1adb2fe3a0f952807cb4b644e18790c1 (patch)
tree722586a59027734fbba91678e51d82061c3a923b /server-beta
parentd2b9dee8ce0ae345e4efd43c112bb3efd4071888 (diff)
downloadlua-language-server-444851fc1adb2fe3a0f952807cb4b644e18790c1.zip
修正一些bug
Diffstat (limited to 'server-beta')
-rw-r--r--server-beta/src/core/diagnostics/global-in-nil-env.lua2
-rw-r--r--server-beta/src/core/diagnostics/init.lua3
-rw-r--r--server-beta/src/files.lua3
-rw-r--r--server-beta/src/parser/compile.lua4
-rw-r--r--server-beta/src/proto/define.lua4
-rw-r--r--server-beta/src/proto/provider.lua6
-rw-r--r--server-beta/src/service/diagnostic.lua45
7 files changed, 54 insertions, 13 deletions
diff --git a/server-beta/src/core/diagnostics/global-in-nil-env.lua b/server-beta/src/core/diagnostics/global-in-nil-env.lua
index 72375ea5..d8cc0075 100644
--- a/server-beta/src/core/diagnostics/global-in-nil-env.lua
+++ b/server-beta/src/core/diagnostics/global-in-nil-env.lua
@@ -50,7 +50,7 @@ return function (uri, callback)
finish = source.finish,
uri = uri,
message = lang.script.DIAG_GLOBAL_IN_NIL_ENV,
- relative = {
+ related = {
{
start = ok.start,
finish = ok.finish,
diff --git a/server-beta/src/core/diagnostics/init.lua b/server-beta/src/core/diagnostics/init.lua
index 8b6167cc..2972694d 100644
--- a/server-beta/src/core/diagnostics/init.lua
+++ b/server-beta/src/core/diagnostics/init.lua
@@ -7,8 +7,9 @@ local function check(uri, name, level, results)
return
end
level = config.config.diagnostics.severity[name] or level
+ local severity = define.DiagnosticSeverity[level]
require('core.diagnostics.' .. name)(uri, function (result)
- result.level = level or result.level
+ result.level = severity or result.level
result.code = name
results[#results+1] = result
end, name)
diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua
index 78610315..47078661 100644
--- a/server-beta/src/files.lua
+++ b/server-beta/src/files.lua
@@ -115,6 +115,9 @@ function m.remove(uri)
end
m.fileMap[uri] = nil
searcher.refreshCache()
+
+ local diagnostic = require 'service.diagnostic'
+ diagnostic.refresh()
end
--- 移除所有文件
diff --git a/server-beta/src/parser/compile.lua b/server-beta/src/parser/compile.lua
index 1a3e5a21..1a187e96 100644
--- a/server-beta/src/parser/compile.lua
+++ b/server-beta/src/parser/compile.lua
@@ -254,7 +254,7 @@ local vmMap = {
type = 'REDEFINED_LABEL',
start = obj.start,
finish = obj.finish,
- relative = {
+ related = {
{
message = 'REDEFINED_LABEL',
start = label.start,
@@ -460,7 +460,7 @@ local function compileGoTo(obj)
info = {
loc = loc[1],
},
- relative = {
+ related = {
{
message = 'JUMPED_LABEL',
start = label.start,
diff --git a/server-beta/src/proto/define.lua b/server-beta/src/proto/define.lua
index 6acd2348..ee968021 100644
--- a/server-beta/src/proto/define.lua
+++ b/server-beta/src/proto/define.lua
@@ -30,7 +30,7 @@ function m.position(lines, text, offset)
}
end
---- 将2个光标位置转化为 range
+--- 将起点与终点位置转化为 range
---@alias range table
---@param lines table
---@param text string
@@ -38,7 +38,7 @@ end
---@param offset2 integer
function m.range(lines, text, offset1, offset2)
return {
- start = m.position(lines, text, offset1),
+ start = m.position(lines, text, offset1-1),
['end'] = m.position(lines, text, offset2),
}
end
diff --git a/server-beta/src/proto/provider.lua b/server-beta/src/proto/provider.lua
index 08229f29..ea1fb203 100644
--- a/server-beta/src/proto/provider.lua
+++ b/server-beta/src/proto/provider.lua
@@ -167,9 +167,9 @@ proto.on('textDocument/definition', function (params)
local targetLines = files.getLines(targetUri)
local targetText = files.getText(targetUri)
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)
+ , define.range(targetLines, targetText, info.target.start, info.target.finish)
+ , define.range(targetLines, targetText, info.target.start, info.target.finish)
+ , define.range(lines, text, info.source.start, info.source.finish)
)
end
return response
diff --git a/server-beta/src/service/diagnostic.lua b/server-beta/src/service/diagnostic.lua
index 6fd212a9..f6b0c1a0 100644
--- a/server-beta/src/service/diagnostic.lua
+++ b/server-beta/src/service/diagnostic.lua
@@ -4,6 +4,7 @@ local define = require 'proto.define'
local lang = require 'language'
local files = require 'files'
local config = require 'config'
+local core = require 'core.diagnostics'
local m = {}
@@ -29,11 +30,11 @@ local function buildSyntaxError(uri, err)
))
end
- local relative = err.info and err.info.relative
+ local related = err.info and err.info.related
local relatedInformation
- if relative then
+ if related then
relatedInformation = {}
- for _, rel in ipairs(relative) do
+ for _, rel in ipairs(related) do
relatedInformation[#relatedInformation+1] = {
message = lang.script('PARSER_'..rel.message),
location = define.location(uri, define.range(lines, text, rel.start, rel.finish)),
@@ -50,6 +51,34 @@ local function buildSyntaxError(uri, err)
}
end
+local function buildDiagnostic(uri, diag)
+ local lines = files.getLines(uri)
+ local text = files.getText(uri)
+
+ local relatedInformation
+ if diag.related then
+ relatedInformation = {}
+ for _, rel in ipairs(diag.related) do
+ local rtext = files.getText(rel.uri)
+ local rlines = files.getLines(rel.uri)
+ relatedInformation[#relatedInformation+1] = {
+ message = rel.message or rtext:sub(rel.start, rel.finish),
+ location = define.location(rel.uri, define.range(rlines, rtext, rel.start, rel.finish))
+ }
+ end
+ end
+
+ return {
+ range = define.range(lines, text, diag.start, diag.finish),
+ source = lang.script.DIAG_DIAGNOSTICS,
+ severity = diag.level,
+ message = diag.message,
+ code = diag.code,
+ tags = diag.tags,
+ relatedInformation = relatedInformation,
+ }
+end
+
function m.doDiagnostic(uri)
local ast = files.getAst(uri)
if not ast then
@@ -62,6 +91,12 @@ function m.doDiagnostic(uri)
diagnostics[#diagnostics+1] = buildSyntaxError(uri, err)
end
+ local diags = core(uri)
+ for _, diag in ipairs(diags) do
+ diagnostics[#diagnostics+1] = buildDiagnostic(uri, diag)
+ end
+
+
proto.notify('textDocument/publishDiagnostics', {
uri = uri,
diagnostics = diagnostics,
@@ -73,7 +108,9 @@ function m.refresh(uri)
m.version = m.version + 1
local myVersion = m.version
await.create(function ()
- m.doDiagnostic(files.getOriginUri(uri))
+ if uri then
+ m.doDiagnostic(files.getOriginUri(uri))
+ end
await.sleep(1.0)
if myVersion ~= m.version then
return