Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly indent output of code actions #30

Closed
wants to merge 8 commits into from
12 changes: 10 additions & 2 deletions packages/typescript/src/configs/getFormatCodeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export async function getFormatCodeSettings(

config = config ?? {};

return {
const defaultFormatOptions = ctx.typescript.module.getDefaultFormatCodeSettings();
zardoy marked this conversation as resolved.
Show resolved Hide resolved

return Object.assign({}, defaultFormatOptions, filterUndefined({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to note:

Suggested change
return Object.assign({}, defaultFormatOptions, filterUndefined({
return Object.assign({}, defaultFormatOptions, JSON.parse(JSON.stringify({

convertTabsToSpaces: options?.insertSpaces,
tabSize: options?.tabSize,
indentSize: options?.tabSize,
Expand All @@ -37,5 +39,11 @@ export async function getFormatCodeSettings(
placeOpenBraceOnNewLineForFunctions: config.placeOpenBraceOnNewLineForFunctions ?? false,
placeOpenBraceOnNewLineForControlBlocks: config.placeOpenBraceOnNewLineForControlBlocks ?? false,
semicolons: config.semicolons ?? 'ignore',
};
}));
}

function filterUndefined<T extends Record<string, any>>(obj: T) {
return Object.fromEntries(
Object.entries(obj).filter(([k, v]) => v !== undefined)
) as T;
}