summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-06-24 22:03:56 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-06-24 22:03:56 +0800
commit58a69cb45e07601354b3f14199999dcf213037c6 (patch)
treebe6d9ffdd8d5960f18a3f571ffbe5d73016d5944
parentb2e64a958248b90d3f16e4ebe4d415f8ae87a454 (diff)
downloadlua-language-server-58a69cb45e07601354b3f14199999dcf213037c6.zip
#52 支持 emmy 注释
-rw-r--r--server/src/core/hover/function.lua9
-rw-r--r--server/src/core/hover/hover.lua8
-rw-r--r--server/src/parser/ast.lua6
-rw-r--r--server/src/parser/grammar.lua6
-rw-r--r--server/src/vm/emmy.lua14
-rw-r--r--server/src/vm/function.lua10
-rw-r--r--server/src/vm/local.lua10
-rw-r--r--server/src/vm/vm.lua7
8 files changed, 67 insertions, 3 deletions
diff --git a/server/src/core/hover/function.lua b/server/src/core/hover/function.lua
index e792485b..8621aee0 100644
--- a/server/src/core/hover/function.lua
+++ b/server/src/core/hover/function.lua
@@ -91,9 +91,17 @@ local function buildValueReturns(func)
return '\n -> ' .. table.concat(strs, ', ')
end
+local function getComment(func)
+ if not func then
+ return nil
+ end
+ return func:getComment() or ''
+end
+
return function (name, func, object, select)
local args, argLabel = buildValueArgs(func, object, select)
local returns = buildValueReturns(func)
+ local comment = getComment(func)
local headLen = #('function %s('):format(name)
local title = ('function %s(%s)%s'):format(name, args, returns)
if argLabel then
@@ -103,5 +111,6 @@ return function (name, func, object, select)
return {
label = title,
argLabel = argLabel,
+ description = comment,
}
end
diff --git a/server/src/core/hover/hover.lua b/server/src/core/hover/hover.lua
index eb82d4cc..25a1bc3b 100644
--- a/server/src/core/hover/hover.lua
+++ b/server/src/core/hover/hover.lua
@@ -214,6 +214,14 @@ local function getValueHover(source, name, value, lib)
end
end
end
+ local comment = loc:getComment()
+ if comment then
+ if tip then
+ tip = tip .. '\n\n-------------\n\n' .. comment
+ else
+ tip = comment
+ end
+ end
elseif source:get 'global' then
tp = 'global'
elseif source:get 'simple' then
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua
index b126efb8..d6d6c0c9 100644
--- a/server/src/parser/ast.lua
+++ b/server/src/parser/ast.lua
@@ -1308,6 +1308,12 @@ local Defs = {
emmyName.type = 'emmyIncomplete'
return emmyName
end,
+ EmmyComment = function (...)
+ return {
+ type = 'emmyComment',
+ [1] = table.concat({...}, ' '),
+ }
+ end,
-- 捕获错误
UnknownSymbol = function (start, symbol)
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index 7aa280ba..8b0f7273 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -515,7 +515,11 @@ Emmy <- '---@'
grammar 'Emmy' [[
Emmy <- EmmySp '---@' EmmyBody ShortComment
-EmmySp <- (!'---@' Comment / %s / %nl)*
+ / EmmyComments
+EmmySp <- (!'---@' !'---' Comment / %s / %nl)*
+EmmyComments <- (EmmyComment (%nl EmmyComment)*)
+ -> EmmyComment
+EmmyComment <- EmmySp '---' %s* {(!%nl .)*}
EmmyBody <- 'class' %s+ EmmyClass -> EmmyClass
/ 'type' %s+ EmmyType -> EmmyType
/ 'alias' %s+ EmmyAlias -> EmmyAlias
diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua
index d41a3535..42f3a72a 100644
--- a/server/src/vm/emmy.lua
+++ b/server/src/vm/emmy.lua
@@ -7,6 +7,7 @@ function mt:clearEmmy()
self._emmyParams = nil
self._emmyReturns = nil
self._emmyGeneric = nil
+ self._emmyComment = nil
end
function mt:doEmmy(action)
@@ -38,6 +39,8 @@ function mt:doEmmy(action)
self:doEmmySee(action)
elseif tp == 'emmyIncomplete' then
self:doEmmyIncomplete(action)
+ elseif tp == 'emmyComment' then
+ self:doEmmyComment(action)
end
end
@@ -79,6 +82,13 @@ function mt:getEmmyGeneric()
return generic
end
+---@return string
+function mt:getEmmyComment()
+ local comment = self._emmyComment
+ self._emmyComment = nil
+ return comment
+end
+
function mt:doEmmyClass(action)
---@type emmyMgr
local emmyMgr = self.emmyMgr
@@ -319,6 +329,10 @@ function mt:doEmmyIncomplete(action)
self:instantSource(action)
end
+function mt:doEmmyComment(action)
+ self._emmyComment = action[1]
+end
+
function mt:doEmmySee(action)
self:instantSource(action)
self:instantSource(action[2])
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua
index a6f2b0cf..60498033 100644
--- a/server/src/vm/function.lua
+++ b/server/src/vm/function.lua
@@ -481,6 +481,16 @@ function mt:setEmmy(params, returns)
end
end
+---@param comment string
+function mt:setComment(comment)
+ self._comment = comment
+end
+
+---@return string
+function mt:getComment()
+ return self._comment
+end
+
function mt:getEmmyParams()
return self._emmyParams
end
diff --git a/server/src/vm/local.lua b/server/src/vm/local.lua
index e7355dc2..7e8af0f1 100644
--- a/server/src/vm/local.lua
+++ b/server/src/vm/local.lua
@@ -153,6 +153,16 @@ function mt:setEmmy(emmy)
end
end
+---@param comment string
+function mt:setComment(comment)
+ self._comment = comment
+end
+
+---@return string
+function mt:getComment()
+ return self._comment
+end
+
local function create(name, source, value, tags)
if not value then
error('Local must has a value')
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index 98b79fe9..3a884404 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -850,6 +850,7 @@ end
function mt:doLocal(action)
local emmy = self:getEmmy()
+ local comment = self:getEmmyComment()
self:instantSource(action)
local vars = action[1]
local exps = action[2]
@@ -876,7 +877,7 @@ function mt:doLocal(action)
if values then
value = values[i]
end
- self:createLocal(key[1], key, value, tags, emmy)
+ self:createLocal(key[1], key, value, tags, emmy, comment)
end)
end
@@ -1097,6 +1098,7 @@ function mt:createFunction(source)
local value = self:createValue('function', source)
local func = functionMgr.create(source)
func:setEmmy(self:getEmmyParams(), self:getEmmyReturns())
+ func:setComment(self:getEmmyComment())
value:setFunction(func)
value:setType('function', 1.0)
if source:getUri() == self.uri then
@@ -1187,7 +1189,7 @@ function mt:bindLabel(source, label, action)
end
end
-function mt:createLocal(key, source, value, tags, emmy)
+function mt:createLocal(key, source, value, tags, emmy, comment)
local loc = self:bindLocal(source)
if not value then
value = self:createValue('nil', source)
@@ -1201,6 +1203,7 @@ function mt:createLocal(key, source, value, tags, emmy)
loc = localMgr.create(key, source, value, tags)
loc:setEmmy(emmy)
+ loc:setComment(comment)
self:saveLocal(key, loc)
self:bindLocal(source, loc, 'local')
loc:close(self:getCurrentFunction():getSource().finish)