diff --git a/docs/en/additionalfeatures/clangd_cdt_support.rst b/docs/en/additionalfeatures/clangd_cdt_support.rst
index c97da0cf9..4b3617e1c 100644
--- a/docs/en/additionalfeatures/clangd_cdt_support.rst
+++ b/docs/en/additionalfeatures/clangd_cdt_support.rst
@@ -9,7 +9,7 @@ In line with this enhancement, we've discontinued support for the standard CDT E
The LSP powered C/C++ editor greatly benefits ESP-IDF developers by aligning with the latest language standards and compiler versions, enhancing productivity, and improving code quality.
-You can find more details on the LSP based C/C++ Editor features `here `_.
+You can find more details on the LSP based C/C++ Editor features in the `Eclipse CDT-LSP documentation `_.
Prerequisites
-------------
@@ -45,6 +45,40 @@ However, if you are dealing with an existing project, please create a `.clangd`
CompilationDatabase: build
Remove: [-m*, -f*]
+How to fix Unknown argument error when navigating to the esp-idf components
+----------------------------------------------------------------------------------------
+
+If you are seeing the following error markers while navigating to the esp-idf components source code:
+
+.. code-block:: none
+
+ Multiple markers at this line
+ - Unknown argument: '-fno-tree-switch-conversion' [drv_unknown_argument]
+ - Unknown argument: '-fno-shrink-wrap' [drv_unknown_argument]
+ - Unknown argument: '-fstrict-volatile-bitfields' [drv_unknown_argument]
+
+Please follow the steps below to fix it:
+
+1. Download the script for `fix_compile_commands.py `_.
+
+2. Invoke the script from the project post build step. Here is example for `CMakeLists.txt `_:
+
+ .. code-block:: cmake
+
+ if(EXISTS "${CMAKE_SOURCE_DIR}/fix_compile_commands.py")
+ add_custom_target(
+ fix_clangd ALL
+ COMMAND ${CMAKE_COMMAND} -E echo "Running fix_compile_commands.py..."
+ COMMAND ${CMAKE_COMMAND} -E env python3 ${CMAKE_SOURCE_DIR}/fix_compile_commands.py
+ COMMENT "Cleaning compile_commands.json for clangd"
+ VERBATIM
+ )
+ endif()
+
+3. Now run the build, the script will remove the -m* and -f* flags from the compile_commands.json file which are unknown to clangd.
+
+4. Now, you can navigate to the esp-idf components source code without any errors.
+
Disable CDT Indexer
-------------------
diff --git a/resources/fix_compile_commands/CMakeLists.txt b/resources/fix_compile_commands/CMakeLists.txt
new file mode 100644
index 000000000..745719b80
--- /dev/null
+++ b/resources/fix_compile_commands/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 3.16)
+
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+project(blink)
+
+if(EXISTS "${CMAKE_SOURCE_DIR}/fix_compile_commands.py")
+ add_custom_target(
+ fix_clangd ALL
+ COMMAND ${CMAKE_COMMAND} -E echo "Running fix_compile_commands.py..."
+ COMMAND ${CMAKE_COMMAND} -E env python3 ${CMAKE_SOURCE_DIR}/fix_compile_commands.py
+ COMMENT "Cleaning compile_commands.json for clangd"
+ VERBATIM
+ )
+endif()
\ No newline at end of file
diff --git a/resources/fix_compile_commands/fix_compile_commands.py b/resources/fix_compile_commands/fix_compile_commands.py
new file mode 100644
index 000000000..33574b052
--- /dev/null
+++ b/resources/fix_compile_commands/fix_compile_commands.py
@@ -0,0 +1,50 @@
+# Author: Kondal Kolipaka
+#
+# Copyright 2025 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
+# Use is subject to license terms.
+
+"""
+This script is used to remove all '-m*' and '-f*' flags from the compile_commands.json file.
+"""
+
+import os
+import json
+import re
+
+def find_compile_commands_json(start_dir):
+ for root, dirs, files in os.walk(start_dir):
+ if 'compile_commands.json' in files:
+ return os.path.join(root, 'compile_commands.json')
+ return None
+
+def remove_mf_flags(compile_commands):
+ for entry in compile_commands:
+ args = entry.get("arguments") or entry.get("command", "").split()
+ filtered_args = [arg for arg in args if not re.match(r"^-([mf]).*", arg)]
+
+ if "arguments" in entry:
+ entry["arguments"] = filtered_args
+ elif "command" in entry:
+ entry["command"] = " ".join(filtered_args)
+ return compile_commands
+
+def main():
+ build_dir = os.path.join(os.path.dirname(__file__), "build")
+ cc_path = find_compile_commands_json(build_dir)
+
+ if not cc_path:
+ print("compile_commands.json not found.")
+ return
+
+ with open(cc_path, "r") as f:
+ compile_commands = json.load(f)
+
+ cleaned_commands = remove_mf_flags(compile_commands)
+
+ with open(cc_path, "w") as f:
+ json.dump(cleaned_commands, f, indent=2)
+
+ print(f"Removed all '-m*' and '-f*' flags from: {cc_path}")
+
+if __name__ == "__main__":
+ main()
\ No newline at end of file