@@ -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" ;
2626import { readParameter } from "../idfConfiguration" ;
2727import { join } from "path" ;
2828import { 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}
0 commit comments