diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-16 16:36:52 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-16 16:36:52 +0800 |
commit | 4cb9c12ca12e3ce6e254897cc1a72f651bd9fdf8 (patch) | |
tree | 9195751e0a581d844a8d3efbefaae3a9c1494151 /server/src/workspace.lua | |
parent | cafdbefc9bb4b1e70fbc7d1bb6d0e3b682395f36 (diff) | |
download | lua-language-server-4cb9c12ca12e3ce6e254897cc1a72f651bd9fdf8.zip |
Windows平台也使用路径的原始大小写
Diffstat (limited to 'server/src/workspace.lua')
-rw-r--r-- | server/src/workspace.lua | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/server/src/workspace.lua b/server/src/workspace.lua index 06048423..9012f721 100644 --- a/server/src/workspace.lua +++ b/server/src/workspace.lua @@ -21,6 +21,14 @@ local function getTrueName(name) return TrueName[name] or name end +local function fileNameEq(a, b) + if platform.OS == 'Windows' then + return a:lower() == b:lower() + else + return a == b + end +end + local function split(str, sep) local t = {} for s in str:gmatch('[^' .. sep .. ']+') do @@ -233,7 +241,22 @@ function mt:createCompiler(str) count = count + 1 local name = 'C' .. tostring(count) local nextName = 'C' .. tostring(count + 1) - state[name] = ll.P(c) * #ll.V(nextName) + local catch = #ll.V(nextName) + if platform.OS == 'Windows' then + for i = #c, 1, -1 do + local char = c:sub(i, i) + local u = char:upper() + local l = char:lower() + if u == l then + catch = ll.P(char) * catch + else + catch = (ll.P(u) + ll.P(l)) * catch + end + end + else + catch = ll.P(c) * catch + end + state[name] = catch return ll.V(name) end local function eof() @@ -295,9 +318,6 @@ function mt:convertPathAsRequire(filename, start) end function mt:matchPath(baseUri, input) - if platform.OS == 'Windows' then - input = input:lower() - end local first = input:match '[^%.]+' if not first then return nil @@ -306,13 +326,18 @@ function mt:matchPath(baseUri, input) local rootLen = #self.root:string() local map = {} for filename in pairs(self.files) do - local start = filename:find('/' .. first, rootLen + 1, true) + local trueFilename = getTrueName(filename) + local start + if platform.OS == 'Windows' then + start = filename:find('[/\\]' .. first:lower(), rootLen + 1) + else + start = trueFilename:find('[/\\]' .. first, rootLen + 1) + end if start then - local list = self:convertPathAsRequire(filename, start + 1) + local list = self:convertPathAsRequire(trueFilename, start + 1) if list then - local trueFilename = getTrueName(filename) for _, str in ipairs(list) do - if #str >= #input and str:sub(1, #input) == input then + if #str >= #input and fileNameEq(str:sub(1, #input), input) then if not map[str] then map[str] = trueFilename else |