diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/method/textDocument/definition.lua | 6 | ||||
-rw-r--r-- | server/src/method/textDocument/implementation.lua | 6 | ||||
-rw-r--r-- | server/src/method/textDocument/references.lua | 81 | ||||
-rw-r--r-- | server/src/workspace.lua | 4 |
4 files changed, 54 insertions, 43 deletions
diff --git a/server/src/method/textDocument/definition.lua b/server/src/method/textDocument/definition.lua index d9c32b36..c2880f7e 100644 --- a/server/src/method/textDocument/definition.lua +++ b/server/src/method/textDocument/definition.lua @@ -75,13 +75,15 @@ return function (lsp, params) end return function (response) LastTask = ac.loop(0.1, function () + local result = findResult(lsp, params) + if result then + response(result) + end if lsp:isWaitingCompile() then return end LastTask:remove() LastTask = nil - local result = findResult(lsp, params) - response(result) end) end end diff --git a/server/src/method/textDocument/implementation.lua b/server/src/method/textDocument/implementation.lua index a4d45169..64bb4fe4 100644 --- a/server/src/method/textDocument/implementation.lua +++ b/server/src/method/textDocument/implementation.lua @@ -74,13 +74,15 @@ return function (lsp, params) end return function (response) LastTask = ac.loop(0.1, function () + local result = findResult(lsp, params) + if result then + response(result) + end if lsp:isWaitingCompile() then return end LastTask:remove() LastTask = nil - local result = findResult(lsp, params) - response(result) end) end end diff --git a/server/src/method/textDocument/references.lua b/server/src/method/textDocument/references.lua index f21625c8..7213e590 100644 --- a/server/src/method/textDocument/references.lua +++ b/server/src/method/textDocument/references.lua @@ -1,6 +1,45 @@ local core = require 'core' local LastTask +local function findReferences(lsp, uri, position, declarat) + local vm = lsp:getVM(uri) + + local positions = core.references(vm, position, declarat) + if not positions then + return nil + end + + local locations = {} + for i, position in ipairs(positions) do + local start, finish, valueUri = position[1], position[2], (position[3] or uri) + local _, valueLines = lsp:getVM(valueUri) + if valueLines then + local start_row, start_col = valueLines:rowcol(start) + local finish_row, finish_col = valueLines:rowcol(finish) + locations[i] = { + uri = valueUri, + range = { + start = { + line = start_row - 1, + character = start_col - 1, + }, + ['end'] = { + line = finish_row - 1, + -- 这里不用-1,因为前端期待的是匹配完成后的位置 + character = finish_col, + }, + } + } + end + end + + if #locations == 0 then + return nil + end + + return locations +end + return function (lsp, params) local uri = params.textDocument.uri local declarat = params.context.includeDeclaration @@ -19,49 +58,15 @@ return function (lsp, params) return function (response) LastTask = ac.loop(0.1, function (t) + local positions = findReferences(lsp, uri, position, declarat) + if positions then + response(positions) + end if lsp:isWaitingCompile() then return end t:remove() LastTask = nil - vm, lines = lsp:getVM(uri) - - local positions = core.references(vm, position, declarat) - if not positions then - response(nil) - return - end - - local locations = {} - for i, position in ipairs(positions) do - local start, finish, valueUri = position[1], position[2], (position[3] or uri) - local _, valueLines = lsp:getVM(valueUri) - if valueLines then - local start_row, start_col = valueLines:rowcol(start) - local finish_row, finish_col = valueLines:rowcol(finish) - locations[i] = { - uri = valueUri, - range = { - start = { - line = start_row - 1, - character = start_col - 1, - }, - ['end'] = { - line = finish_row - 1, - -- 这里不用-1,因为前端期待的是匹配完成后的位置 - character = finish_col, - }, - } - } - end - end - - if #locations == 0 then - response(nil) - return - end - - response(locations) end) end end diff --git a/server/src/workspace.lua b/server/src/workspace.lua index d03fc217..4ab8b6d2 100644 --- a/server/src/workspace.lua +++ b/server/src/workspace.lua @@ -104,12 +104,13 @@ function mt:scanFiles() log.info('忽略文件:\r\n' .. table.concat(ignored, '\r\n')) log.info('开始扫描文件任务') local compiled = {} + local count = 0 self._scanRequest = async.run('scanfiles', { root = self.root:string(), ignored = ignored, }, function (mode, ...) if mode == 'ok' then - log.info('扫描文件任务完成') + log.info('扫描文件任务完成,共', count, '个文件。') self._complete = true self._scanRequest = nil self:reset() @@ -123,6 +124,7 @@ function mt:scanFiles() local uri = self:uriEncode(path) self.files[name] = uri self.lsp:readText(uri, path, file.buf, compiled) + count = count + 1 elseif mode == 'stop' then log.info('扫描文件任务中断') return false |