diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-12-09 21:01:09 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-12-09 21:01:09 +0800 |
commit | 2b3492cea6a1c3358119a3a630763ab3728a2c6f (patch) | |
tree | 8d35268153db208820c7f2fb66144e6de2a7dda5 | |
parent | f6d436e782fbb19851a5b1d3b6c613a5447ca7b2 (diff) | |
download | lua-language-server-2b3492cea6a1c3358119a3a630763ab3728a2c6f.zip |
provider 接入 completion
-rw-r--r-- | script-beta/provider/init.lua | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/script-beta/provider/init.lua b/script-beta/provider/init.lua index 92e5d251..7e9569a0 100644 --- a/script-beta/provider/init.lua +++ b/script-beta/provider/init.lua @@ -54,7 +54,7 @@ local function updateConfig() end if newConfig.completion.enable then - --completion.enable() + completion.enable() else completion.disable() end @@ -295,5 +295,26 @@ end) proto.on('textDocument/completion', function (params) --log.info(util.dump(params)) - return nil + local core = require 'core.completion' + local uri = params.textDocument.uri + if not files.exists(uri) then + return nil + end + local lines = files.getLines(uri) + local text = files.getText(uri) + local offset = define.offset(lines, text, params.position) + local result = core(uri, offset) + if not result then + return nil + end + + local items = {} + for i, res in ipairs(result) do + items[i] = { + label = res.label, + kind = res.kind, + } + end + + return items end) |