summaryrefslogtreecommitdiff
path: root/server/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/core')
-rw-r--r--server/src/core/completion.lua6
-rw-r--r--server/src/core/definition.lua24
-rw-r--r--server/src/core/find_result.lua41
-rw-r--r--server/src/core/find_source.lua36
-rw-r--r--server/src/core/init.lua2
-rw-r--r--server/src/core/references.lua4
-rw-r--r--server/src/core/rename.lua4
7 files changed, 50 insertions, 67 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 98654a65..57e006e9 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -1,4 +1,4 @@
-local findResult = require 'core.find_result'
+local findSource = require 'core.find_source'
local hover = require 'core.hover'
local CompletionItemKind = {
@@ -513,7 +513,7 @@ end
local function searchSpecial(vm, pos, callback)
-- 尝试 #
- local _, source = findResult(vm, pos, 2)
+ local _, source = findSource(vm, pos, 2)
if source and source.indexName and source[1].op == '#'
then
local label = source.indexName .. '+1'
@@ -558,7 +558,7 @@ return function (vm, pos, word)
end
searchSpecial(vm, pos, callback)
if not inString then
- local result, source = findResult(vm, pos)
+ local result, source = findSource(vm, pos)
if not isValidResult(result) then
result, source = findClosePos(vm, pos)
end
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua
index 05e62f4f..e4af5d16 100644
--- a/server/src/core/definition.lua
+++ b/server/src/core/definition.lua
@@ -125,27 +125,15 @@ local function parseResultAsVar(vm, result, lsp)
return positions
end
-local function parseResultAsValue(vm, value, lsp)
- local tp = value:getType()
- local positions = {}
- if tp == 'string' then
- -- require 'XXX' 专用
- positions[#positions+1] = {
- 0,
- 0,
- value.uri,
- }
- end
- return positions
+local function parseValue(vm, value, lsp)
+
end
-return function (vm, result, lsp)
- if not result then
+return function (vm, source, lsp)
+ if not source then
return nil
end
- if result.type == 'value' then
- return parseResultAsValue(vm, result, lsp)
- else
- return parseResultAsVar(vm, result, lsp)
+ if source:bindValue() then
+ return parseValue(vm, source:bindValue(), lsp)
end
end
diff --git a/server/src/core/find_result.lua b/server/src/core/find_result.lua
deleted file mode 100644
index a562f192..00000000
--- a/server/src/core/find_result.lua
+++ /dev/null
@@ -1,41 +0,0 @@
-local function isContainPos(obj, pos)
- if obj.start <= pos and obj.finish + 1 >= pos then
- return true
- end
- return false
-end
-
-local function isValidSource(source)
- return source.type ~= 'simple'
-end
-
-local function findAtPos(results, pos, level)
- local res = {}
- for _, source in ipairs(results.sources) do
- if isValidSource(source) and isContainPos(source, pos) then
- res[#res+1] = {
- object = source.bind,
- source = source,
- range = source.finish - source.start,
- }
- if not source.bind then
- error('Miss source object')
- end
- end
- end
- if #res == 0 then
- return nil
- end
- table.sort(res, function (a, b)
- return a.range < b.range
- end)
- local data = res[level or 1]
- if not data then
- return nil
- end
- return data.object, data.source
-end
-
-return function (vm, pos, level)
- return findAtPos(vm.results, pos, level)
-end
diff --git a/server/src/core/find_source.lua b/server/src/core/find_source.lua
new file mode 100644
index 00000000..52b42501
--- /dev/null
+++ b/server/src/core/find_source.lua
@@ -0,0 +1,36 @@
+local function isContainPos(obj, pos)
+ if obj.start <= pos and obj.finish + 1 >= pos then
+ return true
+ end
+ return false
+end
+
+local function isValidSource(source)
+ return source.start ~= nil
+end
+
+local function findAtPos(sources, pos, level)
+ local res = {}
+ for _, source in ipairs(sources) do
+ if isValidSource(source) and isContainPos(source, pos) then
+ res[#res+1] = source
+ end
+ end
+ if #res == 0 then
+ return nil
+ end
+ table.sort(res, function (a, b)
+ local rangeA = a.finish - a.start
+ local rangeB = b.finish - b.start
+ return rangeA < rangeB
+ end)
+ local source = res[level or 1]
+ if not source then
+ return nil
+ end
+ return source
+end
+
+return function (vm, pos, level)
+ return findAtPos(vm.sources, pos, level)
+end
diff --git a/server/src/core/init.lua b/server/src/core/init.lua
index 148871a1..1a556320 100644
--- a/server/src/core/init.lua
+++ b/server/src/core/init.lua
@@ -5,7 +5,7 @@ local api = {
rename = require 'core.rename',
hover = require 'core.hover',
diagnostics = require 'core.diagnostics',
- findResult = require 'core.find_result',
+ findSource = require 'core.find_source',
findLib = require 'core.find_lib',
completion = require 'core.completion',
signature = require 'core.signature',
diff --git a/server/src/core/references.lua b/server/src/core/references.lua
index 05ba99a9..1d1915f0 100644
--- a/server/src/core/references.lua
+++ b/server/src/core/references.lua
@@ -1,4 +1,4 @@
-local findResult = require 'core.find_result'
+local findSource = require 'core.find_source'
local function parseResult(vm, result, declarat, callback)
local tp = result.type
@@ -46,7 +46,7 @@ local function parseResult(vm, result, declarat, callback)
end
return function (vm, pos, declarat)
- local result = findResult(vm, pos)
+ local result = findSource(vm, pos)
if not result then
return nil
end
diff --git a/server/src/core/rename.lua b/server/src/core/rename.lua
index 655c1b9a..f3132f77 100644
--- a/server/src/core/rename.lua
+++ b/server/src/core/rename.lua
@@ -1,4 +1,4 @@
-local findResult = require 'core.find_result'
+local findSource = require 'core.find_source'
local parser = require 'parser'
local function parseResult(result, source, newName)
@@ -40,7 +40,7 @@ local function parseResult(result, source, newName)
end
return function (vm, pos, newName)
- local result, source = findResult(vm, pos)
+ local result, source = findSource(vm, pos)
if not result then
return nil
end