-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try to use formatters for subfiletypes #380
Open
fenuks
wants to merge
1
commit into
sbdchd:master
Choose a base branch
from
fenuks:handle_filetypes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should enable multiple file formatters conditionally
My concern is that someone could have a filetype like
typescript.jsx
or something and the first one works but the second one failsor maybe the two formatters are incompatible and there is fighting between them
I'm curious what typical multi-file filetypes are common in the ecosystem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard to tell. Generally I would expect that if filetype is
typescript.jsx
then formatters for all filetypes should work correctly. In the same vein, it's uncertain whether all typescript formatters can handle jsx within file (or any other subfiletype that I might have invented), and yet currently NeoFormat will treat it as valid typescript file, which it might be not. I think it's generally a good assumption.I think NeoFormat already has mechanisms to fulfil most common scenarios. User can specify per filetype whether one or more formatters should be used, and it is also possible to disable formatter. If I added option to disable search for subfiletype formatters with global or buffer level variable, combination of these three variables should be flexible enough to enable or disable this feature for specific filetypes. It could be disabled by default to maintain existing behaviour.
It's worth considering if NeoFormat should make additional checks like
g:neoformat_enabled_typescript_jsx = ['prettier']
. I think that is not necessary, it's very much possible to achieve that by settingb:neoformat_enabled_filetype
in filetype plugin.I wonder whether formatters should be de-duplicated. Let's stick to
typescript.jsx
, and suppose both filetypes haveprettier
definition. Should I run only first formatter, or run prettier twice? Perhaps prettier definition forjsx
is different, e.g. different flags are passed to the command, or user has different settings forjsx
prettier formatter, let say they wish different indentation width. This scenario could also be handled with proper setting enabled formatters in filetype plugin, though.In conclusion, I think a variable to enable this behaviour should be sufficient. Disabling it by default will prevent users from stumbling upon weird combinations that wouldn't work without some manual tweaking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbdchd So, what do you think about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so I added option to enable using formatters for all subfiletypes. By default, Neoformat works as before, only first subfiletype is being considered.