Skip to content

Commit

Permalink
Add document URI as context to getDefaultFormatter (#13280)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sgraband authored Jan 25, 2024
1 parent 725a7d2 commit c15aa75
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<a name="breaking_changes_not_yet_released">[Breaking Changes:](#breaking_changes_not_yet_released)</a>

Expand Down
6 changes: 3 additions & 3 deletions packages/monaco/src/browser/monaco-formatting-conflicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(name);
return this.preferenceService.get<string>(name, undefined, resourceURI);
}

private async selectFormatter<T extends FormattingEditProvider>(
Expand All @@ -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);
Expand Down

0 comments on commit c15aa75

Please sign in to comment.