summaryrefslogtreecommitdiff
path: root/script-beta/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-09-29 20:12:12 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-09-29 20:12:12 +0800
commit3bcd1fc6672df2e8a36002caa206f67eb0e5781f (patch)
tree1716d1db0e819c36482326040ed47444c0a46f4a /script-beta/core
parent49a08a52831faa22fd45cb819a96ece41e538673 (diff)
downloadlua-language-server-3bcd1fc6672df2e8a36002caa206f67eb0e5781f.zip
自动完成的 displayContext
Diffstat (limited to 'script-beta/core')
-rw-r--r--script-beta/core/completion.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index 2e1af2aa..82f0f3d2 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -186,11 +186,39 @@ local function buildDetail(source)
end
end
+local function getSnip(source)
+ local context = config.config.completion.displayContext
+ if context <= 0 then
+ return nil
+ end
+ local defs = vm.getRefs(source, 'simple')
+ for _, def in ipairs(defs) do
+ if def ~= source and def.type == 'function' then
+ local uri = guide.getUri(def)
+ local text = files.getText(uri)
+ local lines = files.getLines(uri)
+ if not text then
+ return nil
+ end
+ local row = guide.positionOf(lines, def.start)
+ local firstRow = lines[row]
+ local lastRow = lines[math.min(row + context - 1, #lines)]
+ local snip = text:sub(firstRow.start, lastRow.finish)
+ return snip
+ end
+ end
+end
+
local function buildDesc(source)
local hover = getHover.get(source)
local md = markdown()
md:add('lua', hover.label)
md:add('md', hover.description)
+ local snip = getSnip(source)
+ if snip then
+ md:add('md', '-------------')
+ md:add('lua', snip)
+ end
return md:string()
end