Closed DasOhmoff closed 2 years ago
I'm not really sure. Are you just asking advice, or do you think there's something that OmniSharp-vim should be doing in this situation? We just pass the analysis through from OmniSharp-roslyn so this seems like an issue with how vim and the lanuage server operate?
I assume that omnisharp-vim passes vims buffer to omnisharp-roslyn, which in turn responds with the warnings and errors. Therefore I think that omnisharp-vim is maybe not passing the last empty new line at the end of the file to omnisharp-roslyn, which in turn thinks that there is no new line at the end of the file, and therefore sends the warning back. Basically I think that maybe not the real content of the file is passed to the roslyn server, but the one that is displayed by vim, in which the last blank line is trimmed away.
If that is the case, I think that omnisharp-vim should act as if there is a blank line and the end and pass that to the roslyn server. I think that one could do that by adding the last new line character to the buffer that is passed to the server if the endofline
setting is enabled.
Hmm OK I see what you mean. It sounds ... fiddly though.
Yeah, for sure. Sounds pretty "edgecasy".
Maybe this is important to know: I think vim itself fixes this issue with the fixendofline
setting. When saving the buffer, it automatically adds the last end of line character to the buffer before saving it. But when viewing the text in the editor, it does not seem to do that.
Do you want this analyzer you've installed to actually do anything? That is, if we just add an extra blank line at the end of every request when 'endofline'
is true, then the analyzer will never report an error.
Are you able to make a demo repo with the analyzer included so I can understand exactly what is happening? I assume it also is related to fileformat?
Here is the demo project: DemoProject.zip You should receive the following message in the Program.cs file:
Do you want this analyzer you've installed to actually do anything?
Yeah, I would like the analyzer to work properly.
That is, if we just add an extra blank line at the end of every request when 'endofline' is true, then the analyzer will never report an error.
I don't understand, why will it never report an error? If I think about it, endofline
is only true if there is actually an empty line at the very end. If there is no empty line, then endofline
would be false, therefore the request would not have an empty line at the end of the buffer, shouldn't therefore the analyzer return a warning?
I assume it also is related to fileformat?
I thought so too, but I was not able to find anything related to it.
I think the following might need consideration: If there is no blank line at the end, and fixeol
is enabled, when one save the file, then vim automatically adds a blank line at the end. But endofline
does NOT get set to true, even though now there is a blank line at the end (because vim automatically added it). endofline
becomes outdated, it only holds the state of the file at the opening time, not at the current time after saving.
@DasOhmoff are you able to try out PR #784 to see if it resolves the issue for your analyzer? In the test project I found it went like this:
Program.cs
and see that the analyzer complains, and 'endofline'
is off. xxd Program.cs
verifies that there is no trailing EOL on the last line.:set fixendofline
then :w
adds the final EOL which can be verified again with xxd Program.cs
, but the analyzer still complains (because vim hasn't changed 'endofline'
yet).:e
causes vim to re-read the file and now 'endofline'
is true, and the linting error goes awayYes, it works! Thank you :)
Hey :wave:, thank you for your help
I setup some c# analyzers in my project. One of which makes sure that there is always a blank line at the end the file. Ignore the following source code:
Notice the blank line at the end of the file. When I open up this file in vim, it shows as follows: Notice that vim does not show the last blank line of the file even though it is there. The analyzers seems to get confused and shows warnings in that scenario, message:
File is required to end with a single newline character
.Vim automatically hides the last line when the buffer has an empty line at the end of it, it also sets the
endofline
setting. I tried to disable this setting manually through autocmds and etc, but without success.For example this does not help:
Also this does not help, as it only saves the file correctly, but does not show it correctly in vim:
If the content of the file is correct, shouldn't there be no warning even if vim shows the file differently? How could this be solved?