summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/matcher/implementation.lua51
-rw-r--r--server/src/matcher/references.lua42
-rw-r--r--server/src/matcher/rename.lua43
-rw-r--r--server/src/matcher/vm.lua1
-rw-r--r--server/src/method/textDocument/implementation.lua2
-rw-r--r--server/src/method/textDocument/references.lua2
-rw-r--r--server/src/method/textDocument/rename.lua2
7 files changed, 28 insertions, 115 deletions
diff --git a/server/src/matcher/implementation.lua b/server/src/matcher/implementation.lua
index e51d7a22..34b09693 100644
--- a/server/src/matcher/implementation.lua
+++ b/server/src/matcher/implementation.lua
@@ -1,54 +1,17 @@
local findResult = require 'matcher.find_result'
-local function tryMeta(var)
- local keys = {}
- repeat
- if var.childs.meta then
- local metavar = var.childs.meta
- for i = #keys, 1, -1 do
- local key = keys[i]
- metavar = metavar.childs[key]
- if not metavar then
- return nil
- end
- end
- return metavar
- end
- keys[#keys+1] = var.key
- var = var.parent
- until not var
- return nil
-end
-
local function parseResult(result)
local positions = {}
local tp = result.type
- if tp == 'var' then
- local var = result.var
- if var.type == 'local' then
- local source = var.source
- if not source then
- return false
- end
- positions[1] = {source.start, source.finish}
- end
- for _, info in ipairs(var) do
+ if tp == 'local' then
+ for _, info in ipairs(result.object) do
if info.type == 'set' then
positions[#positions+1] = {info.source.start, info.source.finish}
end
end
- local metavar = tryMeta(var)
- if metavar then
- for _, info in ipairs(metavar) do
- if info.type == 'set' then
- positions[#positions+1] = {info.source.start, info.source.finish}
- end
- end
- end
- elseif tp == 'dots' then
- local dots = result.dots
- for _, info in ipairs(dots) do
- if info.type == 'local' then
+ elseif tp == 'field' then
+ for _, info in ipairs(result.object) do
+ if info.type == 'set' then
positions[#positions+1] = {info.source.start, info.source.finish}
end
end
@@ -65,8 +28,8 @@ local function parseResult(result)
return positions
end
-return function (results, pos)
- local result = findResult(results, pos)
+return function (vm, pos)
+ local result = findResult(vm.results, pos)
if not result then
return nil
end
diff --git a/server/src/matcher/references.lua b/server/src/matcher/references.lua
index f5b72c55..a241025c 100644
--- a/server/src/matcher/references.lua
+++ b/server/src/matcher/references.lua
@@ -1,46 +1,16 @@
local findResult = require 'matcher.find_result'
-local function tryMeta(var)
- local keys = {}
- repeat
- if var.childs.meta then
- local metavar = var.childs.meta
- for i = #keys, 1, -1 do
- local key = keys[i]
- metavar = metavar.childs[key]
- if not metavar then
- return nil
- end
- end
- return metavar
- end
- keys[#keys+1] = var.key
- var = var.parent
- until not var
- return nil
-end
-
local function parseResult(result, declarat)
local positions = {}
local tp = result.type
- if tp == 'var' then
- local var = result.var
- for _, info in ipairs(var) do
+ if tp == 'local' then
+ for _, info in ipairs(result.object) do
if declarat or info.type == 'get' then
positions[#positions+1] = {info.source.start, info.source.finish}
end
end
- local metavar = tryMeta(var)
- if metavar then
- for _, info in ipairs(metavar) do
- if declarat or info.type == 'get' then
- positions[#positions+1] = {info.source.start, info.source.finish}
- end
- end
- end
- elseif tp == 'dots' then
- local dots = result.dots
- for _, info in ipairs(dots) do
+ elseif tp == 'field' then
+ for _, info in ipairs(result.object) do
if declarat or info.type == 'get' then
positions[#positions+1] = {info.source.start, info.source.finish}
end
@@ -58,8 +28,8 @@ local function parseResult(result, declarat)
return positions
end
-return function (results, pos, declarat)
- local result = findResult(results, pos)
+return function (vm, pos, declarat)
+ local result = findResult(vm.results, pos)
if not result then
return nil
end
diff --git a/server/src/matcher/rename.lua b/server/src/matcher/rename.lua
index 1838960f..b395c696 100644
--- a/server/src/matcher/rename.lua
+++ b/server/src/matcher/rename.lua
@@ -1,33 +1,13 @@
local findResult = require 'matcher.find_result'
local parser = require 'parser'
-local function tryMeta(var)
- local keys = {}
- repeat
- if var.childs.meta then
- local metavar = var.childs.meta
- for i = #keys, 1, -1 do
- local key = keys[i]
- metavar = metavar.childs[key]
- if not metavar then
- return nil
- end
- end
- return metavar
- end
- keys[#keys+1] = var.key
- var = var.parent
- until not var
- return nil
-end
-
local function parseResult(result, newName)
local positions = {}
local tp = result.type
- if tp == 'var' then
- local var = result.var
+ if tp == 'local' or tp == 'field' then
+ local var = result.object
local key = result.info.source[1]
- if var.disableRename and key == 'self' then
+ if var.disableRename then
return positions
end
if result.info.source.index then
@@ -39,20 +19,19 @@ local function parseResult(result, newName)
return positions
end
end
+ local mark = {}
for _, info in ipairs(var) do
- if info.source[1] == key then
- positions[#positions+1] = {info.source.start, info.source.finish}
- end
- end
- local metavar = tryMeta(var)
- if metavar then
- for _, info in ipairs(metavar) do
+ if not mark[info.source] then
+ mark[info.source] = info
if info.source[1] == key then
positions[#positions+1] = {info.source.start, info.source.finish}
end
end
end
elseif tp == 'label' then
+ if not parser.grammar(newName, 'Name') then
+ return positions
+ end
local label = result.label
for _, info in ipairs(label) do
positions[#positions+1] = {info.source.start, info.source.finish}
@@ -63,8 +42,8 @@ local function parseResult(result, newName)
return positions
end
-return function (results, pos, newName)
- local result = findResult(results, pos)
+return function (vm, pos, newName)
+ local result = findResult(vm.results, pos)
if not result then
return nil
end
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index 2339f769..af2e9bc2 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -233,6 +233,7 @@ function mt:buildFunction(exp, object)
if object then
local var = self:createLocal('self', object.source, self:getValue(object))
+ var.disableRename = true
func.args[1] = var
end
diff --git a/server/src/method/textDocument/implementation.lua b/server/src/method/textDocument/implementation.lua
index 4d77882d..9b29d4ec 100644
--- a/server/src/method/textDocument/implementation.lua
+++ b/server/src/method/textDocument/implementation.lua
@@ -8,7 +8,7 @@ return function (lsp, params)
end
-- lua是从1开始的,因此都要+1
local position = lines:position(params.position.line + 1, params.position.character + 1)
- local positions = matcher.implementation(vm.results, position)
+ local positions = matcher.implementation(vm, position)
if not positions then
return {}
end
diff --git a/server/src/method/textDocument/references.lua b/server/src/method/textDocument/references.lua
index 22552fbd..ee62a9dc 100644
--- a/server/src/method/textDocument/references.lua
+++ b/server/src/method/textDocument/references.lua
@@ -9,7 +9,7 @@ return function (lsp, params)
end
-- lua是从1开始的,因此都要+1
local position = lines:position(params.position.line + 1, params.position.character + 1)
- local positions = matcher.references(vm.results, position, declarat)
+ local positions = matcher.references(vm, position, declarat)
if not positions then
return {}
end
diff --git a/server/src/method/textDocument/rename.lua b/server/src/method/textDocument/rename.lua
index f9b16237..dca6cbe4 100644
--- a/server/src/method/textDocument/rename.lua
+++ b/server/src/method/textDocument/rename.lua
@@ -9,7 +9,7 @@ return function (lsp, params)
end
-- lua是从1开始的,因此都要+1
local position = lines:position(params.position.line + 1, params.position.character + 1)
- local positions = matcher.rename(vm.results, position, newName)
+ local positions = matcher.rename(vm, position, newName)
if not positions then
return {}
end