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

ALE LSP support with renameProvider only accepts bool, should also accept RenameOptions #2907

Closed
math2001 opened this issue Nov 24, 2019 · 6 comments
Labels
enhancement LSP Any issue relating to LSP or tsserver

Comments

@math2001
Copy link

Information

VIM version

VIM - Vi IMproved 8.1 (2018 May 18, compiled Sep 05 2019 11:15:15)
Included patches: 1-875, 878, 884, 948, 1046, 1365-1368, 1382, 1401

Operating System: Ubuntu 19.10

What went wrong

ALERename doesn't do anything with gopls (I haven't tried other linters). However, renaming is a feature that is supported by gopls

Reproducing the bug

  1. Put cursor on a symbol
  2. Press :ALERename
  3. Change variable name (press enter)
  4. nothing happens (no error messages)

asciicast

:ALEInfo

 Current Filetype: go
Available Linters: ['bingo', 'gobuild', 'gofmt', 'golangci-lint', 'golint', 'gometalinter', 'gopls', 'gosimple', 'gotype', 'govet', 'golangserver', 'staticcheck']
   Linter Aliases:
'gobuild' -> ['go build']
'govet' -> ['go vet']
  Enabled Linters: ['gopls']
 Suggested Fixers: 
  'gofmt' - Fix Go files with go fmt.
  'goimports' - Fix Go files imports with goimports.
  '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.
 Linter Variables:

let g:ale_go_go_executable = 'go'
let g:ale_go_goimports_executable = 'goimports'
let g:ale_go_goimports_options = ''
let g:ale_go_golangci_lint_executable = 'golangci-lint'
let g:ale_go_golangci_lint_options = '--enable-all'
let g:ale_go_golangci_lint_package = 0
let g:ale_go_gopls_executable = 'gopls'
let g:ale_go_gopls_options = '--mode stdio'
let g:ale_go_langserver_executable = 'go-langserver'
let g:ale_go_langserver_options = ''
 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 = {}
