mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-10 10:41:30 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5991c70b17 |
No files matched your search
@@ -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],
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user