summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-21 18:32:40 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-21 18:32:40 +0800
commitc354b5e8bd05ba117857ac93e8d647980875d98d (patch)
tree2ec81c0e5c0713760a1c94b475cabe2baae9a2d2
parent3ef04652c31fa95ce1749f0309566f386ec70854 (diff)
downloadlua-language-server-c354b5e8bd05ba117857ac93e8d647980875d98d.zip
暂存
-rw-r--r--.vscode/launch.json12
-rw-r--r--server-beta/src/core/hover/function.lua10
-rw-r--r--server-beta/src/core/hover/init.lua39
-rw-r--r--server-beta/test.lua2
-rw-r--r--server-beta/test/crossfile/document_symbol.lua121
-rw-r--r--server-beta/test/crossfile/init.lua1
-rw-r--r--server-beta/test/hover/init.lua24
7 files changed, 66 insertions, 143 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index a60710f0..44af2651 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -12,7 +12,8 @@
],
"consoleCoding": "utf8",
"sourceCoding": "utf8",
- "luaRuntime": "5.4 64bit",
+ "luaVersion": "5.4",
+ "luaArch": "x86_64",
"outputCapture": [
"print",
"stderr",
@@ -44,7 +45,8 @@
"consoleCoding": "utf8",
"sourceCoding": "utf8",
"preLaunchTask": "编译",
- "luaRuntime": "5.4 64bit",
+ "luaVersion": "5.4",
+ "luaArch": "x86_64",
"outputCapture": [
"print",
"stderr",
@@ -60,7 +62,8 @@
],
"consoleCoding": "utf8",
"sourceCoding": "utf8",
- "luaRuntime": "5.4 64bit",
+ "luaVersion": "5.4",
+ "luaArch": "x86_64",
"outputCapture": [
"print",
"stderr",
@@ -76,7 +79,8 @@
],
"consoleCoding": "utf8",
"sourceCoding": "utf8",
- "luaRuntime": "5.4 64bit",
+ "luaVersion": "5.4",
+ "luaArch": "x86_64",
"outputCapture": [
"print",
"stderr",
diff --git a/server-beta/src/core/hover/function.lua b/server-beta/src/core/hover/function.lua
new file mode 100644
index 00000000..15e54306
--- /dev/null
+++ b/server-beta/src/core/hover/function.lua
@@ -0,0 +1,10 @@
+local m = {}
+
+function m.label(source)
+ if source.type ~= 'function' then
+ return
+ end
+
+end
+
+return m
diff --git a/server-beta/src/core/hover/init.lua b/server-beta/src/core/hover/init.lua
new file mode 100644
index 00000000..af1bf6da
--- /dev/null
+++ b/server-beta/src/core/hover/init.lua
@@ -0,0 +1,39 @@
+local files = require 'files'
+local guide = require 'parser.guide'
+local vm = require 'vm'
+local funcHover = require 'core.hover.function'
+
+local function getHoverAsFunction(source)
+ local values = vm.getValue(source)
+ for _, value in ipairs(values) do
+ if value.type == 'function' then
+ local funcLabel = funcHover.label(value.source)
+ end
+ end
+end
+
+local function getHover(source)
+ local isFunction = vm.hasType(source, 'function')
+ if isFunction then
+ getHoverAsFunction(source)
+ end
+end
+
+return function (uri, offset)
+ local ast = files.getAst(uri)
+ if not ast then
+ return nil
+ end
+ local hover = guide.eachSourceContain(ast.ast, offset, function (source)
+ if source.type == 'local'
+ or source.type == 'setlocal'
+ or source.type == 'getlocal'
+ or source.type == 'setglobal'
+ or source.type == 'getglobal'
+ or source.type == 'field'
+ or source.type == 'method' then
+ return getHover(source)
+ end
+ end)
+ return hover
+end
diff --git a/server-beta/test.lua b/server-beta/test.lua
index dffae940..dc1023d6 100644
--- a/server-beta/test.lua
+++ b/server-beta/test.lua
@@ -42,7 +42,7 @@ local function main()
test 'highlight'
test 'rename'
test 'type_inference'
- --test 'hover'
+ test 'hover'
--test 'completion'
--test 'signature'
--test 'document_symbol'
diff --git a/server-beta/test/crossfile/document_symbol.lua b/server-beta/test/crossfile/document_symbol.lua
deleted file mode 100644
index 997d42c5..00000000
--- a/server-beta/test/crossfile/document_symbol.lua
+++ /dev/null
@@ -1,121 +0,0 @@
-local service = require 'service'
-local workspace = require 'workspace'
-local fs = require 'bee.filesystem'
-local core = require 'core'
-local uric = require 'uri'
-
-local SymbolKind = {
- File = 1,
- Module = 2,
- Namespace = 3,
- Package = 4,
- Class = 5,
- Method = 6,
- Property = 7,
- Field = 8,
- Constructor = 9,
- Enum = 10,
- Interface = 11,
- Function = 12,
- Variable = 13,
- Constant = 14,
- String = 15,
- Number = 16,
- Boolean = 17,
- Array = 18,
- Object = 19,
- Key = 20,
- Null = 21,
- EnumMember = 22,
- Struct = 23,
- Event = 24,
- Operator = 25,
- TypeParameter = 26,
-}
-
-local EXISTS = {}
-
-local function eq(a, b)
- if a == EXISTS and b ~= nil then
- return true
- end
- local tp1, tp2 = type(a), type(b)
- if tp1 ~= tp2 then
- return false
- end
- if tp1 == 'table' then
- local mark = {}
- for k in pairs(a) do
- if not eq(a[k], b[k]) then
- return false
- end
- mark[k] = true
- end
- for k in pairs(b) do
- if not mark[k] then
- return false
- end
- end
- return true
- end
- return a == b
-end
-
-rawset(_G, 'TEST', true)
-
-function TEST(data)
- local lsp = service()
- local ws = workspace(lsp, 'test')
- lsp.workspace = ws
-
- local targetUri = uric.encode(fs.path(data[1].path))
- local sourceUri = uric.encode(fs.path(data[2].path))
-
- lsp:saveText(sourceUri, 1, data[2].content)
- ws:addFile(uric.decode(sourceUri))
- lsp:saveText(targetUri, 1, data[1].content)
- ws:addFile(uric.decode(targetUri))
- while lsp._needCompile[1] do
- lsp:compileVM(lsp._needCompile[1])
- end
-
- local sourceVM = lsp:getVM(sourceUri)
- assert(sourceVM)
- local result = core.documentSymbol(sourceVM)
- assert(eq(data.symbol, result))
-end
-
-TEST {
- {
- path = 'a.lua',
- content = 'return function () end',
- },
- {
- path = 'b.lua',
- content = [[
-local t = {
- x = require 'a',
-}
- ]],
- },
- symbol = {
- [1] = {
- name = 't',
- detail = EXISTS,
- kind = SymbolKind.Variable,
- range = {7, 7},
- selectionRange = {7, 7},
- valueRange = {11, 34},
- children = {
- [1] = {
- name = 'x',
- detail = EXISTS,
- kind = SymbolKind.Class,
- range = {17, 17},
- selectionRange = {17, 17},
- valueRange = {21, 31},
- },
- }
- }
- }
-}
diff --git a/server-beta/test/crossfile/init.lua b/server-beta/test/crossfile/init.lua
index c516fc7f..c67b3b8f 100644
--- a/server-beta/test/crossfile/init.lua
+++ b/server-beta/test/crossfile/init.lua
@@ -2,4 +2,3 @@ require 'crossfile.references'
require 'crossfile.definition'
--require 'crossfile.hover'
--require 'crossfile.completion'
---require 'crossfile.document_symbol'
diff --git a/server-beta/test/hover/init.lua b/server-beta/test/hover/init.lua
index 87b4cc99..9552e753 100644
--- a/server-beta/test/hover/init.lua
+++ b/server-beta/test/hover/init.lua
@@ -1,28 +1,20 @@
-local parser = require 'parser'
-local core = require 'core'
-local buildVM = require 'vm'
+local core = require 'core.hover'
+local files = require 'files'
rawset(_G, 'TEST', true)
function TEST(script)
return function (expect)
+ files.removeAll()
local start = script:find('<?', 1, true)
local finish = script:find('?>', 1, true)
local pos = (start + finish) // 2 + 1
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
- local ast = parser:parse(new_script, 'lua', 'Lua 5.3')
- local vm = buildVM(ast)
- assert(vm)
- local source = core.findSource(vm, pos)
- local hover = core.hover(source)
- if expect then
- assert(hover)
- expect = expect:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n')
- local label = hover.label:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n')
- assert(expect == label)
- else
- assert(hover == nil)
- end
+ local hover = core(new_script, pos)
+ assert(hover)
+ expect = expect:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n')
+ local label = hover.label:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n')
+ assert(expect == label)
end
end