Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming symbols via ALERename gives a "list index out of range" error #2801

Open
geoyws opened this issue Oct 2, 2019 · 19 comments
Open

Renaming symbols via ALERename gives a "list index out of range" error #2801

geoyws opened this issue Oct 2, 2019 · 19 comments
Assignees
Labels

Comments

@geoyws
Copy link

geoyws commented Oct 2, 2019

Information

VIM version

VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul 21 2019 22:54:00)
macOS version
Included patches: 1-1722
Compiled by Homebrew

Operating System:

masOS Mojave 10.14.6 (18G95)

What went wrong

Oftentimes when using :ALERename, the error "list index out of range" would flash for less than a second" and the symbol would not be renamed in the other files. I've already searched through Issues for relevant help. I have not put it on Stack Overflow since the feature is rather new.

Reproducing the bug

  1. I moved over a variable name and hit :ALERename. Then I put in a new name and hit enter.
  2. Then the error "list index out of range" flashed for less than a second and although the symbol is renamed, her imports are not.

image

:ALEInfo

Current Filetype: typescript
Available Linters: ['eslint', 'tslint', 'tsserver', 'typecheck', 'xo']
Enabled Linters: ['eslint', 'tslint', 'tsserver', 'typecheck', 'xo']
Suggested Fixers:
'eslint' - Apply eslint --fix to a file.
'prettier' - Apply prettier to a file.
'remove_trailing_lines' - Remove all blank lines at the end of a file.
'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
'tslint' - Fix typescript files with tslint --fix.
'xo' - Fix JavaScript/TypeScript files using xo --fix.
Linter Variables:

let g:ale_typescript_tslint_config_path = ''
let g:ale_typescript_tslint_executable = 'tslint'
let g:ale_typescript_tslint_ignore_empty_files = 0
let g:ale_typescript_tslint_rules_dir = ''
let g:ale_typescript_tslint_use_global = 0
let g:ale_typescript_tsserver_config_path = ''
let g:ale_typescript_tsserver_executable = 'tsserver'
let g:ale_typescript_tsserver_use_global = 0
let g:ale_typescript_xo_executable = 'xo'
let g:ale_typescript_xo_options = ''
let g:ale_typescript_xo_use_global = 0
Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = 100
let g:ale_completion_enabled = 1
let g:ale_completion_max_suggestions = 50
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 1
let g:ale_fixers = {'markdown': ['prettier'], 'scss': ['prettier'], '*': ['remove_trailing_lines', 'trim_whitespace'], 'javascript': ['prettier', 'eslint'], 'css': ['prettier']}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {'javascript': ['eslint']}
let g:ale_linters_explicit = 0
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_lsp_root = {}
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '>>'
let g:ale_sign_info = '--'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '--'
let g:ale_sign_warning = '--'
let g:ale_sign_highlight_linenrs = 0
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
Command History:

(finished - exit code 0) ['/bin/bash', '-c', '''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/node_modules/eslint/bin/eslint.js'' -f json --stdin --stdin-filename ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models/index.ts'' < ''/var/folders/4y/003h9qqs4yb21ww1yfc6rtp80000gn/T/vgYxNJc/164/index.ts''']

