From ae53ebf48299680b8906e848903fb32d56ee90a5 Mon Sep 17 00:00:00 2001 From: xl000 Date: Wed, 17 Apr 2019 01:16:12 +0800 Subject: =?UTF-8?q?Unix-like=E7=B3=BB=E7=BB=9F=E8=B7=AF=E5=BE=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8Cosx=E4=B8=8B=E6=B5=8B=E8=AF=95=E9=80=9A?= =?UTF-8?q?=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + server/publish.lua | 2 +- server/src/workspace.lua | 4 ++++ server/test.lua | 28 ++++++++++++++++++++++++++++ server/test/crossfile/hover.lua | 3 ++- 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 server/test.lua diff --git a/.gitignore b/.gitignore index 02485305..81cbfaf3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ node_modules .vscode-test /server/log /server/bin +/server/*.so /publish /build/ !*.exe diff --git a/server/publish.lua b/server/publish.lua index 3b4d4420..c7cbefcc 100644 --- a/server/publish.lua +++ b/server/publish.lua @@ -63,7 +63,7 @@ local function copyFiles(root, out) end local function runTest(root) - local exe = root / 'bin' / 'lua-language-server.exe' + local exe = root / 'bin' / 'lua-language-server' local test = root / 'test' / 'main.lua' local lua = subprocess.spawn { exe, diff --git a/server/src/workspace.lua b/server/src/workspace.lua index 2837f5a2..ef449e1a 100644 --- a/server/src/workspace.lua +++ b/server/src/workspace.lua @@ -52,6 +52,10 @@ local mt = {} mt.__index = mt function mt:uriDecode(uri) + -- Unix-like系统根是/ + if uri:sub(1, 9) == 'file:////' then + return fs.path(uri:sub(9)) + end if uri:sub(1, 8) ~= 'file:///' then log.error('uri decode failed: ', uri) return nil diff --git a/server/test.lua b/server/test.lua new file mode 100644 index 00000000..fe2efd23 --- /dev/null +++ b/server/test.lua @@ -0,0 +1,28 @@ +local fs = require 'bee.filesystem' +local subprocess = require 'bee.subprocess' + +ROOT = fs.current_path() +package.path = (ROOT / 'src' / '?.lua'):string() + .. ';' .. (ROOT / 'src' / '?' / 'init.lua'):string() + +local function runTest(root) + local exe = root / 'bin' / 'lua-language-server' + local test = root / 'test' / 'main.lua' + local lua = subprocess.spawn { + exe, + test, + '-E', + stdout = true, + stderr = true, + } + for line in lua.stdout:lines 'l' do + print(line) + end + lua:wait() + local err = lua.stderr:read 'a' + if err ~= '' then + error(err) + end +end + +runTest(ROOT) diff --git a/server/test/crossfile/hover.lua b/server/test/crossfile/hover.lua index cdc4ebca..41aef8dc 100644 --- a/server/test/crossfile/hover.lua +++ b/server/test/crossfile/hover.lua @@ -76,7 +76,8 @@ function TEST(data) local hover = core.hover(source, lsp) assert(hover) if data.hover.description then - data.hover.description = data.hover.description:gsub('%$ROOT%$', ws:uriEncode(ROOT):gsub('%%', '%%%%')) + local uriROOT = ws:uriEncode(ROOT):gsub('%%', '%%%%') + data.hover.description = data.hover.description:gsub('%$ROOT%$', uriROOT) end if hover.label then hover.label = hover.label:gsub('\r\n', '\n') -- cgit v1.2.3