diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-28 15:36:56 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-28 15:36:56 +0800 |
commit | a080b2516d2ce2efb65ad0fd26126cdfa6f6e4f8 (patch) | |
tree | b5672e03d11a43a56b63fe02d7b685eacd21ace4 /server/src/core/rename.lua | |
parent | 549f6dd7ce8c733f9b51f5e93b3f14c1e2a44aca (diff) | |
download | lua-language-server-a080b2516d2ce2efb65ad0fd26126cdfa6f6e4f8.zip |
matcher -> core
Diffstat (limited to 'server/src/core/rename.lua')
-rw-r--r-- | server/src/core/rename.lua | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/server/src/core/rename.lua b/server/src/core/rename.lua new file mode 100644 index 00000000..459aabcc --- /dev/null +++ b/server/src/core/rename.lua @@ -0,0 +1,51 @@ +local findResult = require 'core.find_result' +local parser = require 'parser' + +local function parseResult(result, source, newName) + local positions = {} + local tp = result.type + if tp == 'local' or tp == 'field' then + local key = source[1] + if result.disableRename then + return positions + end + if 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 + local mark = {} + for _, info in ipairs(result) 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} + end + else + error('Unknow result type:' .. result.type) + end + return positions +end + +return function (vm, pos, newName) + local result, source = findResult(vm, pos) + if not result then + return nil + end + local positions = parseResult(result, source, newName) + return positions +end |