summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/parser/luadoc.lua18
-rw-r--r--test/crossfile/hover.lua15
3 files changed, 29 insertions, 5 deletions
diff --git a/changelog.md b/changelog.md
index 3ce84910..4f7ac9c2 100644
--- a/changelog.md
+++ b/changelog.md
@@ -3,6 +3,7 @@
## 1.21.0
* `NEW` setting: `completion.showParams`
* `NEW` `LuaDoc`: supports multiline comments
+* `NEW` `LuaDoc`: tail comments support lua string
## 1.20.5
`2021-4-30`
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 74e53718..3ab9f6a1 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -2,6 +2,7 @@ local m = require 'lpeglabel'
local re = require 'parser.relabel'
local lines = require 'parser.lines'
local guide = require 'core.guide'
+local grammar = require 'parser.grammar'
local TokenTypes, TokenStarts, TokenFinishs, TokenContents
local Ci, Offset, pushError, Ct, NextComment, Lines
@@ -999,16 +1000,23 @@ local function convertTokens()
end
local function trimTailComment(text)
+ local comment = text
if text:sub(1, 1) == '@' then
- return text:sub(2)
+ comment = text:sub(2)
end
if text:sub(1, 1) == '#' then
- return text:sub(2)
+ comment = text:sub(2)
end
if text:sub(1, 2) == '--' then
- return text:sub(3)
+ comment = text:sub(3)
end
- return text
+ if comment:find '^%s*[\'"[]' then
+ local result = grammar(nil, comment:gsub('^%s+', ''), 'string')
+ if result then
+ comment = result[1][1]
+ end
+ end
+ return comment
end
local function buildLuaDoc(comment)
@@ -1185,7 +1193,7 @@ local function bindDoc(sources, lns, binded)
end
bindGeneric(binded)
local row = guide.positionOf(lns, lastDoc.finish)
- local cstart, cfinish = guide.lineRange(lns, row)
+ local cstart, cfinish = guide.lineRange(lns, row)
local nstart, nfinish = guide.lineRange(lns, row + 1)
bindDocsBetween(sources, binded, bindSources, cstart, cfinish)
if #bindSources == 0 then
diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua
index dacf1ab2..bf56b39a 100644
--- a/test/crossfile/hover.lua
+++ b/test/crossfile/hover.lua
@@ -746,3 +746,18 @@ hover = {
name = 'food',
description = "I'm a multiline comment\n"
}}
+
+TEST {{ path = 'a.lua', content = '', }, {
+ path = 'b.lua',
+ content = [[
+---@return string # 'this is a tab `\t`'
+local function <?f?>() end
+]]
+},
+hover = {
+ label = [[
+function f()
+ -> string]],
+ name = 'food',
+ description = "@*return* — this is a tab `\t`"
+}}