Skip to content

Duplicated formatter registrations #3285

Closed

Description

For microsoft/vscode#70314 and microsoft/vscode#41882 I have analysed formatter conflicts, e.g. multiple formatters that are registered and enabled for one language. Telemetry shows that this extension (sometimes?) registers the its own formatter two times.

Activity

  1. bobbrow commented on Mar 13, 2019

    @bobbrow
    Contributor

    Do you see multiple registrations when using multi-root workspaces? We don't do dynamic registration as your task suggests we should. We use the vscode-languageclient module and it's possible that we return that capability multiple times during static initialization since we have one language client per folder.

    Dirk Bäumer (@dbaeumer), what would you recommend we do for the multi-client case?

  2. jrieken commented on Mar 13, 2019

    @jrieken
    Author

    Do you see multiple registrations when using multi-root workspaces?

    I can't tell, I am just looking at the telemetry from here and that shows there are sometimes two formatters from this extension.

  3. dbaeumer commented on Mar 14, 2019

    @dbaeumer
    Member

    If I remember correctly the CPP extension uses different document selectors in the multi client case. Something like:

    documentSelector: [
    	{ scheme: 'file', language: 'plaintext', pattern: `${folder.uri.fsPath}/**/*` }
    ]

    Bob Brown (@bobbrow) is this still the case for the CPP extension

    Johannes Rieken (@jrieken) this is supported and shouldn't cause any problems. Right?

  4. jrieken commented on Mar 14, 2019

    @jrieken
    Author

    Yeah, that shouldn't be a problem

  5. complyue commented on Apr 15, 2019

    @complyue

    I routinely use multi-root workspaces, and can confirm that the "Format Document" action per document fails routinely, in which case I had to use "Format Document With..." and select one of the 2 or even more same-named options to trigger functional formatting, where only one of them works per specific document.

    image

    I suggest that overall, it's a problem.

  6. sean-mcmanus commented on Apr 23, 2019

    @sean-mcmanus
    Contributor

    Johannes Rieken (@jrieken) Dirk Bäumer (@dbaeumer) I don't see how we can fix this on our end. Our provideDocumentFormattingEdits implementation chooses which of the 2+ clients to handle the formatting request, but VS Code is only sending us the 1st workspace folder client, i.e. by default formatting only works on the 1st folder and you have to switch to a different C/C++ formatter in the drop down to format files in other workspace folders.

  7. dbaeumer commented on Apr 24, 2019

    @dbaeumer
    Member

    Sean McManus (@sean-mcmanus) accroding to Johannes Rieken (@jrieken) using a document selector like this

    documentSelector: [
    	{ scheme: 'file', language: 'plaintext', pattern: `${folder.uri.fsPath}/**/*` }
    ]
    

    (see also #3285 (comment)) should only send it to one format provider. Which document selectors are you using?

  8. bobbrow commented on Apr 24, 2019

    @bobbrow
    Contributor

    We can't use the pattern property in our documentSelector because we support LSP for code files outside the workspace folder (e.g. STL, 3rd party libraries). Right now we use the Middleware interface to do the filtering ourselves.

  9. jrieken commented on Apr 25, 2019

    @jrieken
    Author

    Right now we use the Middleware interface to do the filtering ourselves.

    Bob Brown (@bobbrow) That's a bad idea. The document selector drives enablement of keybindings, menus etc. Doing some extra filtering will make your extension appear as defunct. Can you fully explain why you can't use document selectors?

  10. dbaeumer commented on Apr 25, 2019

    @dbaeumer
    Member

    For files outside you could IMO have two selectors one with a pattern and one without. If more than one document selector wins then the one that is more specific (e.g. has a pattern wins). Johannes Rieken (@jrieken) is this correct?

  11. anbarrasu commented on Jun 21, 2019

    @anbarrasu

    i have the exact problem in multi root workspace. Only one of the formatter works with selected. It is really annoying. Is there any temporary solution?

  12. 5 remaining items

  13. sean-mcmanus commented on Jun 21, 2019

    @sean-mcmanus
    Contributor

    Ah, thanks for finding that -- that result was in my search, but I skipped it accidentally :).

    It looks like somehow VS Code is still trying to use the C/C++ extension to formatting -- I wasn't able to repro it, but it seems like it'd be a VS Code bug. Can you try using Format Document With and selecting the "Clang-Format" extension (or another formatter?).

  14. kisielk commented on Jun 21, 2019

    @kisielk

    It works fine if I use "Format Document With", and "clang-format" is the only option there.

  15. sean-mcmanus commented on Jun 21, 2019

    @sean-mcmanus
    Contributor

    Yeah, and then choose the "Configure Default Formatter" option in the dropdown -- my guess is your default formatter is somehow set to C++ even though we didn't register as a formatter.

  16. kisielk commented on Jun 21, 2019

    @kisielk

    Ah gotcha. That seems to work. I'll use this for now, I had previously uninstalled the clang-format extension because it was conflicting with the other formatter, but I'll use this for now while I wait for a fix for this.

  17. removed
    Visual Studio Code
    on Sep 21, 2019
  18. added
    fixed
    on Jan 22, 2020
  19. sean-mcmanus commented on Mar 4, 2020

    @sean-mcmanus
    Contributor

    Our latest Insiders release has a new multi-root implementation (which fixes this bug): https://github.com/microsoft/vscode-cpptools/releases/tag/0.27.0-insiders. Please let us know if you find any multi-root-related bugs or regressions so we can prioritize fixing those for 0.27.0.

  20. locked and limited conversation to collaborators on Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature: Multi-rootLanguage Servicebugfixed

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions