diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-12 11:04:59 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-12 11:04:59 +0800 |
commit | 9235116d2a54052f9be43e9291d70dd4f85840ad (patch) | |
tree | 78cc8b8b1d4105df57715c05048c25a555dc0423 /server | |
parent | a17d8407524697f18d153c30196132db57e9b8d4 (diff) | |
download | lua-language-server-9235116d2a54052f9be43e9291d70dd4f85840ad.zip |
跟进协议
Diffstat (limited to 'server')
-rw-r--r-- | server/src/method/textDocument/completion.lua | 16 | ||||
-rw-r--r-- | server/src/method/textDocument/definition.lua | 22 | ||||
-rw-r--r-- | server/src/method/textDocument/hover.lua | 6 | ||||
-rw-r--r-- | server/src/method/textDocument/implementation.lua | 23 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 4 |
5 files changed, 38 insertions, 33 deletions
diff --git a/server/src/method/textDocument/completion.lua b/server/src/method/textDocument/completion.lua index b6dd55c4..c0fcfb44 100644 --- a/server/src/method/textDocument/completion.lua +++ b/server/src/method/textDocument/completion.lua @@ -20,12 +20,26 @@ local function findStartPos(pos, buf) local res = nil for i = pos-1, 1, -1 do local c = buf:sub(i, i) - if c:find '%a' then + if c:find '[%w_]' then res = i else break end end + if not res then + for i = pos-1, 1, -1 do + local c = buf:sub(i, i) + if c:find '[%.%:]' then + res = i + elseif c:find '[%s%c]' then + else + break + end + end + end + if not res then + return pos + end return res end diff --git a/server/src/method/textDocument/definition.lua b/server/src/method/textDocument/definition.lua index 8c8a2bb7..a9c05752 100644 --- a/server/src/method/textDocument/definition.lua +++ b/server/src/method/textDocument/definition.lua @@ -1,17 +1,11 @@ local core = require 'core' -local function checkWorkSpaceComplete(lsp, result) - if result.type ~= 'field' and result.type ~= 'local' then +local function checkWorkSpaceComplete(lsp, source) + if not source:bindValue() then return end - if result.value then - if not result.value.isRequire then - return - end - else - if not result.isRequire then - return - end + if not source:bindValue():get 'cross file' then + return end lsp:checkWorkSpaceComplete() end @@ -24,14 +18,14 @@ return function (lsp, params) end -- lua是从1开始的,因此都要+1 local position = lines:position(params.position.line + 1, params.position.character + 1) - local result = core.findSource(vm, position) - if not result then + local source = core.findSource(vm, position) + if not source then return nil end - checkWorkSpaceComplete(lsp, result) + checkWorkSpaceComplete(lsp, source) - local positions = core.definition(vm, result, lsp) + local positions = core.definition(vm, source, lsp) if not positions then return nil end diff --git a/server/src/method/textDocument/hover.lua b/server/src/method/textDocument/hover.lua index 5dea17cb..5bb8cbb9 100644 --- a/server/src/method/textDocument/hover.lua +++ b/server/src/method/textDocument/hover.lua @@ -9,12 +9,12 @@ return function (lsp, params) -- lua是从1开始的,因此都要+1 local position = lines:position(params.position.line + 1, params.position.character + 1) - local result, source = core.findSource(vm, position) - if not result then + local source = core.findSource(vm, position) + if not source then return nil end - local hover = core.hover(result, source, lsp) + local hover = core.hover(source, lsp) if not hover then return nil end diff --git a/server/src/method/textDocument/implementation.lua b/server/src/method/textDocument/implementation.lua index d6bf35bf..c9062180 100644 --- a/server/src/method/textDocument/implementation.lua +++ b/server/src/method/textDocument/implementation.lua @@ -1,14 +1,11 @@ local core = require 'core' -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 +local function checkWorkSpaceComplete(lsp, source) + if not source:bindValue() then + return + end + if not source:bindValue():get 'cross file' then + return end lsp:checkWorkSpaceComplete() end @@ -21,14 +18,14 @@ return function (lsp, params) end -- lua是从1开始的,因此都要+1 local position = lines:position(params.position.line + 1, params.position.character + 1) - local result = core.findSource(vm, position) - if not result then + local source = core.findSource(vm, position) + if not source then return nil end - checkWorkSpaceComplete(lsp, result) + checkWorkSpaceComplete(lsp, source) - local positions = core.implementation(vm, result, lsp) + local positions = core.implementation(vm, source, lsp) if not positions then return nil end diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 9e685138..a5c9168d 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -241,7 +241,7 @@ function mt:callRequire(func, values) local requireValue = self:tryRequireOne(values[1], 'require') if not requireValue then requireValue = self:createValue('boolean') - requireValue.isRequire = true + requireValue:set('cross file', true) end func:setReturn(1, requireValue) end @@ -258,7 +258,7 @@ function mt:callLoadFile(func, values) local requireValue = self:tryRequireOne(values[1], 'loadfile') if not requireValue then requireValue = self:createValue('any') - requireValue.isRequire = true + requireValue:set('cross file', true) end func:setReturn(1, requireValue) end |