From 219db07808f65eecf81fd0ad8408bb2a8615272c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 30 Jan 2021 19:09:01 +0800 Subject: supports type hint --- script/provider/provider.lua | 46 ++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'script/provider/provider.lua') 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) -- cgit v1.2.3