LanguageClient-neovim icon indicating copy to clipboard operation
LanguageClient-neovim copied to clipboard

formatting file clears the last line of a file with golang when nofixeol is active

Open mildred opened this issue 5 years ago • 1 comments

Describe the bug

Environment

  • neovim/vim version (nvim --version): NVIM v0.3.4

  • This plugin version (git rev-parse --short HEAD): f3b2210

  • This plugin's binary version (bin/languageclient --version): languageclient 0.1.146 f3b2210c19b8ae4186ef66abfd75fd8f0323e955

  • Minimal vimrc content min-vimrc.vim:

    call plug#begin('~/.vim/bundle')
    
    Plug 'autozimu/LanguageClient-neovim', {
        \ 'branch': 'next',
        \ 'do': 'make release',
        \ }
    
    call plug#end()
    
    set nofixeol   " Don't fix last line of file to add \n if they don't
    
    let g:LanguageClient_serverCommands = {
        \ 'go':   ['gopls'],
        \ }
    
  • Language server link and version: golang.org/x/tools/[email protected] h1:mU/O8r53RjzdZfkqmFOX4iEt8PJxTPXyLdiuQNa27OE=

To Reproduce

Steps to reproduce the behavior:

  1. Start vim, nvim -u min-vimrc.vim ...
  2. Edit any go file where the last line does not end with \n
  3. Execute :call LanguageClient#textDocument_formatting_sync()
  4. See that the last line has been cleared of its content

Current behavior

LanguageClient#textDocument_formatting_sync() clears the last line of the file if nofixeol is set, creating syntax errors.

Expected behavior

nofixeol should not have any effect on formatting. Not wanting the last line to be fixed is a valid setting, and the formatting should work in any case.

mildred avatar Jul 03 '19 12:07 mildred

Thanks for reporting.

I concluded this is a server issue.

With nofixeol setting in vim, i.e., file don't have a end of line character, gopls returns edits as

{
  "jsonrpc": "2.0",
  "result": [
    {
      "range": {
        "start": {
          "line": 5,
          "character": 0
        },
        "end": {
          "line": 6,
          "character": 0
        }
      },
      "newText": ""
    },
    {
      "range": {
        "start": {
          "line": 6,
          "character": 0
        },
        "end": {
          "line": 7,
          "character": 0
        }
      },
      "newText": ""
    },
    {
      "range": {
        "start": {
          "line": 7,
          "character": 0
        },
        "end": {
          "line": 7,
          "character": 0
        }
      },
      "newText": "\tfmt.Println(\"Hello, 世界\")\n"
    },
    {
      "range": {
        "start": {
          "line": 7,
          "character": 0
        },
        "end": {
          "line": 7,
          "character": 0
        }
      },
      "newText": "}\n"
    }
  ],
  "id": 2
}

which violates the protocol that no text edits should overlap.

I will report to gopls and resolve this one.

autozimu avatar Jul 26 '19 04:07 autozimu