stevearc / conform.nvim

Lightweight yet powerful formatter plugin for Neovim
MIT License
2.55k stars 135 forks source link

unsaved files: smarter file name extension #440

Closed emmanueltouzery closed 1 month ago

emmanueltouzery commented 1 month ago

the extension used to be always the file type, be smarter now. For instance prettier wouldn't recognize a .typescript extension.

emmanueltouzery commented 1 month ago

to be clear, a reproduction would be..

create an empty unsaved file... type function test() {return 5;} set ft=typescript lua require('conform').format()

before the change, nothing would get indented, as prettier says it doesn't recognize the .typescript extension, after the change it works.

EDIT: if you agree with the approach, i can go through the supported formatters for conform, and try to add more entries to this list.

stevearc commented 1 month ago

Sure, the approach looks good! The one request would be to pull the map out of the function. I think it makes sense to just put it in its own file, something like ft_to_ext.lua.

emmanueltouzery commented 1 month ago

I updated the PR. thinking about it some more, i actually think for many file formats, the extension is not very important.. it's probably mostly important for prettier for instance, which knows how to format many file types.

but presumably it can't hurt to get the file extension right. for many file types there is nothing to do (for instance lua, sql, html, zig..). I added those that I noticed.

stevearc commented 1 month ago

LGTM thanks for the PR!