summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-19 20:21:27 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-19 20:21:27 +0800
commit39af624faa6909ea16f1815e819915c6b95d3bd5 (patch)
tree83a2bda8cc48d88d49896fb2ea96593bf0c156f1
parent5750d4484d4f98c8e4e535277066f10452cb0e72 (diff)
downloadlua-language-server-39af624faa6909ea16f1815e819915c6b95d3bd5.zip
path in config supports `~/xxxx`
-rw-r--r--changelog.md1
-rw-r--r--main.lua21
-rw-r--r--script/config/loader.lua7
-rw-r--r--script/utility.lua13
-rw-r--r--script/workspace/workspace.lua13
5 files changed, 30 insertions, 25 deletions
diff --git a/changelog.md b/changelog.md
index 7221ba9f..74b6fedd 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,7 @@
# changelog
## 2.3.1
+* `CHG` path in config supports `~/xxxx`
* `FIX` [#606](https://github.com/sumneko/lua-language-server/issues/606)
* `FIX` [#607](https://github.com/sumneko/lua-language-server/issues/607)
diff --git a/main.lua b/main.lua
index 10c68e5a..7a2e1b9d 100644
--- a/main.lua
+++ b/main.lua
@@ -2,19 +2,8 @@ local currentPath = debug.getinfo(1, 'S').source:sub(2)
local rootPath = currentPath:gsub('[/\\]*[^/\\]-$', '')
rootPath = (rootPath == '' and '.' or rootPath)
loadfile(rootPath .. '/platform.lua')('script')
-local fs = require 'bee.filesystem'
-
-local function expanduser(path)
- if path:sub(1, 1) == '~' then
- local home = os.getenv('HOME')
- if not home then -- has to be Windows
- home = os.getenv 'USERPROFILE' or (os.getenv 'HOMEDRIVE' .. os.getenv 'HOMEPATH')
- end
- return home .. path:sub(2)
- else
- return path
- end
-end
+local fs = require 'bee.filesystem'
+local util = require 'utility'
local function loadArgs()
for _, v in ipairs(arg) do
@@ -39,9 +28,9 @@ end
loadArgs()
-ROOT = fs.path(expanduser(rootPath))
-LOGPATH = LOGPATH and expanduser(LOGPATH) or (ROOT:string() .. '/log')
-METAPATH = METAPATH and expanduser(METAPATH) or (ROOT:string() .. '/meta')
+ROOT = fs.path(util.expandPath(rootPath))
+LOGPATH = LOGPATH and util.expandPath(LOGPATH) or (ROOT:string() .. '/log')
+METAPATH = METAPATH and util.expandPath(METAPATH) or (ROOT:string() .. '/meta')
---@diagnostic disable-next-line: deprecated
debug.setcstacklimit(200)
diff --git a/script/config/loader.lua b/script/config/loader.lua
index b0e8b6db..436bbee9 100644
--- a/script/config/loader.lua
+++ b/script/config/loader.lua
@@ -17,12 +17,7 @@ end
local m = {}
function m.loadLocalConfig(filename)
- local path = fs.path(filename)
- if path:is_relative() then
- if workspace.path then
- path = fs.path(workspace.path) / path
- end
- end
+ local path = fs.path(workspace.getAbsolutePath(filename))
local ext = path:extension():string():lower()
local buf = fsu.loadFile(path)
if not buf then
diff --git a/script/utility.lua b/script/utility.lua
index 16c5e0c9..b838f3a8 100644
--- a/script/utility.lua
+++ b/script/utility.lua
@@ -16,6 +16,7 @@ local mathAbs = math.abs
local mathRandom = math.random
local ioOpen = io.open
local utf8Len = utf8.len
+local getenv = os.getenv
local mathHuge = math.huge
local inf = 1 / 0
local nan = 0 / 0
@@ -634,4 +635,16 @@ function m.trim(str, mode)
return str:match '^%s*(%S+)%s*$'
end
+function m.expandPath(path)
+ if path:sub(1, 1) == '~' then
+ local home = getenv('HOME')
+ if not home then -- has to be Windows
+ home = getenv 'USERPROFILE' or (getenv 'HOMEDRIVE' .. getenv 'HOMEPATH')
+ end
+ return home .. path:sub(2)
+ else
+ return path
+ end
+end
+
return m
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index b98face5..73b6138d 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -13,6 +13,7 @@ local progress = require 'progress'
local define = require "proto.define"
local client = require 'client'
local plugin = require 'plugin'
+local util = require 'utility'
local m = {}
m.type = 'workspace'
@@ -460,6 +461,7 @@ function m.normalize(path)
return (ROOT / 'meta' / '3rd'):string()
end
end)
+ path = util.expandPath(path)
if platform.OS == 'Windows' then
path = path:gsub('[/\\]+', '\\')
:gsub('[/\\]+$', '')
@@ -485,10 +487,15 @@ function m.getAbsolutePath(path)
return path
end
----@param uri uri
+---@param uriOrPath uri|string
---@return string
-function m.getRelativePath(uri)
- local path = furi.decode(uri)
+function m.getRelativePath(uriOrPath)
+ local path
+ if uriOrPath:sub(1, 5) == 'file:' then
+ path = furi.decode(uriOrPath)
+ else
+ path = uriOrPath
+ end
if not m.path then
local relative = m.normalize(path)
return relative:gsub('^[/\\]+', '')