You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Reacted by Alex Mercier, Compl Yue, Fab!an and Robert Hargreaves
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.
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.
I suggest that overall, it's a problem.
Reacted by Kamil Kisiel, Peter Feerick, Harikrishnan Prabakaran, KernoPike and LClancey
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.
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.
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?
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?
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?
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?).
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.
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.
Activity
bobbrow commentedon Mar 13, 2019
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-languageclientmodule 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?
jrieken commentedon Mar 13, 2019
I can't tell, I am just looking at the telemetry from here and that shows there are sometimes two formatters from this extension.
dbaeumer commentedon Mar 14, 2019
If I remember correctly the CPP extension uses different document selectors in the multi client case. Something like:
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?
jrieken commentedon Mar 14, 2019
Yeah, that shouldn't be a problem
complyue commentedon Apr 15, 2019
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.
I suggest that overall, it's a problem.
sean-mcmanus commentedon Apr 23, 2019
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.
dbaeumer commentedon Apr 24, 2019
Sean McManus (@sean-mcmanus) accroding to Johannes Rieken (@jrieken) using a document selector like this
(see also #3285 (comment)) should only send it to one format provider. Which document selectors are you using?
bobbrow commentedon Apr 24, 2019
We can't use the
patternproperty in ourdocumentSelectorbecause we support LSP for code files outside the workspace folder (e.g. STL, 3rd party libraries). Right now we use theMiddlewareinterface to do the filtering ourselves.jrieken commentedon Apr 25, 2019
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?
dbaeumer commentedon Apr 25, 2019
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?
anbarrasu commentedon Jun 21, 2019
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?
5 remaining items
kisielk commentedon Jun 21, 2019
It's in source code here: https://github.com/microsoft/vscode/blob/01423e458d496588ba0d32f9afb17937a571260b/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts#L97
sean-mcmanus commentedon Jun 21, 2019
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?).
kisielk commentedon Jun 21, 2019
It works fine if I use "Format Document With", and "clang-format" is the only option there.
sean-mcmanus commentedon Jun 21, 2019
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.
kisielk commentedon Jun 21, 2019
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.
sean-mcmanus commentedon Mar 4, 2020
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.