summaryrefslogtreecommitdiff
path: root/script/capability/completion.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/capability/completion.lua')
-rw-r--r--script/capability/completion.lua53
1 files changed, 53 insertions, 0 deletions
diff --git a/script/capability/completion.lua b/script/capability/completion.lua
new file mode 100644
index 00000000..28a6036c
--- /dev/null
+++ b/script/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,
+}