summaryrefslogtreecommitdiff
path: root/server-beta/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-08 14:05:55 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-08 14:05:55 +0800
commit0a2df61286035af2bd506605547f6a5d5024c691 (patch)
tree0d77de700d936403aec32c0eea37237448f04b3a /server-beta/src
parentf53b68d739ab7aad9c6aae2b902f34fbb8fc97ea (diff)
downloadlua-language-server-0a2df61286035af2bd506605547f6a5d5024c691.zip
修正诊断策略
Diffstat (limited to 'server-beta/src')
-rw-r--r--server-beta/src/files.lua6
-rw-r--r--server-beta/src/proto/init.lua1
-rw-r--r--server-beta/src/provider/capability.lua (renamed from server-beta/src/proto/capability.lua)0
-rw-r--r--server-beta/src/provider/completion.lua53
-rw-r--r--server-beta/src/provider/init.lua (renamed from server-beta/src/proto/provider.lua)14
-rw-r--r--server-beta/src/service/diagnostic.lua11
-rw-r--r--server-beta/src/service/service.lua2
7 files changed, 80 insertions, 7 deletions
diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua
index 47078661..c0aa5379 100644
--- a/server-beta/src/files.lua
+++ b/server-beta/src/files.lua
@@ -113,11 +113,15 @@ function m.remove(uri)
if platform.OS == 'Windows' then
uri = uri:lower()
end
+ local file = m.fileMap[uri]
+ if not file then
+ return
+ end
m.fileMap[uri] = nil
searcher.refreshCache()
local diagnostic = require 'service.diagnostic'
- diagnostic.refresh()
+ diagnostic.refresh(file.uri)
end
--- 移除所有文件
diff --git a/server-beta/src/proto/init.lua b/server-beta/src/proto/init.lua
index e2fa1bb5..33e637f6 100644
--- a/server-beta/src/proto/init.lua
+++ b/server-beta/src/proto/init.lua
@@ -1,4 +1,3 @@
local proto = require 'proto.proto'
-require 'proto.provider'
return proto
diff --git a/server-beta/src/proto/capability.lua b/server-beta/src/provider/capability.lua
index 71d3bca1..71d3bca1 100644
--- a/server-beta/src/proto/capability.lua
+++ b/server-beta/src/provider/capability.lua
diff --git a/server-beta/src/provider/completion.lua b/server-beta/src/provider/completion.lua
new file mode 100644
index 00000000..d2df44d2
--- /dev/null
+++ b/server-beta/src/provider/completion.lua
@@ -0,0 +1,53 @@
+local proto = require 'proto'
+
+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.')
+ proto.awaitRequest('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.')
+ proto.awaitRequest('client/unregisterCapability', {
+ unregisterations = {
+ {
+ id = 'completion',
+ method = 'textDocument/completion',
+ },
+ }
+ })
+end
+
+return {
+ enable = enable,
+ disable = disable,
+}
diff --git a/server-beta/src/proto/provider.lua b/server-beta/src/provider/init.lua
index 7527ea16..b510c580 100644
--- a/server-beta/src/proto/provider.lua
+++ b/server-beta/src/provider/init.lua
@@ -1,5 +1,6 @@
local util = require 'utility'
-local cap = require 'proto.capability'
+local cap = require 'provider.capability'
+local completion= require 'provider.completion'
local await = require 'await'
local files = require 'files'
local proto = require 'proto.proto'
@@ -51,6 +52,12 @@ local function updateConfig()
or not util.equal(oldOther.exclude, newOther.exclude)
then
end
+
+ if newConfig.completion.enable then
+ completion.enable()
+ else
+ completion.disable()
+ end
end
proto.on('initialize', function (params)
@@ -172,3 +179,8 @@ proto.on('textDocument/definition', function (params)
end
return response
end)
+
+proto.on('textDocument/completion', function (params)
+ log.info(util.dump(params))
+ return nil
+end)
diff --git a/server-beta/src/service/diagnostic.lua b/server-beta/src/service/diagnostic.lua
index b7d6be02..6e5d77c8 100644
--- a/server-beta/src/service/diagnostic.lua
+++ b/server-beta/src/service/diagnostic.lua
@@ -86,9 +86,13 @@ local function buildDiagnostic(uri, diag)
}
end
-function m.doDiagnostic(uri)
+function m.doDiagnostic(uri, syntaxOnly)
local ast = files.getAst(uri)
if not ast then
+ proto.notify('textDocument/publishDiagnostics', {
+ uri = uri,
+ diagnostics = {},
+ })
return
end
@@ -98,7 +102,7 @@ function m.doDiagnostic(uri)
diagnostics[#diagnostics+1] = buildSyntaxError(uri, err)
end
- if m._start then
+ if not syntaxOnly and m._start then
local diags = core(uri)
for _, diag in ipairs(diags) do
diagnostics[#diagnostics+1] = buildDiagnostic(uri, diag)
@@ -109,14 +113,13 @@ function m.doDiagnostic(uri)
uri = uri,
diagnostics = diagnostics,
})
-
end
function m.refresh(uri)
m.version = m.version + 1
local myVersion = m.version
if uri then
- m.doDiagnostic(files.getOriginUri(uri))
+ m.doDiagnostic(uri, true)
end
if not m._start then
return
diff --git a/server-beta/src/service/service.lua b/server-beta/src/service/service.lua
index 6c6d3c90..6ff82897 100644
--- a/server-beta/src/service/service.lua
+++ b/server-beta/src/service/service.lua
@@ -85,6 +85,8 @@ function m.start()
pub.listen()
m.report()
+ require 'provider'
+
m.startTimer()
end