summaryrefslogtreecommitdiff
path: root/server/src/method/workspace/didChangeConfiguration.lua
blob: dd1f84ff04c661cedd8d8280b34196440553d648 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
local rpc = require 'rpc'
local config = require 'config'

local EXISTS = {}

local function eq(a, b)
    if a == EXISTS and b ~= nil then
        return true
    end
    local tp1, tp2 = type(a), type(b)
    if tp1 ~= tp2 then
        return false
    end
    if tp1 == 'table' then
        local mark = {}
        for k in pairs(a) do
            if not eq(a[k], b[k]) then
                return false
            end
            mark[k] = true
        end
        for k in pairs(b) do
            if not mark[k] then
                return false
            end
        end
        return true
    end
    return a == b
end

local function copyTable(a)
    local t = {}
    for k, v in pairs(a) do
        if type(v) == 'table' then
            t[k] = copyTable(v)
        else
            t[k] = v
        end
    end
    return t
end

return function (lsp)
    -- 请求配置
    rpc:request('workspace/configuration', {
        items = {
            {
                section = 'Lua',
            },
        },
    }, function (configs)
        local oldConfig = copyTable(config.config)
        config:setConfig(configs[1])
        local newConfig = config.config
        if not eq(oldConfig.diagnostics, newConfig.diagnostics) then
            log.debug('reDiagnostic')
            lsp:reDiagnostic()
        end
        if not eq(oldConfig.workspace, newConfig.workspace) then
            lsp:clearAllFiles()
            lsp.workspace:scanFiles()
        end
    end)
end