summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lsp.lua11
-rw-r--r--src/method/init.lua1
-rw-r--r--src/method/textDocument/didClose.lua6
3 files changed, 18 insertions, 0 deletions
diff --git a/src/lsp.lua b/src/lsp.lua
index 6c801a33..563f7919 100644
--- a/src/lsp.lua
+++ b/src/lsp.lua
@@ -118,6 +118,17 @@ function mt:loadText(uri)
return obj.text
end
+function mt:removeText(uri, version)
+ local obj = self._file[uri]
+ if not obj then
+ return
+ end
+ if obj.version >= version then
+ return
+ end
+ self._file[uri] = nil
+end
+
function mt:start(method)
self._method = method
while true do
diff --git a/src/method/init.lua b/src/method/init.lua
index 35a5a124..2674f7ae 100644
--- a/src/method/init.lua
+++ b/src/method/init.lua
@@ -8,5 +8,6 @@ init 'initialize'
init 'textDocument/definition'
init 'textDocument/didOpen'
init 'textDocument/didChange'
+init 'textDocument/didClose'
return method
diff --git a/src/method/textDocument/didClose.lua b/src/method/textDocument/didClose.lua
new file mode 100644
index 00000000..3dcbd7d7
--- /dev/null
+++ b/src/method/textDocument/didClose.lua
@@ -0,0 +1,6 @@
+return function (lsp, params)
+ local doc = params.textDocument
+ log.debug('关闭文件:', doc.uri)
+ lsp:removeText(doc.uri, doc.version)
+ return true
+end