summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-09-10 20:52:14 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-09-10 20:52:14 +0800
commita58446a72ada7f74d816f6897be24971321b1e5d (patch)
tree898fa4c7d28f8d13ef602f72c8ea3bd8ce90c09a
parenteed0937505957237b4116afaceeb3cb4c02b4c11 (diff)
downloadlua-language-server-a58446a72ada7f74d816f6897be24971321b1e5d.zip
#84 completion.enable
-rw-r--r--package.json6
-rw-r--r--package.nls.json1
-rw-r--r--package.nls.zh-cn.json1
-rw-r--r--server/build_package.lua8
-rw-r--r--server/src/capability/completion.lua53
-rw-r--r--server/src/capability/init.lua3
-rw-r--r--server/src/config.lua1
-rw-r--r--server/src/log.lua2
-rw-r--r--server/src/method/initialize.lua4
-rw-r--r--server/src/service.lua6
10 files changed, 80 insertions, 5 deletions
diff --git a/package.json b/package.json
index 08d9da28..b8d17a05 100644
--- a/package.json
+++ b/package.json
@@ -22,6 +22,12 @@
"scope": "resource",
"type": "boolean"
},
+ "Lua.completion.enable": {
+ "default": true,
+ "markdownDescription": "%config.completion.enable%",
+ "scope": "resource",
+ "type": "boolean"
+ },
"Lua.diagnostics.disable": {
"items": {
"type": "string"
diff --git a/package.nls.json b/package.nls.json
index cc782acd..6ddc588d 100644
--- a/package.nls.json
+++ b/package.nls.json
@@ -1,5 +1,6 @@
{
"config.completion.callSnippet": "Show function call snippets.",
+ "config.completion.enable": "Enable completion.",
"config.diagnostics.disable": "Disabled diagnostic (Use code in hover brackets).\n```json\n\"Lua.diagnostics.disable\" : [\n \"unused-local\",\n \"lowercase-global\"\n]\n```\n",
"config.diagnostics.enable": "Enable diagnostics.",
"config.diagnostics.globals": "Defined global variables.\n```json\n\"Lua.diagnostics.globals\" : [\n \"GLOBAL1\",\n \"GLOBAL2\"\n]\n```\n",
diff --git a/package.nls.zh-cn.json b/package.nls.zh-cn.json
index da16fd8b..153a3933 100644
--- a/package.nls.zh-cn.json
+++ b/package.nls.zh-cn.json
@@ -1,5 +1,6 @@
{
"config.completion.callSnippet": "显示函数调用片段。",
+ "config.completion.enable": "启用自动完成。",
"config.diagnostics.disable": "禁用的诊断(使用浮框括号内的代码)。\n```json\n\"Lua.diagnostics.disable\" : [\n \"unused-local\",\n \"lowercase-global\"\n]\n```\n",
"config.diagnostics.enable": "启用诊断。",
"config.diagnostics.globals": "已定义的全局变量。\n```json\n\"Lua.diagnostics.globals\" : [\n \"GLOBAL1\",\n \"GLOBAL2\"\n]\n```\n",
diff --git a/server/build_package.lua b/server/build_package.lua
index fc351868..6235601b 100644
--- a/server/build_package.lua
+++ b/server/build_package.lua
@@ -130,6 +130,12 @@ local package = {
type = 'object',
markdownDescription = "%config.workspace.library%"
},
+ ["Lua.completion.enable"] = {
+ scope = "resource",
+ type = "boolean",
+ default = true,
+ markdownDescription = "%config.completion.enable%"
+ },
["Lua.completion.callSnippet"] = {
scope = "resource",
type = "boolean",
@@ -234,6 +240,7 @@ Load external library.
This feature can load external Lua files, which can be used for definition, automatic completion and other functions. Note that the language server does not monitor changes in external files and needs to restart if the external files are modified.
The following example shows loaded files in `C:/lua` and `../lib` ,exclude `../lib/temp`.
]] .. example.library,
+ ['config.completion.enable'] = 'Enable completion.',
['config.completion.callSnippet'] = 'Show function call snippets.',
})
@@ -254,5 +261,6 @@ io.save(ROOT:parent_path() / 'package.nls.zh-cn.json', json.encode {
该功能可以加载外部的Lua文件,用于函数定义、自动完成等功能。注意,语言服务不会监视外部文件的变化,如果修改了外部文件需要重启。
下面这个例子表示加载`C:/lua`与`../lib`中的所有文件,但不加载`../lib/temp`中的文件。
]] .. example.library,
+ ['config.completion.enable'] = '启用自动完成。',
['config.completion.callSnippet'] = '显示函数调用片段。',
})
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)