summaryrefslogtreecommitdiff
path: root/server/src/files/file.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-06-21 18:14:16 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-06-21 18:14:16 +0800
commit21b7cc4df0295df5915a7b4328c04f71e7cf25ca (patch)
tree1856960736bdd43f7c2df18f4c27c911a62cdc76 /server/src/files/file.lua
parentdc0a3791060a6236bac4251a27eb7d7f2de3cb89 (diff)
downloadlua-language-server-21b7cc4df0295df5915a7b4328c04f71e7cf25ca.zip
暂存一下
Diffstat (limited to 'server/src/files/file.lua')
-rw-r--r--server/src/files/file.lua71
1 files changed, 64 insertions, 7 deletions
diff --git a/server/src/files/file.lua b/server/src/files/file.lua
index e8cd783b..deaea8ba 100644
--- a/server/src/files/file.lua
+++ b/server/src/files/file.lua
@@ -1,33 +1,90 @@
+---@class file
local mt = {}
mt.__index = mt
mt.type = 'file'
mt._uri = ''
mt._text = ''
-mt._open = false
+mt._version = -1
+---@param buf string
function mt:setText(buf)
self._text = buf
end
+---@return string
function mt:getText()
return self._text
end
-function mt:open()
- self._open = true
+---@param version integer
+function mt:setVersion(version)
+ self._version = version
end
-function mt:close()
- self._open = false
+---@return integer
+function mt:getVersion()
+ return self._version
end
-function mt:isOpen()
- return self._open
+function mt:remove()
+ if self._removed then
+ return
+ end
+ self._removed = true
+ self._text = nil
+ self._version = nil
+ if self._vm then
+ self._vm:remove()
+ end
end
+---@param vm VM
+function mt:saveVM(vm)
+ self._vm = vm
+end
+
+---@return VM
+function mt:getVM()
+ return self._vm
+end
+
+function mt:removeVM()
+ if not self._vm then
+ return
+ end
+ self._vm:remove()
+ self._vm = nil
+end
+
+---@return file
+function mt:getParent()
+ return self._parent
+end
+
+---@param uri uri
+function mt:removeChild(uri)
+ self._child[uri] = nil
+end
+
+---@param uri uri
+function mt:removeParent(uri)
+ self._parent[uri] = nil
+end
+
+function mt:eachChild()
+ return pairs(self._child)
+end
+
+function mt:eachParent()
+ return pairs(self._parent)
+end
+
+---@param uri string
return function (uri)
local self = setmetatable({
_uri = uri,
+ _parent = {},
+ _child = {},
}, mt)
return self
end