Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 5991c70b17 fix(format): reformat with the Code Style indent, not the detected one
Without a per-language Tabs and Indents override, Reformat Code asked the
language server for the indent detected in the file. A file indented with 2
spaces (e.g. formatted elsewhere with Google style) then reformatted to 2
spaces and reported "already properly formatted", while a new file got 4.
Reformat now always asks for the Code Style indent (EditorConfig included);
detection only affects editing, and an indent chosen for the file in the
status bar still applies.

Fixes #2467
2026-11-10 23:37:12 +08:00
3 змінених файлів з 18 додано та 11 видалено

No files matched your search

+2 -3
Переглянути файл
@@ -167,9 +167,8 @@ export function indentExtension(indent: EffectiveIndent, format: EffectiveIndent
/**
* Indentation explicit reformat requests use: the Code Style without the file's
* detected indents (detection affects editing, reformatting uses the configured
* style, as in IDEA). Set only when the language has an explicit Tabs and Indents
* override — unset, formatting keeps the editor's indent, the status bar choice
* included.
* style, as in IDEA), or the indent chosen for the file in the status bar.
* Unset (editors outside a document model), formatting keeps the editor's indent.
*/
export const formatIndentFacet = Facet.define<EffectiveIndent | null>({
combine: (values) => [values.find((v) => v !== null) ?? null],
+10
Переглянути файл
@@ -91,6 +91,16 @@ describe("DocumentManager + slots", () => {
expect(formatOptionsOf(slot.currentState())).toEqual({ tabSize: 1, insertSpaces: false });
});
it("reformats with the Code Style indent also without a language override (#2467)", async () => {
const settings = { editor: { codeStyle: { languages: {}, detectIndents: true, editorconfig: false } } };
const { manager } = setup({ "/p/A.java": "class A {\n int x;\n}\n" }, settings);
const model = await manager.acquire("/p/A.java");
const slot = new EditorSlot(model, "t1", host);
// Editing follows the 2-space indent detected in the file; Reformat Code uses Java's 4.
expect(slot.currentState().facet(indentUnit)).toBe(" ");
expect(formatOptionsOf(slot.currentState())).toEqual({ tabSize: 4, insertSpaces: true });
});
it("detects the indents again after Reformat Code rewrote them", async () => {
const settings = {
editor: {
+6 -8
Переглянути файл
@@ -414,16 +414,14 @@ export class DocModel {
}
/**
* Indentation explicit reformat requests use (`formatIndentFacet`): with an
* explicit per-language Tabs and Indents override, the Code Style without the
* file's detected indents — the override must reach the formatter, or the
* language server keeps its own style. Without an override formatting keeps
* the editor's indent.
* Indentation explicit reformat requests use (`formatIndentFacet`): the Code Style
* (EditorConfig included) without the file's detected indents, as in IDEA, where
* detection only affects editing. Otherwise a file indented differently from the
* Code Style reformats to its own indent and other files to the Code Style's.
* An indent chosen for this file in the status bar still applies.
*/
formatIndent() {
const lang = this.info ? prefsOf(this.settings()).codeStyle.languages[this.info.id] : undefined;
if (!lang || (lang.useTab === undefined && lang.tabSize === undefined && lang.indent === undefined)) return null;
return effectiveIndent(this.settings(), this.info, this.editorconfig, null);
return this.indentOverride ?? effectiveIndent(this.settings(), this.info, this.editorconfig, null);
}
/**