2020-11-14 10:15:17 +00:00
|
|
|
Given python(An example Python file):
|
|
|
|
def main():
|
|
|
|
a = 1
|
|
|
|
c = a + 1
|
|
|
|
|
|
|
|
Execute():
|
|
|
|
let g:changes = [
|
|
|
|
\ {'end': {'offset': 7, 'line': 1}, 'newText': 'func_qtffgsv', 'start': {'offset': 5, 'line': 1}},
|
|
|
|
\ {'end': {'offset': 9, 'line': 1}, 'newText': '', 'start': {'offset': 8, 'line': 1}},
|
|
|
|
\ {'end': {'offset': 15, 'line': 3}, 'newText': " return c\n\n\ndef main():\n c = func_qtffgsvi()\n", 'start': {'offset': 15, 'line': 3}}
|
|
|
|
\]
|
|
|
|
|
Dispatch textDocument/didChange after rename (2) (#4049)
* Dispatch textDocument/didChange after rename
Previously whenever we renamed a symbol that was referenced from other
files we'd just edit those files in the background, and the LSP wouldn't
know about these changes. If we tried to rename the same symbol again,
the renaming would fail. In some scenarios, the operation would just be
wrong. Here is an attempt to fix this issue.
I also noticed another bug when using Go with `gopls` LSP and the `gofmt`
fixer. Whenever the file was saved, the `gofmt` would run and reformat
the file. But it seems there was some kind of a race condition so I
disabled saving for now, and all of the modified files will be unsaved,
so the user should call `:wa` to save them. I personally like this even
better because I can inspect exactly what changes happened, and I
instantly see them in the other opened buffers, which was previously not
the case.
Fixes #3343, #3642, #3781.
* Address PR comments
* Remove mode tests in corner case tests
* Address PR comments
* Save after ALERename and ALEOrganizeImports
Also provide options to disable automatic saving, as well as instructions to
enable `set hidden` before doing that.
* Fix broken test
* Save only when !&hidden
* Update doc
* Update doc
* Add silent
2022-02-08 11:07:39 +00:00
|
|
|
call ale#code_action#ApplyChanges(expand('%:p'), g:changes, {})
|
2020-11-14 10:15:17 +00:00
|
|
|
|
|
|
|
Expect(The changes should be applied correctly):
|
|
|
|
def func_qtffgsvi():
|
|
|
|
a = 1
|
|
|
|
c = a + 1
|
|
|
|
return c
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
c = func_qtffgsvi()
|
|
|
|
|
|
|
|
|
|
|
|
Given python(Second python example):
|
|
|
|
import sys
|
|
|
|
import exifread
|
|
|
|
|
|
|
|
def main():
|
|
|
|
with open(sys.argv[1], 'rb') as f:
|
|
|
|
exif = exifread.process_file(f)
|
|
|
|
dt = str(exif['Image DateTime'])
|
|
|
|
date = dt[:10].replace(':', '-')
|
|
|
|
|
|
|
|
Execute():
|
|
|
|
let g:changes = [
|
2021-02-20 16:16:47 +00:00
|
|
|
\ {'end': {'offset': 16, 'line': 2}, 'newText': "\n\n\ndef func_ivlpdpao(f):\n exif = exifread.process_file(f)\n dt = str(exif['Image DateTime'])\n date = dt[:10].replace(':', '-')\n return date\n", 'start': {'offset': 16, 'line': 2}},
|
2020-11-14 10:15:17 +00:00
|
|
|
\ {'end': {'offset': 32, 'line': 6}, 'newText': 'date = func', 'start': {'offset': 9, 'line': 6}},
|
|
|
|
\ {'end': {'offset': 42, 'line': 8}, 'newText': "ivlpdpao(f)\n", 'start': {'offset': 33, 'line': 6}}
|
|
|
|
\]
|
|
|
|
|
Dispatch textDocument/didChange after rename (2) (#4049)
* Dispatch textDocument/didChange after rename
Previously whenever we renamed a symbol that was referenced from other
files we'd just edit those files in the background, and the LSP wouldn't
know about these changes. If we tried to rename the same symbol again,
the renaming would fail. In some scenarios, the operation would just be
wrong. Here is an attempt to fix this issue.
I also noticed another bug when using Go with `gopls` LSP and the `gofmt`
fixer. Whenever the file was saved, the `gofmt` would run and reformat
the file. But it seems there was some kind of a race condition so I
disabled saving for now, and all of the modified files will be unsaved,
so the user should call `:wa` to save them. I personally like this even
better because I can inspect exactly what changes happened, and I
instantly see them in the other opened buffers, which was previously not
the case.
Fixes #3343, #3642, #3781.
* Address PR comments
* Remove mode tests in corner case tests
* Address PR comments
* Save after ALERename and ALEOrganizeImports
Also provide options to disable automatic saving, as well as instructions to
enable `set hidden` before doing that.
* Fix broken test
* Save only when !&hidden
* Update doc
* Update doc
* Add silent
2022-02-08 11:07:39 +00:00
|
|
|
call ale#code_action#ApplyChanges(expand('%:p'), g:changes, {})
|
2020-11-14 10:15:17 +00:00
|
|
|
|
|
|
|
Expect(The changes should be applied correctly):
|
|
|
|
import sys
|
|
|
|
import exifread
|
|
|
|
|
|
|
|
|
|
|
|
def func_ivlpdpao(f):
|
|
|
|
exif = exifread.process_file(f)
|
|
|
|
dt = str(exif['Image DateTime'])
|
|
|
|
date = dt[:10].replace(':', '-')
|
|
|
|
return date
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
with open(sys.argv[1], 'rb') as f:
|
|
|
|
date = func_ivlpdpao(f)
|