summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-05-06 14:48:44 +0800
committersumneko <sumneko@hotmail.com>2019-05-06 14:48:44 +0800
commitdf62d7a467cc2ffa1d4945c4912a4568baf75847 (patch)
treebc9329d5eb349cea72ab1f660d9ed7c7d2af620a /server
parentcbd5169adaed554fe5ae3b2c9f4141039c2082cd (diff)
downloadlua-language-server-df62d7a467cc2ffa1d4945c4912a4568baf75847.zip
emmySee
Diffstat (limited to 'server')
-rw-r--r--server/src/core/definition.lua15
-rw-r--r--server/src/parser/ast.lua4
-rw-r--r--server/src/parser/grammar.lua2
-rw-r--r--server/src/utility.lua9
-rw-r--r--server/src/vm/emmy.lua7
-rw-r--r--server/test/definition/emmy.lua10
6 files changed, 41 insertions, 6 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua
index 4ed70bc4..c2a29dae 100644
--- a/server/src/core/definition.lua
+++ b/server/src/core/definition.lua
@@ -179,6 +179,18 @@ local function parseClass(callback, vm, source)
end)
end
+local function parseSee(callback, vm, source)
+ local see = source:get 'emmy see'
+ local className = see[1][1]
+ local childName = see[2][1]
+ vm.emmyMgr:eachClass(className, function (class)
+ ---@type value
+ local value = class:getValue()
+ local child = value:getChild(childName)
+ parseValueByValue(callback, vm, source, child)
+ end)
+end
+
local function parseFunction(callback, vm, source)
if Mode == 'definition' then
callback(source:bindFunction():getSource())
@@ -260,6 +272,9 @@ return function (vm, pos, mode)
if source:get 'emmy class' then
parseClass(callback, vm, source)
end
+ if source:get 'emmy see' then
+ parseSee(callback, vm, source)
+ end
if #list == 0 then
parseValueSimily(callback, vm, source)
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua
index 5a3630cd..12077f8e 100644
--- a/server/src/parser/ast.lua
+++ b/server/src/parser/ast.lua
@@ -1242,9 +1242,11 @@ local Defs = {
language,
}
end,
- EmmySee = function (className, methodName)
+ EmmySee = function (start, className, methodName, finish)
return {
type = 'emmySee',
+ start = start,
+ finish = finish - 1,
className, methodName
}
end,
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index 25ac30f2..90e12e39 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -586,7 +586,7 @@ EmmyFunctionArgs<- '(' %s* EmmyFunctionArg %s* (',' %s* EmmyFunctionArg %s*)* '
EmmyFunctionRtn <- ':' %s* EmmyType
EmmyFunctionArg <- MustEmmyName %s* ':' %s* EmmyType
-EmmySee <- MustEmmyName '#' MustEmmyName
+EmmySee <- {} MustEmmyName %s* '#' %s* MustEmmyName {}
]]
grammar 'Lua' [[
diff --git a/server/src/utility.lua b/server/src/utility.lua
index b908bdc7..0817bc03 100644
--- a/server/src/utility.lua
+++ b/server/src/utility.lua
@@ -1,7 +1,7 @@
local fs = require 'bee.filesystem'
local table_sort = table.sort
-local string_rep = string.rep
+local stringRep = string.rep
local type = type
local pairs = pairs
local ipairs = ipairs
@@ -20,7 +20,7 @@ local function formatNumber(n)
end
local TAB = setmetatable({}, { __index = function (self, n)
- self[n] = string_rep('\t', n)
+ self[n] = stringRep('\t', n)
return self[n]
end})
@@ -57,11 +57,11 @@ function table.dump(tbl)
local mark = {}
lines[#lines+1] = '{'
local function unpack(tbl, tab)
- if tab > 10 and mark[tbl] then
+ if mark[tbl] and mark[tbl] > 0 then
lines[#lines+1] = TAB[tab+1] .. '"<Loop>"'
return
end
- mark[tbl] = true
+ mark[tbl] = (mark[tbl] or 0) + 1
local keys = {}
local keymap = {}
local integerFormat = '[%d]'
@@ -108,6 +108,7 @@ function table.dump(tbl)
lines[#lines+1] = ('%s%s = %s,'):format(TAB[tab+1], keymap[key], tostring(value))
end
end
+ mark[tbl] = mark[tbl] - 1
end
unpack(tbl, 0)
lines[#lines+1] = '}'
diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua
index 7a82cfcd..4ecef4d3 100644
--- a/server/src/vm/emmy.lua
+++ b/server/src/vm/emmy.lua
@@ -35,6 +35,7 @@ function mt:doEmmy(action)
elseif tp == 'emmyFunctionType' then
self:doEmmyFunctionType(action)
elseif tp == 'emmySee' then
+ self:doEmmySee(action)
elseif tp == 'emmyIncomplete' then
self:doEmmyIncomplete(action)
end
@@ -312,3 +313,9 @@ end
function mt:doEmmyIncomplete(action)
self:instantSource(action)
end
+
+function mt:doEmmySee(action)
+ self:instantSource(action)
+ self:instantSource(action[2])
+ action[2]:set('emmy see', action)
+end
diff --git a/server/test/definition/emmy.lua b/server/test/definition/emmy.lua
index fde1fe17..ee8fa6a7 100644
--- a/server/test/definition/emmy.lua
+++ b/server/test/definition/emmy.lua
@@ -79,3 +79,13 @@ TEST [[
local mt = {}
mt.<?name?>
]]
+
+TEST [[
+---@class loli
+local unit
+
+function unit:<!pants!>()
+end
+
+---@see loli#<?pants?>
+]]