dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.56k stars 1.44k forks source link

uncrustify through ALEFix treats C# file as C file. #2259

Open jasonboukheir opened 5 years ago

jasonboukheir commented 5 years ago

Information

VIM version 8.0

Operating System Ubuntu 18.04 WSL

Uncrustify Version Uncrustify-0.66.1_f

What went wrong

Using ALEFix on my .cs file with uncrustify was causing strange problems due to it being treated as a C file rather than CS file. One example is the string interpolation operator.

$"some string text"; => $ "some string text";

Uncrustify incorrectly adds a space around the $ symbol.

Reproducing the bug

  1. Use this as example.cs
  2. open example.cs in vim
  3. use :ALEFix

However, I'm pretty sure it's visible with these two commands: uncrustify --no-backup < example.cs v.s. uncrustify --no-backup example.cs

:ALEInfo

ALEInfo

jasonboukheir commented 5 years ago

Reading the uncrustify documentation, it looks like you can override the language with the -l flag. I'm not familiar with scripting vim, but I could try creating a pull request this weekend with a fix that supplies the file type when calling uncrustify.

so instead of uncrustify --no-backup < $FILENAME we'd call something like uncrustify --no-backup -l $LANGUAGE_TYPE < $FILENAME

RyanSquared commented 5 years ago

You should be able to fix it by using:

autocmd FileType cs let g:ale_c_uncrustify_options = '-l CS'
RyanSquared commented 5 years ago

Unfortunately I'm not sure of a good solution to do this for every language without a switch for each potential filetype, which could change if uncrustable begins supporting more things. If there's a "file name" option (like --stdin-filename or something similar) that would be very helpful.

jasonboukheir commented 5 years ago

Lol Perfect timing. I had just found those options. Thanks so much!

Closing this issue.

RyanSquared commented 5 years ago

Reopening for the time being until we get an automated solution, through flag or otherwise.

jasonboukheir commented 5 years ago

uncrustify -f example.cs treats the filetype correctly with CS and outputs to stdout. I'll try it with other filetypes.

RyanSquared commented 5 years ago

Does that treat it like the stdin filename but still read from the stdin? If so, that should work for most filetypes.

jasonboukheir commented 5 years ago

I'm not sure I understand the question, but unfortunately, if the architecture is forcing us to feed it with < filename then it looks like it won't work without roundabout hacks.

if we can pass in just the filename to the executable, instead of using stdin on the contents of the file, the -f option would work.

RyanSquared commented 5 years ago

We can't use a filename or that would mean ALE would only work when the file is saved. I can't find any documentation on this, so I'm not sure what to do at this point.

w0rp commented 5 years ago

I'm okay with just adding some code to automatically determine the filetype flag to send to uncrustify. It supports 8 languages, so it wouldn't be too difficult.

w0rp commented 5 years ago

See the prettier fixer for somewhat similar code.