Skip to content

Commit

Permalink
Add document URI as context to getDefaultFormatter
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 eclipse-theia#13108 for an example.

Fixes eclipse-theia#13108.

Contributed on behalf of STMicroelectronics
  • Loading branch information
sgraband committed Jan 17, 2024
1 parent 0dbca07 commit 3191578
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 @@ -9,6 +9,7 @@
- [plugin] stub multiDocumentHighlightProvider proposed API [#13248](https://github.com/eclipse-theia/theia/pull/13248) - contributed on behalf of STMicroelectronics
- [terminal] rename terminal.sendText() parameter from addNewLine to shouldExecute [#13236](https://github.com/eclipse-theia/theia/pull/13236) - contributed on behalf of STMicroelectronics
- [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
- [monaco] add document URI as context to getDefaultFormatter [#13279](https://github.com/eclipse-theia/theia/pull/13279) - 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 3191578

Please sign in to comment.