summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/code-action.lua31
-rw-r--r--test.lua1
-rw-r--r--test/code_action/init.lua36
3 files changed, 68 insertions, 0 deletions
diff --git a/script/core/code-action.lua b/script/core/code-action.lua
index 3a7f7374..13d5220d 100644
--- a/script/core/code-action.lua
+++ b/script/core/code-action.lua
@@ -279,6 +279,34 @@ local function solveDiagnostic(uri, diag, results)
disableDiagnostic(uri, diag.code, results)
end
+local function checkSwapParams(results, uri, start, finish)
+ local ast = files.getAst(uri)
+ if not ast then
+ return
+ end
+ local result = guide.eachSourceBetween(ast.ast, start, finish, function (source)
+ if source.type == 'callargs' then
+ return {
+ node = source.parent.node,
+ args = source,
+ }
+ end
+ if source.type == 'funcargs' then
+ return {
+ node = source.parent,
+ args = source,
+ }
+ end
+ end)
+ if not result then
+ return
+ end
+end
+
+local function checkExtractAsFunction(results, uri, start, finish)
+
+end
+
return function (uri, start, finish, diagnostics)
local ast = files.getAst(uri)
if not ast then
@@ -291,5 +319,8 @@ return function (uri, start, finish, diagnostics)
solveDiagnostic(uri, diag, results)
end
+ checkSwapParams(results, uri, start, finish)
+ checkExtractAsFunction(results, uri, start, finish)
+
return results
end
diff --git a/test.lua b/test.lua
index 88c2817c..ed8d8dfc 100644
--- a/test.lua
+++ b/test.lua
@@ -68,6 +68,7 @@ local function main()
test 'completion'
test 'signature'
test 'document_symbol'
+ test 'code_action'
test 'crossfile'
test 'full'
--test 'other'
diff --git a/test/code_action/init.lua b/test/code_action/init.lua
new file mode 100644
index 00000000..d3b2d768
--- /dev/null
+++ b/test/code_action/init.lua
@@ -0,0 +1,36 @@
+local core = require 'core.code-action'
+local files = require 'files'
+local lang = require 'language'
+
+rawset(_G, 'TEST', true)
+
+function TEST(script)
+ return function (expect)
+ files.removeAll()
+ local start = script:find('<?', 1, true)
+ local finish = script:find('?>', 1, true)
+ local pos = (start + finish) // 2 + 1
+ local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
+ files.setText('', new_script)
+ local results = core('', pos)
+ assert(results)
+ assert(expect == results)
+ end
+end
+
+TEST [[
+print(<?a?>, b, c)
+]]
+{
+ {
+ title = lang.script.ACTION_SWAP_PARAMS,
+ kind = 'refactor.rewrite',
+ edit = {
+ change = {
+ ['file:///.lua'] = {
+
+ }
+ }
+ }
+ }
+}