Skip to content

Commit d6c086b

Browse files
committed
Address review feedback
Signed-off-by: Simon Graband <sgraband@eclipsesource.com>
1 parent 6b501bb commit d6c086b

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed

packages/editor/src/browser/language-status/editor-formatter-status-contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ export class EditorFormatterStatusContribution {
339339
// No formatter configured
340340
return {
341341
icon: FormatterIcon.Info,
342-
label: nls.localize('theia/editor/nFormatters', '{0} formatters', formatterCount),
343-
tooltip: nls.localize('theia/editor/noDefaultConfigured', 'No default formatter configured'),
342+
label: nls.localize('theia/editor/noDefaultConfiguredLabel', 'No default formatter configured'),
343+
tooltip: nls.localize('theia/editor/noDefaultConfiguredTooltip', 'No default formatter configured ({0} formatters available)', formatterCount),
344344
hasConfigureAction: true,
345345
severity: Severity.Info
346346
};

packages/editor/src/browser/language-status/editor-language-status-service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ export class EditorLanguageStatusService {
287287
const itemContainer = document.createElement('div');
288288
itemContainer.classList.add('hover-language-status');
289289

290-
const alwaysShowIcon = this.isFormatterItem(item);
291-
itemContainer.appendChild(this.createSeverityIndicator(item.severity, alwaysShowIcon));
290+
itemContainer.appendChild(this.createSeverityIndicator(item.severity));
292291

293292
const textContainer = document.createElement('div');
294293
textContainer.className = 'element';

packages/monaco/src/browser/monaco-formatter-service.ts

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
// *****************************************************************************
1616

1717
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
18-
import { Emitter, Event, PreferenceLanguageOverrideService, PreferenceScope, PreferenceService } from '@theia/core';
18+
import { Emitter, Event, PreferenceInspection, PreferenceLanguageOverrideService, PreferenceScope, PreferenceService } from '@theia/core';
19+
import { WorkspaceService } from '@theia/workspace/lib/browser';
1920
import { FormatterInfo, FormatterService, FormatterSettingScope, FormatterStatus } from '@theia/editor/lib/browser/editor-formatter-service';
2021
import { TextEditor } from '@theia/editor/lib/browser';
2122
import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
@@ -54,6 +55,9 @@ export class MonacoFormatterService implements FormatterService {
5455
@inject(PreferenceLanguageOverrideService)
5556
protected readonly preferenceSchema: PreferenceLanguageOverrideService;
5657

58+
@inject(WorkspaceService)
59+
protected readonly workspaceService: WorkspaceService;
60+
5761
protected readonly onDidChangeFormattersEmitter = new Emitter<void>();
5862
readonly onDidChangeFormatters: Event<void> = this.onDidChangeFormattersEmitter.event;
5963

@@ -125,14 +129,8 @@ export class MonacoFormatterService implements FormatterService {
125129
return undefined;
126130
}
127131

128-
let scope: FormatterSettingScope;
129-
if (inspection.workspaceFolderValue !== undefined) {
130-
scope = 'folder';
131-
} else if (inspection.workspaceValue !== undefined) {
132-
scope = 'workspace';
133-
} else {
134-
scope = 'user';
135-
}
132+
const preferenceScope = this.getConfiguredScopeFromInspection(inspection);
133+
const scope = this.preferenceToFormatterScope(preferenceScope);
136134
const formatter = formatters.find(f => f.id === configuredFormatterId);
137135

138136
return {
@@ -143,6 +141,37 @@ export class MonacoFormatterService implements FormatterService {
143141
};
144142
}
145143

144+
/**
145+
* Determines the preference scope from an inspection result.
146+
* In single-folder workspaces, folder and workspace scopes are equivalent,
147+
* so we need to check if we're in a multi-root workspace.
148+
*/
149+
protected getConfiguredScopeFromInspection<T>(inspection: PreferenceInspection<T>): PreferenceScope | undefined {
150+
if (this.workspaceService.isMultiRootWorkspaceOpened && inspection.workspaceFolderValue !== undefined) {
151+
return PreferenceScope.Folder;
152+
}
153+
if (inspection.workspaceValue !== undefined) {
154+
return PreferenceScope.Workspace;
155+
}
156+
if (inspection.globalValue !== undefined) {
157+
return PreferenceScope.User;
158+
}
159+
return undefined;
160+
}
161+
162+
protected preferenceToFormatterScope(scope: PreferenceScope | undefined): FormatterSettingScope {
163+
switch (scope) {
164+
case PreferenceScope.Folder:
165+
return 'folder';
166+
case PreferenceScope.Workspace:
167+
return 'workspace';
168+
case PreferenceScope.User:
169+
return 'user';
170+
default:
171+
return 'none';
172+
}
173+
}
174+
146175
getAvailableFormatters(editor: TextEditor): FormatterInfo[] {
147176
const model = this.getEditorModel(editor);
148177
if (!model) {
@@ -207,15 +236,6 @@ export class MonacoFormatterService implements FormatterService {
207236
return undefined;
208237
}
209238

210-
if (inspection.workspaceFolderValue !== undefined) {
211-
return PreferenceScope.Folder;
212-
}
213-
if (inspection.workspaceValue !== undefined) {
214-
return PreferenceScope.Workspace;
215-
}
216-
if (inspection.globalValue !== undefined) {
217-
return PreferenceScope.User;
218-
}
219-
return undefined;
239+
return this.getConfiguredScopeFromInspection(inspection);
220240
}
221241
}

0 commit comments

Comments
 (0)