summaryrefslogtreecommitdiff
path: root/script/method
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-06-23 16:12:29 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-06-23 16:12:29 +0800
commita782eb79202e29326b96fab7cd7591ba881a7778 (patch)
tree01e2e9d8369b154067b0671b533bf84b5302619f /script/method
parent3c4203ac592c00fa8f3072faf77e1966149a7860 (diff)
downloadlua-language-server-a782eb79202e29326b96fab7cd7591ba881a7778.zip
自动完成显示代码块参考
Diffstat (limited to 'script/method')
-rw-r--r--script/method/completionItem/resolve.lua27
-rw-r--r--script/method/init.lua1
2 files changed, 28 insertions, 0 deletions
diff --git a/script/method/completionItem/resolve.lua b/script/method/completionItem/resolve.lua
new file mode 100644
index 00000000..9909166a
--- /dev/null
+++ b/script/method/completionItem/resolve.lua
@@ -0,0 +1,27 @@
+return function (lsp, item)
+ if not item.data then
+ return item
+ end
+ local offset = item.data.offset
+ local uri = item.data.uri
+ local _, lines, text = lsp:getVM(uri)
+ if not lines then
+ return item
+ end
+ local row = lines:rowcol(offset)
+ local firstRow = lines[row]
+ local lastRow = lines[math.min(row + 5, #lines)]
+ local snip = text:sub(firstRow.start, lastRow.finish)
+ local document = ([[
+%s
+------------
+```lua
+%s
+```
+]]):format(item.documentation and item.documentation.value or '', snip)
+ item.documentation = {
+ kind = 'markdown',
+ value = document,
+ }
+ return item
+end
diff --git a/script/method/init.lua b/script/method/init.lua
index dd662a2d..cd9010bb 100644
--- a/script/method/init.lua
+++ b/script/method/init.lua
@@ -8,6 +8,7 @@ init 'exit'
init 'initialize'
init 'initialized'
init 'shutdown'
+init 'completionItem/resolve'
init 'textDocument/codeAction'
init 'textDocument/completion'
init 'textDocument/definition'