OmniSharp / omnisharp-vim

Vim omnicompletion (intellisense) and more for C#
http://www.omnisharp.net
MIT License
1.7k stars 169 forks source link

When virtualedit is enable, code format inserts '<' character when adding new lines #731

Closed nwessing closed 3 years ago

nwessing commented 3 years ago

I am using this plugin with neovim. I often notice this problem when using code format or code actions to introduce a new import. When omnisharp-vim does an action that results in a newline being inserted, i get a < character on the line that should be empty example;

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DomainProvider : MonoBehaviour {
    void Start() {

    }

    void Update() {

    }
}
:OmniSharpCodeFormat
using System.Collections;
using System.Collections.Generic;
<
using UnityEngine;

public class DomainProvider : MonoBehaviour {
    void Start() {

    }

    void Update() {

    }
}

Notice how line 3 has the extra < character.

I did a little bit of digging into your code to figure what was going on, I have not seen this issue mentioned anywhere else so I wanted to make sure it wasn't my configuration.

I found this: https://github.com/OmniSharp/omnisharp-vim/blob/70425f1bf7f6a9e7005535ee6265adaec932c9ea/autoload/OmniSharp/buffer.vim#L104

Where I can see the character is meant to be inserted and deleted. It turns out when I remove

set virtualedit=all

From my configuration I no longer have the issue with the extra character being inserted. It would be fantastic if you could make the plugin work better with the virtualedit option, thank you!

nickspoons commented 3 years ago

Thanks for reporting this @nwessing, and for tracking down the culprit. I had actually run into this myself a few times but not had time to investigate.

It's a very simple fix - that extra < is simply not needed when virtualedit=all.

nwessing commented 3 years ago

Thank you!