From c15aa75f8771dc8313400f3b1bb01bfd4d7b9dd6 Mon Sep 17 00:00:00 2001 From: Simon Graband Date: Thu, 25 Jan 2024 09:50:05 +0100 Subject: [PATCH] Add document URI as context to getDefaultFormatter (#13280) This way the default formatter will be resolved correctly in multi-root workspaces. Beforehand only the workspace settings where taken into account. Now the behavior is as expected, see #13108 for an example. Fixes #13108. Contributed on behalf of STMicroelectronics --- CHANGELOG.md | 1 + packages/monaco/src/browser/monaco-formatting-conflicts.ts | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89c38ab053d4f..919029e59c84e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - [terminal] update terminalQuickFixProvider proposed API according to vscode 1.85 version [#13240](https://github.com/eclipse-theia/theia/pull/13240) - contributed on behalf of STMicroelectronics - [core] added preference 'workbench.tree.indent' to control the indentation in the tree widget [#13179](https://github.com/eclipse-theia/theia/pull/13179) - contributed on behalf of STMicroelectronics - [remote] upport specifying the port of a remote SSH connection [#13296](https://github.com/eclipse-theia/theia/pull/13296) - contributed on behalf of STMicroelectronics +- [monaco] add document URI as context to getDefaultFormatter [#13280](https://github.com/eclipse-theia/theia/pull/13280) - contributed on behalf of STMicroelectronics [Breaking Changes:](#breaking_changes_not_yet_released) diff --git a/packages/monaco/src/browser/monaco-formatting-conflicts.ts b/packages/monaco/src/browser/monaco-formatting-conflicts.ts index 361db7e5350cd..b3eb98faf823f 100644 --- a/packages/monaco/src/browser/monaco-formatting-conflicts.ts +++ b/packages/monaco/src/browser/monaco-formatting-conflicts.ts @@ -59,13 +59,13 @@ export class MonacoFormattingConflictsContribution implements FrontendApplicatio await this.preferenceService.set(name, formatter); } - private getDefaultFormatter(language: string): string | undefined { + private getDefaultFormatter(language: string, resourceURI: string): string | undefined { const name = this.preferenceSchema.overridePreferenceName({ preferenceName: PREFERENCE_NAME, overrideIdentifier: language }); - return this.preferenceService.get(name); + return this.preferenceService.get(name, undefined, resourceURI); } private async selectFormatter( @@ -85,7 +85,7 @@ export class MonacoFormattingConflictsContribution implements FrontendApplicatio } const languageId = currentEditor.editor.document.languageId; - const defaultFormatterId = this.getDefaultFormatter(languageId); + const defaultFormatterId = this.getDefaultFormatter(languageId, document.uri.toString()); if (defaultFormatterId) { const formatter = formatters.find(f => f.extensionId && f.extensionId.value === defaultFormatterId);