summaryrefslogtreecommitdiff
path: root/script/filename.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-07-08 19:51:10 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-07-08 19:51:10 +0800
commitae3a20cfd5ea89919326a6499c5a3c93fdfe2120 (patch)
treeb4b337b82bda3a14f300ab30862efd12b6e10650 /script/filename.lua
parent5354d8c339ddb6487f3c0ec1b240eb3e93d19585 (diff)
downloadlua-language-server-ae3a20cfd5ea89919326a6499c5a3c93fdfe2120.zip
fix #187
Diffstat (limited to 'script/filename.lua')
-rw-r--r--script/filename.lua65
1 files changed, 65 insertions, 0 deletions
diff --git a/script/filename.lua b/script/filename.lua
new file mode 100644
index 00000000..a28b004c
--- /dev/null
+++ b/script/filename.lua
@@ -0,0 +1,65 @@
+local platform = require 'bee.platform'
+local config = require 'config'
+local m = {}
+
+local TrueName = {}
+
+function m.getFileName(path)
+ local name = path:string()
+ if platform.OS == 'Windows' then
+ local lname = name:lower()
+ TrueName[lname] = name
+ return lname
+ else
+ return name
+ end
+end
+
+function m.getTrueName(name)
+ return TrueName[name] or name
+end
+
+local function split(str, sep)
+ local t = {}
+ for s in str:gmatch('[^' .. sep .. ']+') do
+ t[#t+1] = s
+ end
+ return t
+end
+
+function m.similarity(a, b)
+ local ta = split(a, '/\\')
+ local tb = split(b, '/\\')
+ for i = 1, #ta do
+ if ta[i] ~= tb[i] then
+ return i - 1
+ end
+ end
+ return #ta
+end
+
+function m.isLuaFile(path)
+ local pathStr = path:string()
+ for k, v in pairs(config.other.associations) do
+ if v == 'lua' then
+ k = k:gsub('^%*', '')
+ if m.fileNameEq(pathStr:sub(-#k), k) then
+ return true
+ end
+ end
+ end
+ if m.fileNameEq(pathStr:sub(-4), '.lua') then
+ return true
+ end
+ return false
+end
+
+function m.fileNameEq(a, b)
+ if platform.OS == 'Windows' then
+ return a:lower() == b:lower()
+ else
+ return a == b
+ end
+end
+
+return m