summaryrefslogtreecommitdiff
path: root/script/provider/provider.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-01-30 19:09:01 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-01-30 19:09:01 +0800
commit219db07808f65eecf81fd0ad8408bb2a8615272c (patch)
treef3cdab6c2f4cb1c67d4a6a7a85cc7cf653db2440 /script/provider/provider.lua
parenta0c905ba6de413df0fc754d638db6431a203b330 (diff)
downloadlua-language-server-219db07808f65eecf81fd0ad8408bb2a8615272c.zip
supports type hint
Diffstat (limited to 'script/provider/provider.lua')
-rw-r--r--script/provider/provider.lua46
1 files changed, 27 insertions, 19 deletions
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index c9c0cb44..6c042f7a 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -727,24 +727,32 @@ proto.on('window/workDoneProgress/cancel', function (params)
progress.cancel(params.token)
end)
-proto.on('didChangeVisibleRanges', function (params)
- log.debug(util.dump(params))
- proto.notify('$/decorations/create', {
- uri = params.uri,
- edits = {
- {
- newText = ': 你猜猜我是啥类型',
- range = {
- start = {
- line = params.ranges[1]['end'].line - 2,
- character = params.ranges[1]['end'].character - 5,
- },
- ['end'] = {
- line = params.ranges[1]['end'].line - 2,
- character = params.ranges[1]['end'].character - 5,
- },
- },
- }
- }
+proto.on('$/didChangeVisibleRanges', function (params)
+ local typeHint = require 'core.type-hint'
+ local edits = {}
+ local uri = params.uri
+ while not files.exists(uri) do
+ await.sleep(0.1)
+ end
+
+ -- compute type-hint
+ for _, range in ipairs(params.ranges) do
+ local start, finish = files.unrange(uri, range)
+ local piece = typeHint(uri, start, finish)
+ if piece then
+ for _, edit in ipairs(piece) do
+ edits[#edits+1] = {
+ newText = edit.newText,
+ range = files.range(uri, edit.start, edit.finish)
+ }
+ end
+ end
+ end
+ if #edits == 0 then
+ return
+ end
+ proto.notify('$/typeHint', {
+ uri = uri,
+ edits = edits,
})
end)