diff options
author | sumneko <sumneko@hotmail.com> | 2021-11-25 00:19:42 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2021-11-25 00:19:42 +0800 |
commit | 8a4e2274e25d005a2c9e30512105b3a5e527b8df (patch) | |
tree | 3c4513b97901c07adf3fa227249721c02482ad9a /script/files.lua | |
parent | 3b7f8cee482d4980a4d0d5ec8fde3b76337a1a50 (diff) | |
parent | 35ecea910789fbd470d0c6d68b75409ac3c3e21e (diff) | |
download | lua-language-server-8a4e2274e25d005a2c9e30512105b3a5e527b8df.zip |
Merge remote-tracking branch 'origin/bugfix'
Diffstat (limited to 'script/files.lua')
-rw-r--r-- | script/files.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/script/files.lua b/script/files.lua index a779f0f6..d5344847 100644 --- a/script/files.lua +++ b/script/files.lua @@ -1,4 +1,5 @@ local platform = require 'bee.platform' +local fs = require 'bee.filesystem' local config = require 'config' local glob = require 'glob' local furi = require 'file-uri' @@ -29,6 +30,33 @@ m.fileCount = 0 m.astCount = 0 m.astMap = {} -- setmetatable({}, { __mode = 'v' }) +local fixedUri = {} +--- 获取文件的真实uri(真实大小写) +---@param uri uri +---@return uri +function m.getRealUri(uri) + if platform.OS ~= 'Windows' then + return uri + end + local filename = furi.decode(uri) + local path = fs.path(filename) + local suc, res = pcall(fs.exists, path) + if not suc or not res then + return uri + end + suc, res = pcall(fs.canonical, path) + if not suc or res:string() == filename then + return uri + end + filename = res:string() + local ruri = furi.encode(filename) + if not fixedUri[ruri] then + fixedUri[ruri] = true + log.warn(('Fix real file uri: %s -> %s'):format(uri, ruri)) + end + return ruri +end + --- 打开文件 ---@param uri uri function m.open(uri) @@ -156,6 +184,7 @@ function m.setText(uri, text, isTrust, version) file.text = newText file.trusted = isTrust file.originText = text + file.rows = nil file.words = nil m.astMap[uri] = nil file.cache = {} |