<<>>
[{"filePath":"/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models/index.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}]
<<>>

(finished - exit code 0) ['/bin/bash', '-c', 'cd ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models'' && ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/node_modules/.bin/tslint'' --format json -c ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/tslint.json'' ''/var/folders/4y/003h9qqs4yb21ww1yfc6rtp80000gn/T/vgYxNJc/165/index.ts''']

<<>>
[]
<<>>

(executable check - failure) typecheck
(executable check - failure) xo
(finished - exit code 0) ['/bin/bash', '-c', '''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/node_modules/eslint/bin/eslint.js'' -f json --stdin --stdin-filename ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models/index.ts'' < ''/var/folders/4y/003h9qqs4yb21ww1yfc6rtp80000gn/T/vgYxNJc/166/index.ts''']

<<>>
[{"filePath":"/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models/index.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}]
<<>>

(finished - exit code 0) ['/bin/bash', '-c', 'cd ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models'' && ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/node_modules/.bin/tslint'' --format json -c ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/tslint.json'' ''/var/folders/4y/003h9qqs4yb21ww1yfc6rtp80000gn/T/vgYxNJc/167/index.ts''']

<<>>
[]
<<>>

(executable check - failure) typecheck
(executable check - failure) xo
(finished - exit code 0) ['/bin/bash', '-c', '''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/node_modules/eslint/bin/eslint.js'' -f json --stdin --stdin-filename ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models/index.ts'' < ''/var/folders/4y/003h9qqs4yb21ww1yfc6rtp80000gn/T/vgYxNJc/168/index.ts''']

<<>>
[{"filePath":"/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models/index.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}]
<<>>

(finished - exit code 0) ['/bin/bash', '-c', 'cd ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models'' && ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/node_modules/.bin/tslint'' --format json -c ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/tslint.json'' ''/var/folders/4y/003h9qqs4yb21ww1yfc6rtp80000gn/T/vgYxNJc/169/index.ts''']

<<>>
[]
<<>>

(executable check - failure) typecheck
(executable check - failure) xo
(finished - exit code 0) ['/bin/bash', '-c', '''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/node_modules/eslint/bin/eslint.js'' -f json --stdin --stdin-filename ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models/index.ts'' < ''/var/folders/4y/003h9qqs4yb21ww1yfc6rtp80000gn/T/vgYxNJc/170/index.ts''']

<<>>
[{"filePath":"/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models/index.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}]
<<>>

(finished - exit code 0) ['/bin/bash', '-c', 'cd ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models'' && ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/node_modules/.bin/tslint'' --format json -c ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/tslint.json'' ''/var/folders/4y/003h9qqs4yb21ww1yfc6rtp80000gn/T/vgYxNJc/171/index.ts''']

<<>>
[]
<<>>

(executable check - failure) typecheck
(executable check - failure) xo
(finished - exit code 0) ['/bin/bash', '-c', '''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/node_modules/eslint/bin/eslint.js'' -f json --stdin --stdin-filename ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models/index.ts'' < ''/var/folders/4y/003h9qqs4yb21ww1yfc6rtp80000gn/T/vgYxNJc/172/index.ts''']

<<>>
[{"filePath":"/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models/index.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}]
<<>>

(finished - exit code 0) ['/bin/bash', '-c', 'cd ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/src/models'' && ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/node_modules/.bin/tslint'' --format json -c ''/Users/geoyws/work/src/ifca/ifca-react/src/modules/ifca-construction-react/tslint.json'' ''/var/folders/4y/003h9qqs4yb21ww1yfc6rtp80000gn/T/vgYxNJc/173/index.ts''']

<<>>
[]
<<>>

(executable check - failure) typecheck
(executable check - failure) xo

@w0rp w0rp added the bug label Oct 3, 2019
@w0rp
Copy link
Member

w0rp commented Oct 3, 2019

Can you create a small sample project you can reliably repeat this bug in? I've seen this bug appear only once before, and I've never been able to repeat it since.

@geoyws
Copy link
Author

geoyws commented Oct 4, 2019

https://github.com/geoyws/test-ts

Hope it's something that's wrong on my end instead. Looking forward to not having to use another plugin. 😅

@w0rp
Copy link
Member

w0rp commented Oct 7, 2019

I know the error does happen now and then, but I can't repeat it with that project. I'm interested to know how to repeat the bug consistently.

@geoyws
Copy link
Author

geoyws commented Oct 10, 2019

Maybe there's something wrong on my end. Let me run a few tests :). Thanks for your kind attention!

@geoyws geoyws closed this as completed Oct 10, 2019
@w0rp
Copy link
Member

w0rp commented Oct 14, 2019

I'll reopen as I know this is an an issue, it just doesn't happen all of the time, and I can't repeat it consistently.

@w0rp w0rp reopened this Oct 14, 2019
@geoyws
Copy link
Author

geoyws commented Oct 17, 2019

I'm rushing a project currently so am really busy, but I have an inkling it has to do with when we forget to save the buffer we're working on and invoke FZF...

@dfn-certling
Copy link
Contributor

I have a similar problem with neovim and python-language-server.

As far as I debugged it, the problem lies in handling a range that falls at the end of the file. With a rename python-language-server (at least in my current case) returns the whole file as a change. Thus the range of the edit ends with character 0 on the first line after the last line of the file. This breaks the logic in ale#code_action#ApplyChanges that assumes that l:lines[l:end_line - 1] and l:lines[l:end_line :] are valid index accesses. With l:end_line being the line after the last line that isn't true and yields a list index out of range.

Looking now at geoyws screenshot, I realize that it may be a different cause for the same error, as in my case the index being out of range is not 0.

@w0rp
Copy link
Member

w0rp commented Sep 9, 2020

@dfn-certling Could you attach a diff for that, and the complete error message that you see? If so, I can add a test for that and make sure that doesn't happen again.

@dfn-certling
Copy link
Contributor

I just made a pull request #3344 that fixes that error for me.

For completeness the previous error messages are:

Error detected while processing function <SNR>114_NeoVimCallback[4]..ale#util#JoinNeovimOutput[
2]..<lambda>13[1]..ale#lsp#HandleMessage[30]..ale#rename#HandleLSPResponse[48]..ale#code_action
#HandleCodeAction[15]..ale#code_action#ApplyChanges:
line   67:
E684: list index out of range: 155
Press ENTER or type command to continue
Error detected while processing function <SNR>114_NeoVimCallback[4]..ale#util#JoinNeovimOutput[
2]..<lambda>13[1]..ale#lsp#HandleMessage[30]..ale#rename#HandleLSPResponse[48]..ale#code_action
#HandleCodeAction[15]..ale#code_action#ApplyChanges:
line   67:
E15: Invalid expression: l:lines[l:end_line - 1][l:end_column - 1 :]

@steveYeah
Copy link

I also get the same error

Error detected while processing function <SNR>84_NeoVimCallback[4]..ale#util#JoinNeovimOutput[2]..<lambda>11[1]..ale#lsp#HandleMessage[30]..ale#rename#HandleLSPResponse[48]..ale#code_action#HandleCodeAction[22]..ale
#code_action#ApplyChanges:
line   67:
E684: list index out of range: 96
Error detected while processing function <SNR>84_NeoVimCallback[4]..ale#util#JoinNeovimOutput[2]..<lambda>11[1]..ale#lsp#HandleMessage[30]..ale#rename#HandleLSPResponse[48]..ale#code_action#HandleCodeAction[22]..ale
#code_action#ApplyChanges:
line   67:
E15: Invalid expression: l:lines[l:end_line - 1][l:end_column - 1 :]

@montanier
Copy link

I got the same error, and confirm that #3344 fixes it

@w0rp
Copy link
Member

w0rp commented Nov 21, 2020

I've merged that pull request now, so that should fix that.

Thanks to @dfn-certling 👍.

@w0rp w0rp closed this as completed Nov 21, 2020
@steveYeah
Copy link

Amazing! Thanks for sorting this 👍

@montanier
Copy link

Thanks @w0rp @dfn-certling 👍

@gmg137
Copy link

gmg137 commented Feb 23, 2021

I encountered the same problem when renaming the rust function.
Language server: rust-analyzer
neovim: 0.4.4
ale: latest

Error detected while processing function <SNR>94_NeoVimCallback[4]..ale#util#JoinNeovimOutput[2]..<lambda>8[1]..ale#lsp#HandleMessage[30]..ale#rename#HandleLS
PResponse[21]..ale#code_action#HandleCodeAction[6]..ale#code_action#ApplyChanges:
line   44:
E684: list index out of range: 39

Reproduce the code.

main.rs

mod test;
use test::*;
fn main() {
    let a = test1();
}

test.rs

pub fn test1() {}

@w0rp w0rp reopened this Feb 24, 2021
@w0rp
Copy link
Member

w0rp commented Feb 24, 2021

@gmg137 Could you git pull the latest version of ALE and try this again? Please include all of the lines of the error message, as Vim can sometimes hit a problem on one line that causes an error on another line, so you can't see which line the problem actually comes from. Line 44 in that function seems to be for something else in the latest commit now. (The only index expression on that line is for -1 now, so it doesn't match up.)

@w0rp w0rp self-assigned this Feb 24, 2021
@w0rp w0rp added this to To Do in On the Radar via automation Feb 24, 2021
@gmg137
Copy link

gmg137 commented Feb 25, 2021

@w0rp Hi, there is no error output after pull the latest version of ale, but the contents of other files are overwritten.
2021-02-25 08-53-00 的屏幕截图
2021-02-25 08-53-19 的屏幕截图

The contents of main.rs are overwritten after executing ALERename.
2021-02-25 08-53-52 的屏幕截图

@w0rp
Copy link
Member

w0rp commented Mar 1, 2021

Could you upload that example Rust project to GitHub so I can try it out? I can install Rust pretty easily on my machine to test it and figure out how to fix it.

@gmg137
Copy link

gmg137 commented Mar 2, 2021

Hello, the rust example has been uploaded.
https://github.com/gmg137/test_ale

This is my ale configuration

let g:ale_linters = {
    \   'rust': ['analyzer', 'cargo', 'rustc'],
    \   'go': ['golint', 'gopls', 'go build', 'go vet', 'gofmt'],
    \   'json': ['jq'],
    \}
let g:ale_linters_explicit = 1
let g:ale_fixers = {
    \   '*': ['remove_trailing_lines', 'trim_whitespace'],
    \   'rust': ['rustfmt'],
    \   'go': ['gofmt'],
    \   'json': ['jq'],
    \}
let g:ale_rust_rls_config = {
    \   'rust': {
    \     'clippy_preference': 'on'
    \   }
    \ }

let g:ale_rust_analyzer_config = {
    \ 'diagnostics': { 'disabled': ['unresolved-import'] },
    \ 'cargo': { 'loadOutDirsFromCheck': v:true },
    \ 'procMacro': { 'enable': v:true },
    \ 'checkOnSave': { 'command': 'clippy', 'enable': v:true }
    \ }
let g:ale_fix_on_save = 1
let g:ale_rust_rustfmt_options = "--edition 2018"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

6 participants