summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package.json8
-rw-r--r--server/src/config.lua63
-rw-r--r--server/src/core/diagnostics.lua33
-rw-r--r--server/src/method/init.lua1
-rw-r--r--server/src/method/initialized.lua17
-rw-r--r--server/src/method/workspace/didChangeConfiguration.lua15
6 files changed, 119 insertions, 18 deletions
diff --git a/package.json b/package.json
index b162dbed..7237bde2 100644
--- a/package.json
+++ b/package.json
@@ -47,12 +47,8 @@
},
"Lua.diagnostics.globals": {
"scope": "resource",
- "type": "array",
- "items": {
- "type": "string"
- },
- "default": [],
- "description": "Defined global variables.\n已定义的全局变量。"
+ "type": "string",
+ "description": "Defined global variables.Split by `;`.\n已定义的全局变量。使用`;`分割。"
}
}
}
diff --git a/server/src/config.lua b/server/src/config.lua
new file mode 100644
index 00000000..8aff6d40
--- /dev/null
+++ b/server/src/config.lua
@@ -0,0 +1,63 @@
+local function Boolean(v)
+ if type(v) == 'boolean' then
+ return true, v
+ end
+ return false
+end
+
+local function Str2Hash(sep)
+ return function (v)
+ if type(v) ~= 'string' then
+ return false
+ end
+ local t = {}
+ for s in v:gmatch('[^'..sep..']+') do
+ t[s] = true
+ end
+ return t
+ end
+end
+
+local Template = {
+ diagnostics = {
+ postSpcae = {true, Boolean},
+ spaceOnlyLine = {true, Boolean},
+ globals = {{}, Str2Hash ';'},
+ }
+}
+
+local Config
+
+local function init()
+ if Config then
+ return
+ end
+ Config = {}
+ for c, t in pairs(Template) do
+ Config[c] = {}
+ for k, info in pairs(t) do
+ Config[c][k] = info[1]
+ end
+ end
+end
+
+local function setConfig(config)
+ pcall(function ()
+ for c, t in pairs(config) do
+ for k, v in pairs(t) do
+ local f = Template[c][k]
+ local suc, v = f(v)
+ if suc then
+ Config[c][k] = v
+ end
+ end
+ end
+ end)
+end
+
+init()
+
+return {
+ setConfig = setConfig,
+ config = Config,
+}
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index a6672c0b..6a87a25b 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -1,4 +1,5 @@
local lang = require 'language'
+local config = require 'config'
local DiagnosticSeverity = {
Error = 1,
@@ -40,6 +41,9 @@ local function searchUndefinedGlobal(results, callback)
if type(index) ~= 'string' then
goto NEXT_VAR
end
+ if config.config.diagnostics.globals[index] then
+ goto NEXT_VAR
+ end
local lIndex = index:lower()
if lIndex == 'log' or lIndex == 'arg' or lIndex == '' then
goto NEXT_VAR
@@ -97,25 +101,30 @@ local function searchSpaces(vm, lines, callback)
for i = 1, #lines do
local line = lines:line(i)
- if line:find '^[ \t]+$' then
- local start, finish = lines:range(i)
- if isInString(vm, start, finish) then
+ if config.config.diagnostics.spaceOnlyLine then
+ if line:find '^[ \t]+$' then
+ local start, finish = lines:range(i)
+ if isInString(vm, start, finish) then
+ goto NEXT_LINE
+ end
+ callback(start, finish, lang.script.DIAG_LINE_ONLY_SPACE)
goto NEXT_LINE
end
- callback(start, finish, lang.script.DIAG_LINE_ONLY_SPACE)
- goto NEXT_LINE
end
- local pos = line:find '[ \t]+$'
- if pos then
- local start, finish = lines:range(i)
- start = start + pos - 1
- if isInString(vm, start, finish) then
+ if config.config.diagnostics.postSpcae then
+ local pos = line:find '[ \t]+$'
+ if pos then
+ local start, finish = lines:range(i)
+ start = start + pos - 1
+ if isInString(vm, start, finish) then
+ goto NEXT_LINE
+ end
+ callback(start, finish, lang.script.DIAG_LINE_POST_SPACE)
goto NEXT_LINE
end
- callback(start, finish, lang.script.DIAG_LINE_POST_SPACE)
- goto NEXT_LINE
end
+
::NEXT_LINE::
end
end
diff --git a/server/src/method/init.lua b/server/src/method/init.lua
index 1c272eb4..764df987 100644
--- a/server/src/method/init.lua
+++ b/server/src/method/init.lua
@@ -20,6 +20,7 @@ init 'textDocument/publishDiagnostics'
init 'textDocument/rename'
init 'textDocument/references'
init 'textDocument/signatureHelp'
+init 'workspace/didChangeConfiguration'
init 'workspace/didChangeWatchedFiles'
init 'workspace/didChangeWorkspaceFolders'
diff --git a/server/src/method/initialized.lua b/server/src/method/initialized.lua
index 906fb3a3..fa0e33cb 100644
--- a/server/src/method/initialized.lua
+++ b/server/src/method/initialized.lua
@@ -1,7 +1,9 @@
local rpc = require 'rpc'
local workspace = require 'workspace'
+local config = require 'config'
return function (lsp)
+ -- 请求工作目录
rpc:request('workspace/workspaceFolders', nil, function (folders)
if folders then
local folder = folders[1]
@@ -11,6 +13,16 @@ return function (lsp)
end
end
end)
+ -- 请求配置
+ rpc:request('workspace/configuration', {
+ items = {
+ {
+ section = 'Lua',
+ },
+ },
+ }, function (configs)
+ confgi:setConfig(configs[1])
+ end)
-- 必须动态注册的事件:
rpc:request('client/registerCapability', {
registrations = {
@@ -27,6 +39,11 @@ return function (lsp)
},
},
},
+ -- 配置变化
+ {
+ id = '1',
+ method = 'workspace/didChangeConfiguration',
+ }
}
}, function ()
log.debug('client/registerCapability Success!')
diff --git a/server/src/method/workspace/didChangeConfiguration.lua b/server/src/method/workspace/didChangeConfiguration.lua
new file mode 100644
index 00000000..c1240147
--- /dev/null
+++ b/server/src/method/workspace/didChangeConfiguration.lua
@@ -0,0 +1,15 @@
+local rpc = require 'rpc'
+local config =require 'config'
+
+return function (lsp)
+ -- 请求配置
+ rpc:request('workspace/configuration', {
+ items = {
+ {
+ section = 'Lua',
+ },
+ },
+ }, function (configs)
+ config:setConfig(configs[1])
+ end)
+end