Skip to content

Commit

Permalink
fix ref
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jan 27, 2022
1 parent 7b19ab0 commit e9c319a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# changelog

## 2.6.3
`2022-1-25`
* `FIX` new files are not loaded correctly
* `FIX` [#923](https://github.com/sumneko/lua-language-server/issues/923)
* `FIX` [#926](https://github.com/sumneko/lua-language-server/issues/926)
Expand Down
2 changes: 2 additions & 0 deletions script/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ function m.addRef(uri)
return nil
end
file._ref = (file._ref or 0) + 1
log.debug('add ref', uri)
return function ()
m.delRef(uri)
end
Expand All @@ -378,6 +379,7 @@ function m.delRef(uri)
return
end
file._ref = (file._ref or 0) - 1
log.debug('del ref', uri)
if file._ref <= 0 then
m.remove(uri)
end
Expand Down
24 changes: 14 additions & 10 deletions script/workspace/loading.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,24 @@ function mt:loadFile(uri, libraryUri)
if files.getFile(uri) then
self.read = self.read + 1
self:update()
files.addRef(uri)
if not self._cache[uri] then
files.addRef(uri)
end
self._cache[uri] = true
log.info(('Skip loaded file: %s'):format(uri))
else
local content = pub.awaitTask('loadFile', furi.decode(uri))
self.read = self.read + 1
self:update()
if not self._cache[uri] then
files.addRef(uri)
end
self._cache[uri] = true
if not content then
return
end
log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #content / 1024.0))
files.setText(uri, content, false)
if not self._cache[uri] then
files.addRef(uri)
end
self._cache[uri] = true
end
if libraryUri then
log.info('++++As library of:', libraryUri)
Expand All @@ -110,22 +112,24 @@ function mt:loadFile(uri, libraryUri)
if files.getFile(uri) then
self.read = self.read + 1
self:update()
files.addRef(uri)
if not self._cache[uri] then
files.addRef(uri)
end
self._cache[uri] = true
log.info(('Skip loaded file: %s'):format(uri))
else
local content = pub.awaitTask('loadFile', furi.decode(uri))
self.read = self.read + 1
self:update()
if not self._cache[uri] then
files.addRef(uri)
end
self._cache[uri] = true
if not content then
return
end
log.info(('Preload dll at: %s , size = %.3f KB'):format(uri, #content / 1024.0))
files.saveDll(uri, content)
if not self._cache[uri] then
files.addRef(uri)
end
self._cache[uri] = true
end
if libraryUri then
log.info('++++As library of:', libraryUri)
Expand Down

0 comments on commit e9c319a

Please sign in to comment.