From 2550f5d952caea4ac607ec0796d8f1fae4d7b9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Janou=C5=A1ek?= Date: Sat, 20 Feb 2021 17:16:47 +0100 Subject: Fixes to code actions (cursor moving, tests, EOL/EOF corner cases) (#3478) * code_action: Don't move cursor when change covers entire file * code_action: Refactor/simplify ApplyChanges * code_action: Fix EOL at EOF corner cases while performing no changes * code_action: Fix column around EOL corner cases * code_action: Handle positions out of bounds * code_action: Add instructions for verifying corner case tests against vscode --- test/test_code_action.vader | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'test/test_code_action.vader') diff --git a/test/test_code_action.vader b/test/test_code_action.vader index 7eabb759..c613222c 100644 --- a/test/test_code_action.vader +++ b/test/test_code_action.vader @@ -1,14 +1,7 @@ Before: Save g:ale_enabled - let g:ale_enabled = 0 - " Enable fix end-of-line as tests below expect that - set fixeol - - runtime autoload/ale/code_action.vim - runtime autoload/ale/util.vim - let g:file1 = tempname() let g:file2 = tempname() let g:test = {} @@ -42,8 +35,6 @@ Before: endfunction! After: - Restore - " Close the extra buffers if we opened it. if bufnr(g:file1) != -1 execute ':bp! | :bd! ' . bufnr(g:file1) @@ -65,8 +56,7 @@ After: unlet! g:changes delfunction WriteFileAndEdit - runtime autoload/ale/code_action.vim - runtime autoload/ale/util.vim + Restore Execute(It should modify and save multiple files): @@ -214,7 +204,6 @@ Execute(End of file can be modified): \) AssertEqual g:test.text + [ - \ '', \ 'type A: string', \ 'type B: number', \ '', @@ -364,6 +353,15 @@ Execute(Cursor will not move when changes happening on lines >= cursor, but afte AssertEqual ' value: number', getline('.') AssertEqual [2, 3], getpos('.')[1:2] +Execute(Cursor will not move when change covers entire file): + call WriteFileAndEdit() + call setpos('.', [0, 2, 3, 0]) + call ale#code_action#HandleCodeAction( + \ g:test.create_change(1, 1, len(g:test.text) + 1, 1, + \ join(g:test.text + ['x'], "\n")), + \ {'should_save': 1}) + AssertEqual [2, 3], getpos('.')[1:2] + Execute(It should just modify file when should_save is set to v:false): call WriteFileAndEdit() let g:test.change = g:test.create_change(1, 1, 1, 1, "import { writeFile } from 'fs';\n") -- cgit v1.2.3