question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Do not format' setting does not work with LSP

See original GitHub issue

I’m trying to exclude my flutter repo from being auto-formatted. I added patterns for the directory as well as a single file flutter-dev/packages/flutter_tools/lib/src/commands/downgrade.dart. Yet, saving that file still formats it.

To Reproduce Steps to reproduce the behavior:

  1. Add paths to ‘Do not format’ setting
  2. Save modified file downgrade.dart inside ‘flutter-dev’ folder

Expected behavior downgrade.dart is not formatted

Versions (please complete the following information):

  • VS Code version: 1.60.2
  • Dart extension version: 3.26.0
  • Dart/Flutter SDK version: 2.6.0-12.0.pre.27, Dart version 2.15.0

settings.json

{
    "[dart]": {
        "editor.formatOnSave": true,
        "editor.rulers": [
            80
        ],
        "editor.selectionHighlight": false,
        "editor.suggest.snippetsPreventQuickSuggestions": false,
        "editor.suggestSelection": "first",
        "editor.tabCompletion": "onlySnippets",
        "editor.wordBasedSuggestions": false
    },
    "dart.doNotFormat": [
        "**/development/flutter/**",
        "**/development/flutter-dev/**",
        "**/flutter-dev/**",
        "*/downgrade.dart"
    ],
    "workbench.sideBar.location": "right",
    "workbench.colorTheme": "Material Theme Darker",
    "workbench.iconTheme": "eq-material-theme-icons-darker",
    "dart.debugExternalPackageLibraries": false,
    "dart.debugSdkLibraries": false,
    "git.autofetch": true,
    "dart.hotReloadProgress": "statusBar",
    "files.autoSave": "onFocusChange",
    "explorer.confirmDragAndDrop": false,
    "workbench.tree.indent": 16,
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
DanTupcommented, Sep 30, 2021

The doNotFormat setting is not currently supported when using the LSP integration (which is the new default). The way it was implemented was a little awkward and if it’s still being used we should probably find a better way of handling it than just mirroring what we had into LSP.

In the meantime, if there are specific projects you don’t want to format, you can use the VS Code Workspace Settings to disable format-on-save for just those specific workspaces (for example in my Flutter framework checkout, I have "editor.formatOnSave": false in the workspace settings so it never formats on save). If you use Git in VS Code, then using only format modified text may also reduce the formatting to only the lines you’re changing.

0reactions
DanTupcommented, Jan 25, 2022

Okey, closing this as as-intended for now. If there’s demand for disabling format-on-save for specific files we can try to get this via VS Code. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[LSP] Why does formatting not work for certain lsp's? - Reddit
Certain lsp's don't seem to format files using vim.lsp.buf.formatting() . For example, i've installed the html lsp using LspInstall html .
Read more >
LSP formatting doesn't always work - Neovim Discourse
Formatting requests are pretty simple, I can't imagine that we are doing anything wrong client side if you are running a single, “true”...
Read more >
emacs-lsp/lsp-mode - Gitter
I'm getting the flycheck-add-next-checker: lsp is not a valid syntax checker everytime I (require 'lsp-ui) ... your fix indeed solves it but I'm...
Read more >
VSCode OCaml Platform - Visual Studio Marketplace
Note: File formatting is performed on the OCaml-LSP side, so OCaml-LSP may be the culprit in a formatting problem. Make sure, however, that...
Read more >
Core - LSP Mode - LSP support for Emacs
Hooks to run after diagnostics are received. ... Do not use this setting unless you are familiar with lsp-mode internals and you are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found