summaryrefslogtreecommitdiff
path: root/server/src/method/workspace/didChangeWatchedFiles.lua
blob: 8f0feecd27a942e45f26d6b97c5db44cbff6f25b (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
local FileChangeType = {
    Created = 1,
    Changed = 2,
    Deleted = 3,
}

return function (lsp, params)
    if not lsp.workspace then
        return
    end
    local needReset
    for _, change in ipairs(params.changes) do
        if change.type == FileChangeType.Created then
            lsp.workspace:addFile(change.uri)
        elseif change.type == FileChangeType.Deleted then
            lsp.workspace:removeFile(change.uri)
            -- 删除文件后,清除该文件的诊断
            lsp:clearDiagnostics(change.uri)
        end
        if lsp:getVM(change.uri) then
            needReset = true
        end
    end
    -- 缓存过的文件发生变化后,重新计算
    if needReset then
        lsp.workspace:reset()
    end
end