summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-07-22 17:22:10 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-07-22 17:22:10 +0800
commit5bf4d5f892e9af225f2cdd77c2e3ea4be582705b (patch)
tree6c6a6c4972e85a2cafbe689cb5ab42b306e51789
parent050b7262a4019a1ecafac0acdc5bd9a1b0ca0bf4 (diff)
downloadlua-language-server-5bf4d5f892e9af225f2cdd77c2e3ea4be582705b.zip
修改配置由前端完成;为了防止冲突,命令加个前缀
-rw-r--r--script/core/code_action.lua20
-rw-r--r--script/method/workspace/executeCommand.lua92
2 files changed, 12 insertions, 100 deletions
diff --git a/script/core/code_action.lua b/script/core/code_action.lua
index b5fa91ef..c9203f29 100644
--- a/script/core/code_action.lua
+++ b/script/core/code_action.lua
@@ -7,10 +7,10 @@ local function disableDiagnostic(lsp, uri, data, callback)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_DISABLE_DIAG,
- command = 'config',
+ command = 'lua.config',
arguments = {
{
- key = {'diagnostics', 'disable'},
+ key = 'Lua.diagnostics.disable',
action = 'add',
value = data.code,
uri = uri,
@@ -26,10 +26,10 @@ local function addGlobal(name, uri, callback)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_MARK_GLOBAL,
- command = 'config',
+ command = 'lua.config',
arguments = {
{
- key = {'diagnostics', 'globals'},
+ key = 'Lua.diagnostics.globals',
action = 'add',
value = name,
uri = uri,
@@ -45,10 +45,10 @@ local function changeVersion(version, uri, callback)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_RUNTIME_VERSION,
- command = 'config',
+ command = 'lua.config',
arguments = {
{
- key = {'runtime', 'version'},
+ key = 'Lua.runtime.version',
action = 'set',
value = version,
uri = uri,
@@ -64,10 +64,10 @@ local function openCustomLibrary(libName, uri, callback)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_OPEN_LIBRARY,
- command = 'config',
+ command = 'lua.config',
arguments = {
{
- key = {'runtime', 'library'},
+ key = 'Lua.runtime.library',
action = 'add',
value = libName,
uri = uri,
@@ -124,7 +124,7 @@ local function solveTrailingSpace(lsp, uri, data, callback)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_REMOVE_SPACE,
- command = 'removeSpace',
+ command = 'lua.removeSpace',
arguments = {
{
uri = uri,
@@ -160,7 +160,7 @@ local function solveAmbiguity1(lsp, uri, data, callback)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_ADD_BRACKETS,
- command = 'solve',
+ command = 'lua.solve',
arguments = {
{
name = 'ambiguity-1',
diff --git a/script/method/workspace/executeCommand.lua b/script/method/workspace/executeCommand.lua
index d5abb453..357c21c0 100644
--- a/script/method/workspace/executeCommand.lua
+++ b/script/method/workspace/executeCommand.lua
@@ -1,9 +1,5 @@
-local fs = require 'bee.filesystem'
-local json = require 'json'
-local config = require 'config'
local rpc = require 'rpc'
local lang = require 'language'
-local platform = require 'bee.platform'
local command = {}
@@ -39,91 +35,7 @@ end
--- @param lsp LSP
--- @param data table
-function command.config(lsp, data)
- local def = config.config
- for _, k in ipairs(data.key) do
- def = def[k]
- if not def then
- return
- end
- end
- if data.action == 'add' then
- if type(def) ~= 'table' then
- return
- end
- end
-
- local vscodePath
- local mode
- local ws
- if data.uri then
- ws = lsp:findWorkspaceFor(data.uri)
- end
- if ws then
- vscodePath = ws.root / '.vscode'
- mode = 'workspace'
- else
- if platform.OS == 'Windows' then
- vscodePath = fs.path(os.getenv 'USERPROFILE') / 'AppData' / 'Roaming' / 'Code' / 'User'
- else
- vscodePath = fs.path(os.getenv 'HOME') / '.vscode-server' / 'data' / 'Machine'
- end
- mode = 'user'
- if not fs.exists(vscodePath) then
- rpc:notify('window/showMessage', {
- type = 3,
- message = lang.script.MWS_UCONFIG_FAILED,
- })
- return
- end
- end
-
- local settingBuf = io.load(vscodePath / 'settings.json')
- if not settingBuf then
- fs.create_directories(vscodePath)
- end
-
- local setting = json.decode(settingBuf or '', true) or {}
- local key = 'Lua.' .. table.concat(data.key, '.')
- local attr = setting[key]
-
- if data.action == 'add' then
- if attr == nil then
- attr = {}
- elseif type(attr) == 'string' then
- attr = {}
- for str in attr:gmatch '[^;]+' do
- attr[#attr+1] = str
- end
- elseif type(attr) == 'table' then
- else
- return
- end
-
- attr[#attr+1] = data.value
- setting[key] = attr
- elseif data.action == 'set' then
- setting[key] = data.value
- end
-
- io.save(vscodePath / 'settings.json', json.encode(setting) .. '\r\n')
-
- if mode == 'workspace' then
- rpc:notify('window/showMessage', {
- type = 3,
- message = lang.script.MWS_WCONFIG_UPDATED,
- })
- elseif mode == 'user' then
- rpc:notify('window/showMessage', {
- type = 3,
- message = lang.script.MWS_UCONFIG_UPDATED,
- })
- end
-end
-
---- @param lsp LSP
---- @param data table
-function command.removeSpace(lsp, data)
+command['lua.removeSpace'] = function (lsp, data)
local uri = data.uri
local vm, lines = lsp:getVM(uri)
if not vm then
@@ -188,7 +100,7 @@ local literalMap = {
--- @param lsp LSP
--- @param data table
-function command.solve(lsp, data)
+command['lua.resolve'] = function (lsp, data)
local uri = data.uri
local vm, lines = lsp:getVM(uri)
if not vm then