Skip to content

Commit a10249e

Browse files
committed
add clangd format file
1 parent 241e44c commit a10249e

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/clang/index.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
getToolchainPath,
2323
isBinInPath,
2424
} from "../utils";
25-
import { pathExists, writeJSON } from "fs-extra";
25+
import { pathExists, writeJSON, writeFile } from "fs-extra";
2626
import { readParameter } from "../idfConfiguration";
2727
import { join } from "path";
2828
import { Logger } from "../logger/logger";
@@ -39,7 +39,10 @@ export async function validateEspClangExists(workspaceFolder: Uri) {
3939
return espClangdPath;
4040
}
4141

42-
export async function setClangSettings(settingsJson: any, workspaceFolder: Uri) {
42+
export async function setClangSettings(
43+
settingsJson: any,
44+
workspaceFolder: Uri
45+
) {
4346
const espClangPath = await validateEspClangExists(workspaceFolder);
4447
if (!espClangPath) {
4548
const error = new Error(
@@ -76,7 +79,9 @@ export async function configureClangSettings(workspaceFolder: Uri) {
7679
}
7780
let settingsJson: any;
7881
try {
79-
const settingsContent = await workspace.fs.readFile(Uri.file(settingsJsonPath));
82+
const settingsContent = await workspace.fs.readFile(
83+
Uri.file(settingsJsonPath)
84+
);
8085
settingsJson = parse(settingsContent.toString());
8186
} catch (error) {
8287
Logger.errorNotify(
@@ -92,4 +97,24 @@ export async function configureClangSettings(workspaceFolder: Uri) {
9297
await writeJSON(settingsJsonPath, settingsJson, {
9398
spaces: workspace.getConfiguration().get("editor.tabSize") || 2,
9499
});
100+
101+
await createClangdFile(workspaceFolder);
102+
}
103+
104+
export async function createClangdFile(workspaceFolder: Uri) {
105+
const clangdFilePath = join(workspaceFolder.fsPath, ".clangd");
106+
const clangdContent = `CompileFlags:
107+
Remove: [-f*, -m*]
108+
`;
109+
110+
try {
111+
await writeFile(clangdFilePath, clangdContent, { encoding: "utf8" });
112+
Logger.infoNotify(".clangd file created successfully.");
113+
} catch (error) {
114+
Logger.errorNotify(
115+
"Failed to create .clangd file.",
116+
error,
117+
"clang index createClangdFile"
118+
);
119+
}
95120
}

src/newProject/newProjectPanel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { IExample } from "../examples/Example";
2323
import { setCurrentSettingsInTemplate } from "./utils";
2424
import { NotificationMode, readParameter } from "../idfConfiguration";
2525
import { IdfSetup } from "../views/setup/types";
26+
import { createClangdFile } from "../clang";
2627

2728
export class NewProjectPanel {
2829
public static currentPanel: NewProjectPanel | undefined;
@@ -301,6 +302,7 @@ export class NewProjectPanel {
301302
openOcdConfigs,
302303
workspaceFolder
303304
);
305+
await createClangdFile(vscode.Uri.file(newProjectPath));
304306
await writeJSON(settingsJsonPath, settingsJson, {
305307
spaces: 2,
306308
});

0 commit comments

Comments
 (0)