-
Notifications
You must be signed in to change notification settings - Fork 184
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
Feature: Only format when project configured for formatting #2412
Comments
This is not only conceivable, but already possible: Lines 14 to 16 in 8696a5d
For this you need to use the Sublime Text project feature, i.e. save a A "smart" option for this setting might be a bit tricky to implement (but not impossible); it would first need to signalize that to the LSP-* helper plugin if applicable, which would then need to implement the logic to read from |
Indeed, I've tested and I'm able to disable "format on save" in projects where I don't want it or enable it in projects where I do. I don't believe this solution is the right one, though, because it requires additional per-project configuration that's specific to my development workflow (using Sublime Text) and configuration (LSP plus lsp-ruff plus "format on save" enabled by default). As an example, I'm guessing the Python project wouldn't want me adding a |
Can't this be a server setting like "ruff.smartAutoFormat" and let lsp-ruff (the server) figure it out? |
I've found it's not sufficient to create such a project file. It does work for that current session, but if one exits SublimeText and then re-opens it on that folder (e.g. |
ctrl+shift+p is the default shortcut that opens a project selector that shows the list of projects that were saved. This is how you are really supposed to interact with the projects. |
Today I encountered another case where having a .sublime-project is unhelpful. I was editing a specific file (e.g. |
This didn't work for me, but I think on Mac, the hotkey is Ctrl+Cmd+p. I do get a project switcher there. This approach still doesn't suit the workflow very well as it requires having an open session and replacing the current session with a different one... and even I'm already working on that project and I realize the settings aren't loaded, using the quick project switcher causes the current tabs to be closed. It's the wrong workaround for the problem I'm facing. |
Currently there is no dynamic toggle for that setting, but you could create a custom command to toggle it globally (and add a key binding for it): import sublime
import sublime_plugin
class ToggleLspSettingCommand(sublime_plugin.ApplicationCommand):
def run(self, setting_name='lsp_format_on_paste'):
lsp_settings = sublime.load_settings('LSP.sublime-settings')
value = lsp_settings.get(setting_name)
if not isinstance(value, bool):
raise ValueError(setting_name + 'is not boolean')
lsp_settings.set(setting_name, not value)
sublime.save_settings('LSP.sublime-settings') If/when #2448 gets merged, it should work without the server(s) being restarted. |
Is your feature request related to a problem? Please describe.
I've recently switched from
python-black
tolsp-ruff
for formatting my Python code in Sublime Text.I'd previously worked with the maintainers of
python-black
to enable "format on save" but only when the project appears to be configured to use black. They called this the "smart" setting for "format on save". See the Settings section of the docs.Without this setting, if I configure "format on save" and then pick up a project that hasn't been configured for ruff, it will get formatted on save, causing unwanted changes.
Describe the solution you'd like
LSP to offer a similar feature - to only format a file if it's present in a project configured for ruff formatting (or whatever formatter is present).
Describe alternatives you've considered
A less convenient feature would be a way to suppress formatting for a given file (ephemerally).
It's also conceivable that the "format on save" option could be enabled in a per-project and per-editor configuration file, but that would be tedious and noisy.
The text was updated successfully, but these errors were encountered: