summaryrefslogtreecommitdiff
path: root/script/method/textDocument/didChange.lua
blob: fd8af6bac2cbad295723aacf2535fe1f8b3ece74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
local fn = require 'filename'

--- @param lsp LSP
--- @param params table
--- @return boolean
return function (lsp, params)
    local doc = params.textDocument
    local change = params.contentChanges
    local ws = lsp:findWorkspaceFor(doc.uri)
    if ws then
        local path = ws:relativePathByUri(doc.uri)
        if not path or not fn.isLuaFile(path) then
            return
        end
        if not lsp:isOpen(doc.uri) and ws.gitignore(path:string()) then
            return
        end
    end
    -- TODO 支持差量更新
    lsp:saveText(doc.uri, doc.version, change[1].text)
    return true
end