let b:ale_fixers = ['goimports']
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = v:null
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 = 'never'
let g:ale_linter_aliases = {}
let g:ale_linters = {}
let b:ale_linters = ['gopls']
let g:ale_linters_explicit = 0
let g:ale_list_vertical = 1
let g:ale_list_window_size = 5
let g:ale_loclist_msg_format = v:null
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 = v:null
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 = 0
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 1
let b:ale_sign_column_always = 1
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/sh', '-c', '''goimports'' -l -w -srcdir ''/home/math2001/tmp-go-rename/rename.go'' ''/tmp/vEgs4HO/1/rename.go''']
(finished - exit code 0) ['/bin/sh', '-c', '''goimports'' -l -w -srcdir ''/home/math2001/tmp-go-rename/rename.go'' ''/tmp/vEgs4HO/2/rename.go''']
(finished - exit code 0) ['/bin/sh', '-c', '''goimports'' -l -w -srcdir ''/home/math2001/tmp-go-rename/rename.go'' ''/tmp/vEgs4HO/3/rename.go''']
@RyanSquared
Copy link
Member

Are you sure you're using the latest version of gopls? It seems like support for renaming is rather limited at the moment, if it even is supported for your version. Also, can you use ch_logfile() so ALE's LSP output gets logged to a file (which you can then attach to a comment on this issue), so we can see what gopls is returning for the call?

@math2001
Copy link
Author

Are you sure you're using the latest version of gopls?

~ $ gopls version                                                                                                                                                                                  hp-compaq
golang.org/x/tools/gopls 0.2.0
    golang.org/x/tools/[email protected] h1:qXHEqJw4CqROYvoDXinY1ZOkyAFS+jcPOvLRK76dvwY=

Which seems to be the latest version (that's what I get after running go get golang.org/x/tools/gopls@latest, which is given here)

Nothing happens with in the logfile when I run the ALERename (I use a separate terminal with tail -f logfile to see in real time). Here is a fresh log file after running ALERename:

==== start log session ====

Just to prove that the log do work, here they are after inserting a few characters:

==== start log session ====
==== start log session ====
 43.774291 SEND on 0(in): 'Content-Length: 279

{"method":"textDocument/didChange","jsonrpc":"2.0","params":{"contentChanges":[{"text":"package main\n\nimport \"fmt\"\n\nfunc main() {\n\ttext := \"hello\"\n    dd\n\tfmt.Println(text)\n}\n"}],"textDocument":{"uri":"file:///home/math2001/tmp-go-rename/rename.go","version":30}}}'
 43.782798 RECV on 0(out): 'Content-Length: 282

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///home/math2001/tmp-go-rename/rename.go","diagnostics":[{"range":{"start":{"line":6,"character":4},"end":{"line":6,"character":6}},"severity":1,"source":"compiler","message":"undeclared name: dd"}]}}'
 43.783176 SEND on 0(in): 'Content-Length: 178

{"method":"textDocument/completion","jsonrpc":"2.0","id":23,"params":{"textDocument":{"uri":"file:///home/math2001/tmp-go-rename/rename.go"},"position":{"character":6,"line":6}}}'
 43.788024 RECV on 0(out): 'Content-Length: 68

'
 43.788035 : looking for messages on channels
 43.788085 on 0: Invoking channel callback <SNR>66_VimOutputCallback
 43.790510 RECV on 0(out): '{"jsonrpc":"2.0","result":{"isIncomplete":false,"items":[]},"id":23}'
 43.790867 on 0: Invoking channel callback <SNR>66_VimOutputCallback
 43.801477 : looking for messages on channels
 43.903856 SEND on 0(in): 'Content-Length: 280

{"method":"textDocument/didChange","jsonrpc":"2.0","params":{"contentChanges":[{"text":"package main\n\nimport \"fmt\"\n\nfunc main() {\n\ttext := \"hello\"\n    ddf\n\tfmt.Println(text)\n}\n"}],"textDocument":{"uri":"file:///home/math2001/tmp-go-rename/rename.go","version":31}}}'
 43.904713 SEND on 0(in): 'Content-Length: 178

{"method":"textDocument/completion","jsonrpc":"2.0","id":24,"params":{"textDocument":{"uri":"file:///home/math2001/tmp-go-rename/rename.go"},"position":{"character":7,"line":6}}}'
 43.906033 RECV on 0(out): 'Content-Length: 283

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///home/math2001/tmp-go-rename/rename.go","diagnostics":[{"range":{"start":{"line":6,"character":4},"end":{"line":6,"character":7}},"severity":1,"source":"compiler","message":"undeclared name: ddf"}]}}'
 43.906042 : looking for messages on channels
 43.906068 on 0: Invoking channel callback <SNR>66_VimOutputCallback
 43.906492 RECV on 0(out): 'Content-Length: 68

{"jsonrpc":"2.0","result":{"isIncomplete":false,"items":[]},"id":24}'
 43.909469 on 0: Invoking channel callback <SNR>66_VimOutputCallback
 43.991858 : looking for messages on channels
 44.095447 SEND on 0(in): 'Content-Length: 281

{"method":"textDocument/didChange","jsonrpc":"2.0","params":{"contentChanges":[{"text":"package main\n\nimport \"fmt\"\n\nfunc main() {\n\ttext := \"hello\"\n    ddfs\n\tfmt.Println(text)\n}\n"}],"textDocument":{"uri":"file:///home/math2001/tmp-go-rename/rename.go","version":32}}}'
 44.097086 SEND on 0(in): 'Content-Length: 178

{"method":"textDocument/completion","jsonrpc":"2.0","id":25,"params":{"textDocument":{"uri":"file:///home/math2001/tmp-go-rename/rename.go"},"position":{"character":8,"line":6}}}'
 44.097457 RECV on 0(out): 'Content-Length: 284

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///home/math2001/tmp-go-rename/rename.go","diagnostics":[{"range":{"start":{"line":6,"character":4},"end":{"line":6,"character":8}},"severity":1,"source":"compiler","message":"undeclared name: ddfs"}]}}'
 44.097465 : looking for messages on channels
 44.097539 on 0: Invoking channel callback <SNR>66_VimOutputCallback
 44.098411 RECV on 0(out): 'Content-Length: 68

{"jsonrpc":"2.0","result":{"isIncomplete":false,"items":[]},"id":25}'
 44.101005 on 0: Invoking channel callback <SNR>66_VimOutputCallback
 45.200905 : looking for messages on channels
 45.303349 SEND on 0(in): 'Content-Length: 280

{"method":"textDocument/didChange","jsonrpc":"2.0","params":{"contentChanges":[{"text":"package main\n\nimport \"fmt\"\n\nfunc main() {\n\ttext := \"hello\"\n    ddf\n\tfmt.Println(text)\n}\n"}],"textDocument":{"uri":"file:///home/math2001/tmp-go-rename/rename.go","version":33}}}'
 45.304145 SEND on 0(in): 'Content-Length: 178

{"method":"textDocument/completion","jsonrpc":"2.0","id":26,"params":{"textDocument":{"uri":"file:///home/math2001/tmp-go-rename/rename.go"},"position":{"character":7,"line":6}}}'
 45.304755 RECV on 0(out): 'Content-Length: 283

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///home/math2001/tmp-go-rename/rename.go","diagnostics":[{"range":{"start":{"line":6,"character":4},"end":{"line":6,"character":7}},"severity":1,"source":"compiler","message":"undeclared name: ddf"}]}}'
 45.304763 : looking for messages on channels
 45.304983 on 0: Invoking channel callback <SNR>66_VimOutputCallback
 45.305400 RECV on 0(out): 'Content-Length: 68

{"jsonrpc":"2.0","result":{"isIncomplete":false,"items":[]},"id":26}'
 45.308400 on 0: Invoking channel callback <SNR>66_VimOutputCallback
 45.344311 : looking for messages on channels
 45.446693 SEND on 0(in): 'Content-Length: 279

{"method":"textDocument/didChange","jsonrpc":"2.0","params":{"contentChanges":[{"text":"package main\n\nimport \"fmt\"\n\nfunc main() {\n\ttext := \"hello\"\n    dd\n\tfmt.Println(text)\n}\n"}],"textDocument":{"uri":"file:///home/math2001/tmp-go-rename/rename.go","version":34}}}'
 45.448066 SEND on 0(in): 'Content-Length: 178

{"method":"textDocument/completion","jsonrpc":"2.0","id":27,"params":{"textDocument":{"uri":"file:///home/math2001/tmp-go-rename/rename.go"},"position":{"character":6,"line":6}}}'
 45.448267 RECV on 0(out): 'Content-Length: 282

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///home/math2001/tmp-go-rename/rename.go","diagnostics":[{"range":{"start":{"line":6,"character":4},"end":{"line":6,"character":6}},"severity":1,"source":"compiler","message":"undeclared name: dd"}]}}'
 45.448275 : looking for messages on channels
 45.448337 on 0: Invoking channel callback <SNR>66_VimOutputCallback
 45.450255 RECV on 0(out): 'Content-Length: 68

{"jsonrpc":"2.0","result":{"isIncomplete":false,"items":[]},"id":27}'
 45.451555 on 0: Invoking channel callback <SNR>66_VimOutputCallback
 45.520266 : looking for messages on channels
 47.287555 SEND on 0(in): 'Content-Length: 277

{"method":"textDocument/didChange","jsonrpc":"2.0","params":{"contentChanges":[{"text":"package main\n\nimport \"fmt\"\n\nfunc main() {\n\ttext := \"hello\"\n    \n\tfmt.Println(text)\n}\n"}],"textDocument":{"uri":"file:///home/math2001/tmp-go-rename/rename.go","version":35}}}'
 47.290121 RECV on 0(out): 'Content-Length: 142

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///home/math2001/tmp-go-rename/rename.go","diagnostics":[]}}'
 47.290277 : looking for messages on channels
 47.290368 on 0: Invoking channel callback <SNR>66_VimOutputCallback
 51.294585 : looking for messages on channels

@math2001
Copy link
Author

math2001 commented Nov 24, 2019

Oh, I got something. I did a little bit of echo everywhere, and this is where we stop:

ale/autoload/ale/rename.vim

Lines 143 to 147 in b91d82b

if !ale#lsp#HasCapability(l:id, 'rename')
return
endif

Which makes sense because when I run echo ale#lsp#GetConnections(), I get something like this:

{
  'gopls:/home/math2001/tmp-go-rename':
  {
    'root': '/home/math2001/tmp-go-rename',
    'id': 'gopls:/home/math2001/tmp-go-rename',
    'data': '',
    'open_documents': {'1': 3},
    'initialized': 1,
    'job_id': 15711,
    'capabilities': {
        'symbol_search': 0,
        'rename': 0,
        'completion': 1,
        'references': 1,
        'completion_trigger_characters': ['.'],
        'typeDefinition': 1,
        'hover': 1,
        'definition': 1},
        'init_options': {},
        'callback_list': [function('ale#lsp_linter#HandleLSPResponse')], 'init_queue': [], 'init_request_id': 1, 'is_tsserver': 0, 'config': {}}}}
}

But how does capabilities get populated?

Echoing a:response here:

gives

{'id': 1, 'jsonrpc': '2.0', 'result': {'capabilities': {'executeCommandProvider': {'commands': ['tidy']}, 'documentHighlightProvider': v:true, 'hoverProvider': v:true, 'typeDefinitionProvider': v:true, 'referencesProvider': v:true, 'signatureHelpProvider': {'triggerCharacters': ['(', ',']}, 'foldingRangeProvider': v:true, 'codeActionProvider': v:true, 'textDocumentSync': {'save': {}, 'change': 2, 'openClose': v:true}, 'workspace': {'workspaceFolders': {'changeNotifications': 'workspace/didChangeWorkspaceFolders', 'supported': v:true}}, 'documentLinkProvider': {}, 'implementationProvider': v:true, 'definitionProvider': v:true, 'documentFormattingProvider': v:true, 'documentSymbolProvider': v:true, 'renameProvider': {}, 'completionProvider': {'triggerCharacters': ['.']}}, 'custom': v:null}})']}}}}

The part that seems relevant: 'renameProvider': {}... That's odd.

@RyanSquared
Copy link
Member

renameProvider can either be boolean | RenameOptions. The version of ALE that I'm looking through right now only supports the boolean option.

I'm guessing this issue can be solved by supporting a RenameOptions option for the LSP renameProvider. I'm renaming this issue to reflect that as LSP support as a whole.

@RyanSquared RyanSquared changed the title ALERename doesn't work with gopls ALE LSP support with renameProvider only accepts bool, should also accept RenameOptions Nov 25, 2019
@sbromberger
Copy link

sbromberger commented Dec 30, 2019

Here's the channel log of a (failed) ALERename using gopls:

  6.007525 : SafeState: reset: key typed
  6.010738 SEND on 1(in): 'Content-Length: 211

{"method":"textDocument/rename","jsonrpc":"2.0","id":3,"params":{"newName":"dofoo34","textDocument":{"uri":"file:///home/seth/dev/go/src/github.com/sbromberger/vt1/main.go"},"position":{"character":5,"line":4}}}'
  6.011038 : SafeState: Start triggering
  6.011387 : looking for messages on channels
  6.011408 : SafeState: back to waiting, triggering SafeStateAgain
  6.012076 RECV on 1(out): 'Content-Length: 362

{"jsonrpc":"2.0","result":{"documentChanges":[{"textDocument":{"version":1,"uri":"file:///home/seth/dev/go/src/github.com/sbromberger/vt1/main.go"},"edits":[{"range":{"start":{"line":4,"character":5},"end":{"line":4,"character":10
}},"newText":"dofoo34"},{"range":{"start":{"line":9,"character":6},"end":{"line":9,"character":11}},"newText":"dofoo34"}]}]},"id":3}'
  6.012089 on 1: Invoking channel callback <SNR>71_VimOutputCallback
  6.012948 : SafeState: back to waiting, triggering SafeStateAgain
  6.062713 : looking for messages on channels
  6.062797 : SafeState: back to waiting, triggering SafeStateAgain
  6.062910 : SafeState: reset: key typed

gopls built yesterday from master:

seth@hydrogen:~/dev/go/me/vt1$ gopls version
golang.org/x/tools/gopls master
    golang.org/x/tools/gopls@(devel)

@w0rp w0rp added enhancement LSP Any issue relating to LSP or tsserver labels Feb 22, 2020
@w0rp w0rp closed this as completed in 9bdabce Aug 7, 2020
@w0rp
Copy link
Member

w0rp commented Aug 7, 2020

I've fixed this and many other things by checking if the capabilities are dictionaries, including one that doesn't support dictionaries in the spec, but you can bet it will some day. ALE doesn't do anything with any of the options at the moment, (except for completion) it just turns the features on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement LSP Any issue relating to LSP or tsserver
Projects
None yet
Development

No branches or pull requests

4 participants