diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-09-10 20:52:14 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-09-10 20:52:14 +0800 |
commit | a58446a72ada7f74d816f6897be24971321b1e5d (patch) | |
tree | 898fa4c7d28f8d13ef602f72c8ea3bd8ce90c09a /server/src | |
parent | eed0937505957237b4116afaceeb3cb4c02b4c11 (diff) | |
download | lua-language-server-a58446a72ada7f74d816f6897be24971321b1e5d.zip |
#84 completion.enable
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/capability/completion.lua | 53 | ||||
-rw-r--r-- | server/src/capability/init.lua | 3 | ||||
-rw-r--r-- | server/src/config.lua | 1 | ||||
-rw-r--r-- | server/src/log.lua | 2 | ||||
-rw-r--r-- | server/src/method/initialize.lua | 4 | ||||
-rw-r--r-- | server/src/service.lua | 6 |
6 files changed, 64 insertions, 5 deletions
diff --git a/server/src/capability/completion.lua b/server/src/capability/completion.lua new file mode 100644 index 00000000..28a6036c --- /dev/null +++ b/server/src/capability/completion.lua @@ -0,0 +1,53 @@ +local rpc = require 'rpc' + +local isEnable = false + +local function allWords() + local str = [[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:('"[,#*@| ]] + local list = {} + for c in str:gmatch '.' do + list[#list+1] = c + end + return list +end + +local function enable() + if isEnable then + return + end + isEnable = true + log.debug('Enable completion.') + rpc:request('client/registerCapability', { + registrations = { + { + id = 'completion', + method = 'textDocument/completion', + registerOptions = { + resolveProvider = false, + triggerCharacters = allWords(), + }, + }, + } + }) +end + +local function disable() + if not isEnable then + return + end + isEnable = false + log.debug('Disable completion.') + rpc:request('client/unregisterCapability', { + unregisterations = { + { + id = 'completion', + method = 'textDocument/completion', + }, + } + }) +end + +return { + enable = enable, + disable = disable, +} diff --git a/server/src/capability/init.lua b/server/src/capability/init.lua new file mode 100644 index 00000000..09eb6a09 --- /dev/null +++ b/server/src/capability/init.lua @@ -0,0 +1,3 @@ +return { + completion = require 'capability.completion', +} diff --git a/server/src/config.lua b/server/src/config.lua index 24e0d53e..a71cb191 100644 --- a/server/src/config.lua +++ b/server/src/config.lua @@ -120,6 +120,7 @@ local ConfigTemplate = { )} }, completion = { + enable = {true, Boolean}, callSnippet = {true, Boolean}, }, } diff --git a/server/src/log.lua b/server/src/log.lua index 7ebb55cf..d8e782c0 100644 --- a/server/src/log.lua +++ b/server/src/log.lua @@ -8,7 +8,7 @@ log.size = 0 log.max_size = 100 * 1024 * 1024 local function trim_src(src) - src = src:sub(log.prefix_len + 1, -5) + src = src:sub(log.prefix_len + 3, -5) src = src:gsub('^[/\\]+', '') src = src:gsub('[\\/]+', '.') return src diff --git a/server/src/method/initialize.lua b/server/src/method/initialize.lua index 84388fef..8bc47fdd 100644 --- a/server/src/method/initialize.lua +++ b/server/src/method/initialize.lua @@ -28,10 +28,6 @@ return function (lsp) -- 文本改变时完全通知 TODO 支持差量更新(2) change = 1, }, - completionProvider = { - resolveProvider = false, - triggerCharacters = allWords(), - }, workspace = { workspaceFolders = { supported = true, diff --git a/server/src/service.lua b/server/src/service.lua index c763d73a..fd814ff3 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -19,6 +19,7 @@ local config = require 'config' local task = require 'task' local files = require 'files' local uric = require 'uri' +local capability = require 'capability' local ErrorCodes = { -- Defined by JSON RPC @@ -757,6 +758,11 @@ function mt:onUpdateConfig(updated, other) log.debug('reDiagnostic') self:reDiagnostic() end + if newConfig.completion.enable then + capability.completion.enable() + else + capability.completion.disable() + end if not table.equal(oldConfig.workspace, newConfig.workspace) or not table.equal(oldOther.associations, newOther.associations) or not table.equal(oldOther.exclude, newOther.exclude) |