diff --git a/changelog.md b/changelog.md index acf13ee69..aaf85af2d 100644 --- a/changelog.md +++ b/changelog.md @@ -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) diff --git a/script/files.lua b/script/files.lua index 5e86d217b..37aef7e19 100644 --- a/script/files.lua +++ b/script/files.lua @@ -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 @@ -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 diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua index 2ea981e73..3cdeaad6c 100644 --- a/script/workspace/loading.lua +++ b/script/workspace/loading.lua @@ -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) @@ -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)