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
This commit is contained in:
Tomáš Janoušek
2021-02-20 17:16:47 +01:00
committed by GitHub
parent d340710fcf
commit 2550f5d952
4 changed files with 250 additions and 48 deletions

View File

@@ -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")