diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/locale/en-US/script.lni | 2 | ||||
-rw-r--r-- | server/locale/zh-CN/script.lni | 2 | ||||
-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 |
6 files changed, 68 insertions, 7 deletions
diff --git a/server/locale/en-US/script.lni b/server/locale/en-US/script.lni index 5b7c76f7..ba95660d 100644 --- a/server/locale/en-US/script.lni +++ b/server/locale/en-US/script.lni @@ -10,3 +10,5 @@ DIAG_OVER_MAX_ARGS = 'The function takes only {:d} parameters, but you passed MWS_NOT_SUPPORT = '{} dose not support multi workspace for now, I may need to restart to support the new workspace ...' MWS_RESTART = 'Restart' +MWS_NOT_COMPLETE = 'Workspace is not complete yet. You may try again later...' +MWS_COMPLETE = 'Workspace is complete now. You may try again...' diff --git a/server/locale/zh-CN/script.lni b/server/locale/zh-CN/script.lni index 735f429b..233c7afe 100644 --- a/server/locale/zh-CN/script.lni +++ b/server/locale/zh-CN/script.lni @@ -10,3 +10,5 @@ DIAG_OVER_MAX_ARGS = '函数只接收 {:d} 个参数,但你传了 {:d} 个 MWS_NOT_SUPPORT = '{} 目前还不支持多工作目录,我可能需要重启才能支持新的工作目录...' MWS_RESTART = '重启' +MWS_NOT_COMPLETE = '工作目录还没有准备好,你可以稍后再试一下...' +MWS_COMPLETE = '工作目录准备好了,你可以再试一下了...' 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() |