diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-05 18:40:52 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-05 18:40:52 +0800 |
commit | 87a7ea0746191bec7f24315cef85c79be37d0bf8 (patch) | |
tree | 8615abfb26db534e7478430d405feb576d3aa69f | |
parent | c8464b46347c08a2d63083670e19c5b3d8de86ee (diff) | |
download | lua-language-server-87a7ea0746191bec7f24315cef85c79be37d0bf8.zip |
对可使用的命名进行限制
-rw-r--r-- | server/src/matcher/rename.lua | 16 | ||||
-rw-r--r-- | server/src/method/textDocument/rename.lua | 2 |
2 files changed, 14 insertions, 4 deletions
diff --git a/server/src/matcher/rename.lua b/server/src/matcher/rename.lua index 13e72189..3b697309 100644 --- a/server/src/matcher/rename.lua +++ b/server/src/matcher/rename.lua @@ -1,4 +1,5 @@ local findResult = require 'matcher.find_result' +local parser = require 'parser' local function tryMeta(var) local keys = {} @@ -20,7 +21,7 @@ local function tryMeta(var) return nil end -local function parseResult(result) +local function parseResult(result, newName) local positions = {} local tp = result.type if tp == 'var' then @@ -29,6 +30,15 @@ local function parseResult(result) if var.disable_rename and key == 'self' then return positions end + if result.info.source.index then + if not parser.grammar(newName, 'Exp') then + return positions + end + else + if not parser.grammar(newName, 'Name') then + return positions + end + end for _, info in ipairs(var) do if info.source[1] == key then positions[#positions+1] = {info.source.start, info.source.finish} @@ -51,11 +61,11 @@ local function parseResult(result) return positions end -return function (results, pos) +return function (results, pos, newName) local result = findResult(results, pos) if not result then return nil end - local positions = parseResult(result) + local positions = parseResult(result, newName) return positions end diff --git a/server/src/method/textDocument/rename.lua b/server/src/method/textDocument/rename.lua index 1340226b..f8d46409 100644 --- a/server/src/method/textDocument/rename.lua +++ b/server/src/method/textDocument/rename.lua @@ -10,7 +10,7 @@ return function (lsp, params) end -- lua是从1开始的,因此都要+1 local position = lines:position(params.position.line + 1, params.position.character + 1, 'utf8') - local positions = matcher.rename(results, position) + local positions = matcher.rename(results, position, newName) if not positions then return {} end |