diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-12-11 15:16:32 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-12-11 15:16:32 +0800 |
commit | 63910e66117d7989fc6a129bbb9e1ca23d6c19e2 (patch) | |
tree | c1ea4221a96333fce83fa06cbc6fcccba720447e | |
parent | e818b4bd52458bed6842555ce7f9b8d874968b07 (diff) | |
download | lua-language-server-63910e66117d7989fc6a129bbb9e1ca23d6c19e2.zip |
stash
-rw-r--r-- | script/core/code-action.lua | 76 | ||||
-rw-r--r-- | test/code_action/init.lua | 12 |
2 files changed, 84 insertions, 4 deletions
diff --git a/script/core/code-action.lua b/script/core/code-action.lua index d3546bbb..246e1549 100644 --- a/script/core/code-action.lua +++ b/script/core/code-action.lua @@ -370,9 +370,77 @@ local function checkSwapParams(results, uri, start, finish) end end -local function checkExtractAsFunction(results, uri, start, finish) - -end +--local function checkExtractAsFunction(results, uri, start, finish) +-- local ast = files.getAst(uri) +-- local text = files.getText(uri) +-- local funcs = {} +-- guide.eachSourceContain(ast.ast, start, function (source) +-- if source.type == 'function' +-- or source.type == 'main' then +-- funcs[#funcs+1] = source +-- end +-- end) +-- table.sort(funcs, function (a, b) +-- return a.start > b.start +-- end) +-- local func = funcs[1] +-- if not func then +-- return +-- end +-- if #func == 0 then +-- return +-- end +-- if func.finish < finish then +-- return +-- end +-- local actions = {} +-- for i = 1, #func do +-- local action = func[i] +-- if action.start < start +-- and action.finish > start then +-- return +-- end +-- if action.start < finish +-- and action.finish > finish then +-- return +-- end +-- if action.finish >= start +-- and action.start <= finish then +-- actions[#actions+1] = action +-- end +-- end +-- if text:sub(start, actions[1].start - 1):find '[%C%S]' then +-- return +-- end +-- if text:sub(actions[1].finish + 1, finish):find '[%C%S]' then +-- return +-- end +-- while func do +-- local funcName = getExtractFuncName(uri, actions[1].start) +-- local funcParams = getExtractFuncParams(uri, actions[1].start) +-- results[#results+1] = { +-- title = lang.script('ACTION_EXTRACT'), +-- kind = 'refactor.extract', +-- edit = { +-- changes = { +-- [uri] = { +-- { +-- start = actions[1].start, +-- finish = actions[1].start - 1, +-- newText = text:sub(targetArg.start, targetArg.finish), +-- }, +-- { +-- start = targetArg.start, +-- finish = targetArg.finish, +-- newText = text:sub(myArg.start, myArg.finish), +-- }, +-- } +-- } +-- } +-- } +-- func = guide.getParentFunction(func) +-- end +--end return function (uri, start, finish, diagnostics) local ast = files.getAst(uri) @@ -384,7 +452,7 @@ return function (uri, start, finish, diagnostics) checkQuickFix(results, uri, diagnostics) checkSwapParams(results, uri, start, finish) - checkExtractAsFunction(results, uri, start, finish) + --checkExtractAsFunction(results, uri, start, finish) return results end diff --git a/test/code_action/init.lua b/test/code_action/init.lua index 64c12c09..11ce6ec7 100644 --- a/test/code_action/init.lua +++ b/test/code_action/init.lua @@ -113,3 +113,15 @@ return function(<?a?>, b, c) end edit = EXISTS, }, } + +--TEST [[ +--<?print(1) +--print(2)?> +--]] +--{ +-- { +-- title = lang.script.ACTION_EXTRACT, +-- kind = 'refactor.extract', +-- edit = EXISTS, +-- }, +--} |