Giter Club home page Giter Club logo

Comments (8)

jwortmann avatar jwortmann commented on September 23, 2024

It's also conceivable that the "format on save" option could be enabled in a per-project

This is not only conceivable, but already possible:

LSP/LSP.sublime-settings

Lines 14 to 16 in 8696a5d

// This option is also supported in syntax-specific settings and/or in the
// "settings" section of project files.
"lsp_format_on_save": false,

For this you need to use the Sublime Text project feature, i.e. save a *.sublime-project file (Project / Save Project As... from the menu) and edit the "settings" section in that project file.

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 pyproject.toml whether the project is configured for ruff formatting, and pass the result back to LSP.

from lsp.

jaraco avatar jaraco commented on September 23, 2024

It's also conceivable that the "format on save" option could be enabled in a per-project

This is not only conceivable, but already possible:

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 cpython.sublime-settings to the project just to disable the behavior. And I'd like to avoid adding it to the 100+ projects I maintain where I want the setting enabled. I'm not complaining; just sharing my experience.

from lsp.

rwols avatar rwols commented on September 23, 2024

Can't this be a server setting like "ruff.smartAutoFormat" and let lsp-ruff (the server) figure it out?

from lsp.

jaraco avatar jaraco commented on September 23, 2024

For this you need to use the Sublime Text project feature, i.e. save a *.sublime-project file (Project / Save Project As... from the menu) and edit the "settings" section in that project file.

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. subl .), the project file is not opened and the setting has no effect. One has to additionally change their workflow to open the project file when working on that project (i.e. subl *.sublime-project). That's rather inconvenient and clunky to have to rewire my brain for each affected project.

from lsp.

rchl avatar rchl commented on September 23, 2024

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.

from lsp.

jaraco avatar jaraco commented on September 23, 2024

Today I encountered another case where having a .sublime-project is unhelpful. I was editing a specific file (e.g. subl ~/.local/bin/hg) and I was making some changes to it, but ruff's formatting was actually corrupting the intended syntax (replacing ''' with """ where ''' is needed). Again I needed a way to temporarily disable the save-on-format. Is there a way to configure a hot key or action that would disable format-on-save for the current session?

from lsp.

jaraco avatar jaraco commented on September 23, 2024

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.

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.

from lsp.

jwortmann avatar jwortmann commented on September 23, 2024

Is there a way to configure a hot key or action that would disable format-on-save for the current session?

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.

from lsp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.