summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-12 20:19:10 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-12 20:19:10 +0800
commitecffa11c6f5f296856428743f5763abde16c4b85 (patch)
treea68595833becc38867b385545afb26df117135f8 /script
parentbb73d6199cd3613d819a99e393bf41823f0dd67c (diff)
downloadlua-language-server-ecffa11c6f5f296856428743f5763abde16c4b85.zip
resolve #1124 supports path in link
Diffstat (limited to 'script')
-rw-r--r--script/core/hover/description.lua43
1 files changed, 29 insertions, 14 deletions
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index 4726718d..bbf35743 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -6,6 +6,7 @@ local lang = require 'language'
local util = require 'utility'
local guide = require 'parser.guide'
local rpath = require 'workspace.require-path'
+local furi = require 'file-uri'
local function collectRequire(mode, literal, uri)
local result, searchers
@@ -97,6 +98,30 @@ local function getBindComment(source)
return table.concat(lines, '\n')
end
+---@param comment string
+---@param suri uri
+---@return string?
+local function normalizeComment(comment, suri)
+ if comment:sub(1, 1) == '-' then
+ comment = comment:sub(2)
+ end
+ if comment:sub(1, 1) == '@' then
+ return nil
+ end
+ comment = comment:gsub('(%[.-%]%()(.-)(%))', function (left, path, right)
+ if path:match '^file:/' then
+ return
+ end
+ local absPath = ws.getAbsolutePath(suri:gsub('/[^/]+$', ''), path)
+ if not absPath then
+ return
+ end
+ local uri = furi.encode(absPath)
+ return left .. uri .. right
+ end)
+ return comment
+end
+
local function lookUpDocComments(source, docGroup)
if source.type == 'setlocal'
or source.type == 'getlocal' then
@@ -105,16 +130,11 @@ local function lookUpDocComments(source, docGroup)
if source.parent.type == 'funcargs' then
return
end
+ local uri = guide.getUri(source)
local lines = {}
for _, doc in ipairs(docGroup) do
if doc.type == 'doc.comment' then
- local comment = doc.comment.text
- if comment:sub(1, 1) == '-' then
- comment = comment:sub(2)
- end
- if comment:sub(1, 1) == '@' then
- goto CONTINUE
- end
+ local comment = normalizeComment(doc.comment.text, uri)
lines[#lines+1] = comment
elseif doc.type == 'doc.type' then
if doc.comment then
@@ -273,16 +293,11 @@ local function getFunctionComment(source)
end
end
+ local uri = guide.getUri(source)
local md = markdown()
for _, doc in ipairs(docGroup) do
if doc.type == 'doc.comment' then
- local comment = doc.comment.text
- if comment:sub(1, 1) == '-' then
- comment = comment:sub(2)
- end
- if comment:sub(1, 1) == '@' then
- goto CONTINUE
- end
+ local comment = normalizeComment(doc.comment.text, uri)
md:add('md', comment)
elseif doc.type == 'doc.param' then
if doc.comment then