diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-26 13:52:59 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-26 13:52:59 +0800 |
commit | ca498542d4424322e2172425ab02a8986deb477b (patch) | |
tree | 093d0af88667c1fac500b0940473fa7b768f724c /server/src | |
parent | 3b76eaf9620585c8f4b3304de030767e61ceb42c (diff) | |
download | lua-language-server-ca498542d4424322e2172425ab02a8986deb477b.zip |
跨文件的一个提示
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/matcher/implementation.lua | 5 | ||||
-rw-r--r-- | server/src/method/textDocument/definition.lua | 16 | ||||
-rw-r--r-- | server/src/method/textDocument/implementation.lua | 26 | ||||
-rw-r--r-- | server/src/service.lua | 24 |
4 files changed, 64 insertions, 7 deletions
diff --git a/server/src/matcher/implementation.lua b/server/src/matcher/implementation.lua index 03b163e3..6f90484e 100644 --- a/server/src/matcher/implementation.lua +++ b/server/src/matcher/implementation.lua @@ -1,5 +1,3 @@ -local findResult = require 'matcher.find_result' - local function parseResultAcrossUri(positions, vm, result) -- 跨越文件时,遍历的是值的绑定信息 for _, info in ipairs(result.value) do @@ -75,8 +73,7 @@ local function parseResult(vm, result) return positions end -return function (vm, pos) - local result = findResult(vm, pos) +return function (vm, result) if not result then return nil end diff --git a/server/src/method/textDocument/definition.lua b/server/src/method/textDocument/definition.lua index 75df54da..1f21d67d 100644 --- a/server/src/method/textDocument/definition.lua +++ b/server/src/method/textDocument/definition.lua @@ -1,5 +1,18 @@ local matcher = require 'matcher' +local function checkWorkSpaceComplete(lsp, result) + if result.value then + if not result.value.isRequire then + return + end + else + if not result.isRequire then + return + end + end + lsp:checkWorkSpaceComplete() +end + return function (lsp, params) local uri = params.textDocument.uri local vm, lines = lsp:loadVM(uri) @@ -12,6 +25,9 @@ return function (lsp, params) if not result then return nil end + + checkWorkSpaceComplete(lsp, result) + local positions = matcher.definition(vm, result) if not positions then return nil diff --git a/server/src/method/textDocument/implementation.lua b/server/src/method/textDocument/implementation.lua index c42acf05..c92a8c56 100644 --- a/server/src/method/textDocument/implementation.lua +++ b/server/src/method/textDocument/implementation.lua @@ -1,16 +1,36 @@ local matcher = require 'matcher' +local function checkWorkSpaceComplete(lsp, result) + if result.value then + if not result.value.isRequire then + return + end + else + if not result.isRequire then + return + end + end + lsp:checkWorkSpaceComplete() +end + return function (lsp, params) local uri = params.textDocument.uri local vm, lines = lsp:loadVM(uri) if not vm then - return {} + return nil end -- lua是从1开始的,因此都要+1 local position = lines:position(params.position.line + 1, params.position.character + 1) - local positions = matcher.implementation(vm, position) + local result = matcher.findResult(vm, position) + if not result then + return nil + end + + checkWorkSpaceComplete(lsp, result) + + local positions = matcher.implementation(vm, result) if not positions then - return {} + return nil end local locations = {} diff --git a/server/src/service.lua b/server/src/service.lua index ac986bf7..aed5bb9b 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -5,6 +5,7 @@ local async = require 'async' local rpc = require 'rpc' local parser = require 'parser' local matcher = require 'matcher' +local lang = require 'language' thread.newchannel 'proto' @@ -236,6 +237,14 @@ function mt:reCompile() for uri in pairs(self._opening) do self:needCompile(uri, compiled) end + + if self._needShowComplete then + self._needShowComplete = nil + rpc:notify('window/showMessage', { + type = 3, + message = lang.script.MWS_COMPLETE, + }) + end end function mt:loadVM(uri) @@ -335,6 +344,21 @@ function mt:removeText(uri) self._file[uri] = nil end +function mt:checkWorkSpaceComplete() + if self._hasCheckedWorkSpaceComplete then + return + end + self._hasCheckedWorkSpaceComplete = true + if self.workspace:isComplete() then + return + end + self._needShowComplete = true + rpc:notify('window/showMessage', { + type = 3, + message = lang.script.MWS_NOT_COMPLETE, + }) +end + function mt:onTick() while true do local ok, proto = self._proto:pop() |