From d91ba50ad69316d7504b6736d50265553328efe2 Mon Sep 17 00:00:00 2001 From: Gyan Date: Mon, 4 May 2026 06:43:06 +0800 Subject: [PATCH 1/9] =?UTF-8?q?`.clangd`=20=E7=94=9F=E6=88=90=EF=BC=9A?= =?UTF-8?q?=E6=94=B9=E7=94=A8=20`-isystem`=20=E4=BB=A3=E6=9B=BF=20`-I`=20?= =?UTF-8?q?=E5=BC=95=E5=85=A5=E7=B3=BB=E7=BB=9F=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clangdConfigProvider.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/clangdConfigProvider.ts b/src/clangdConfigProvider.ts index 62a37745..3005934f 100644 --- a/src/clangdConfigProvider.ts +++ b/src/clangdConfigProvider.ts @@ -144,20 +144,31 @@ export async function onRegisterClangdProvider(prj: AbstractProject) { cfg['CompileFlags']['Compiler'] = gccLikePath; let clangdCompileFlags = (cfg['CompileFlags']['Add']); let compilerArgs = prj.getCpptoolsConfig().cppCompilerArgs; + // 用 -isystem 引入系统头文件,避免 clangd 对系统头进行诊断; + // 兼容历史遗留的 -I 入口,便于切换工具链时清理旧路径。 + const stripIncludePrefix = (s: string): string | undefined => { + if (s.startsWith('-isystem')) return s.substring('-isystem'.length); + if (s.startsWith('-I')) return s.substring(2); + return undefined; + }; if (isGccFamilyToolchain(toolchain.name)) { const tRoot = toolchain.getToolchainDir().path; - clangdCompileFlags = clangdCompileFlags.filter(p => !File.isSubPathOf(tRoot, p.substr(2))); + clangdCompileFlags = clangdCompileFlags.filter(p => { + const incPath = stripIncludePrefix(p); + if (incPath === undefined) return true; + return !File.isSubPathOf(tRoot, incPath); + }); let li = getGccSystemSearchList(File.ToLocalPath(gccLikePath), ['-xc++'].concat(compilerArgs || [])); if (li) { li.forEach(p => { - clangdCompileFlags.push(`-I${File.normalize(p)}`); + clangdCompileFlags.push(`-isystem${File.normalize(p)}`); }); } } else if (toolchain.name == 'LLVM_ARM') { // nothing todo. This is llvm. } else { - clangdCompileFlags.push(`-I${toolchain.getToolchainDir().path}/include`); - clangdCompileFlags.push(`-I${toolchain.getToolchainDir().path}/include/libcxx`); + clangdCompileFlags.push(`-isystem${toolchain.getToolchainDir().path}/include`); + clangdCompileFlags.push(`-isystem${toolchain.getToolchainDir().path}/include/libcxx`); } // // add flags // if (compilerArgs) @@ -177,7 +188,7 @@ export async function onRegisterClangdProvider(prj: AbstractProject) { const prjConfig = prj.GetConfiguration(); const compilerFlags: string[] = cfg['CompileFlags']['Add'] || []; toolchain.getSystemIncludeList(builderOpts) - .forEach(p => compilerFlags.push(`-I"${p}"`)); + .forEach(p => compilerFlags.push(`-isystem"${p}"`)); toolchain.getInternalDefines(prjConfig.config.toolchainConfig, builderOpts) .forEach(d => compilerFlags.push(`-D"${d.name}=${d.value}"`)); cfg['CompileFlags']['Add'] = ArrayDelRepetition(compilerFlags); From e3a8af109ab3a4bf1460547d44359c1407a10be2 Mon Sep 17 00:00:00 2001 From: Gyan Date: Mon, 4 May 2026 20:55:11 +0800 Subject: [PATCH 2/9] =?UTF-8?q?AC5=20/=20SDCC=20=E7=AD=89=20clangd=20?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E5=B7=AE=E7=9A=84=E5=B7=A5=E5=85=B7=E9=93=BE?= =?UTF-8?q?=20=E6=94=B9=E5=9B=9E=20`-I`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clangdConfigProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clangdConfigProvider.ts b/src/clangdConfigProvider.ts index 3005934f..e4cb883e 100644 --- a/src/clangdConfigProvider.ts +++ b/src/clangdConfigProvider.ts @@ -188,7 +188,7 @@ export async function onRegisterClangdProvider(prj: AbstractProject) { const prjConfig = prj.GetConfiguration(); const compilerFlags: string[] = cfg['CompileFlags']['Add'] || []; toolchain.getSystemIncludeList(builderOpts) - .forEach(p => compilerFlags.push(`-isystem"${p}"`)); + .forEach(p => compilerFlags.push(`-I"${p}"`)); toolchain.getInternalDefines(prjConfig.config.toolchainConfig, builderOpts) .forEach(d => compilerFlags.push(`-D"${d.name}=${d.value}"`)); cfg['CompileFlags']['Add'] = ArrayDelRepetition(compilerFlags); From ffcbb58cae4bde7d0c5188685bae2be46587533e Mon Sep 17 00:00:00 2001 From: Gyan Date: Tue, 5 May 2026 04:09:04 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clangdConfigProvider.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/clangdConfigProvider.ts b/src/clangdConfigProvider.ts index e4cb883e..b750c21a 100644 --- a/src/clangdConfigProvider.ts +++ b/src/clangdConfigProvider.ts @@ -153,16 +153,18 @@ export async function onRegisterClangdProvider(prj: AbstractProject) { }; if (isGccFamilyToolchain(toolchain.name)) { const tRoot = toolchain.getToolchainDir().path; + // 移除旧的系统头路径 clangdCompileFlags = clangdCompileFlags.filter(p => { const incPath = stripIncludePrefix(p); + // 保留非 include 路径相关的 flag if (incPath === undefined) return true; + // 移除工具链目录下的 include 路径(系统头路径) return !File.isSubPathOf(tRoot, incPath); }); let li = getGccSystemSearchList(File.ToLocalPath(gccLikePath), ['-xc++'].concat(compilerArgs || [])); if (li) { - li.forEach(p => { - clangdCompileFlags.push(`-isystem${File.normalize(p)}`); - }); + // 重新添加系统头路径。使用 -isystem 前缀,避免 clangd 对系统头进行诊断 + li.forEach(p => { clangdCompileFlags.push(`-isystem${File.normalize(p)}`); }); } } else if (toolchain.name == 'LLVM_ARM') { // nothing todo. This is llvm. From 2db093967664de820783d08d4a8892d489b57edc Mon Sep 17 00:00:00 2001 From: Gyan Date: Tue, 5 May 2026 04:15:44 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E7=BB=9F=E4=B8=80=20.clangd=20=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=A4=B4=E8=B7=AF=E5=BE=84=20flag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clangdConfigProvider.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/clangdConfigProvider.ts b/src/clangdConfigProvider.ts index b750c21a..5c605e4f 100644 --- a/src/clangdConfigProvider.ts +++ b/src/clangdConfigProvider.ts @@ -146,8 +146,9 @@ export async function onRegisterClangdProvider(prj: AbstractProject) { let compilerArgs = prj.getCpptoolsConfig().cppCompilerArgs; // 用 -isystem 引入系统头文件,避免 clangd 对系统头进行诊断; // 兼容历史遗留的 -I 入口,便于切换工具链时清理旧路径。 + const sysIncPrefix = '-isystem'; const stripIncludePrefix = (s: string): string | undefined => { - if (s.startsWith('-isystem')) return s.substring('-isystem'.length); + if (s.startsWith(sysIncPrefix)) return s.substring(sysIncPrefix.length); if (s.startsWith('-I')) return s.substring(2); return undefined; }; @@ -164,13 +165,13 @@ export async function onRegisterClangdProvider(prj: AbstractProject) { let li = getGccSystemSearchList(File.ToLocalPath(gccLikePath), ['-xc++'].concat(compilerArgs || [])); if (li) { // 重新添加系统头路径。使用 -isystem 前缀,避免 clangd 对系统头进行诊断 - li.forEach(p => { clangdCompileFlags.push(`-isystem${File.normalize(p)}`); }); + li.forEach(p => { clangdCompileFlags.push(sysIncPrefix + File.normalize(p)); }); } } else if (toolchain.name == 'LLVM_ARM') { // nothing todo. This is llvm. } else { - clangdCompileFlags.push(`-isystem${toolchain.getToolchainDir().path}/include`); - clangdCompileFlags.push(`-isystem${toolchain.getToolchainDir().path}/include/libcxx`); + clangdCompileFlags.push(`${sysIncPrefix}${toolchain.getToolchainDir().path}/include`); + clangdCompileFlags.push(`${sysIncPrefix}${toolchain.getToolchainDir().path}/include/libcxx`); } // // add flags // if (compilerArgs) From 27013faa7b51a2b59c6d81044f0830af9cce5d4d Mon Sep 17 00:00:00 2001 From: Gyan Date: Tue, 5 May 2026 04:33:06 +0800 Subject: [PATCH 5/9] =?UTF-8?q?.clangd=20=E9=85=8D=E7=BD=AE=EF=BC=9AAC5=20?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=BD=BF=E7=94=A8=20-isystem=20=E5=BC=95?= =?UTF-8?q?=E5=85=A5=E7=B3=BB=E7=BB=9F=E5=A4=B4=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clangdConfigProvider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clangdConfigProvider.ts b/src/clangdConfigProvider.ts index 5c605e4f..e577b328 100644 --- a/src/clangdConfigProvider.ts +++ b/src/clangdConfigProvider.ts @@ -140,13 +140,13 @@ export async function onRegisterClangdProvider(prj: AbstractProject) { cfg['CompileFlags']['CompilationDatabase'] = './' + File.ToUnixPath(prj.getOutputDir()); const toolchain = prj.getToolchain(); const gccLikePath = toolchain.getGccFamilyCompilerPathForCpptools('c'); + const sysIncPrefix = '-isystem'; // 用 -isystem 引入系统头文件 if (gccLikePath) { // clangd 仅兼容gcc的编译器 cfg['CompileFlags']['Compiler'] = gccLikePath; let clangdCompileFlags = (cfg['CompileFlags']['Add']); let compilerArgs = prj.getCpptoolsConfig().cppCompilerArgs; // 用 -isystem 引入系统头文件,避免 clangd 对系统头进行诊断; // 兼容历史遗留的 -I 入口,便于切换工具链时清理旧路径。 - const sysIncPrefix = '-isystem'; const stripIncludePrefix = (s: string): string | undefined => { if (s.startsWith(sysIncPrefix)) return s.substring(sysIncPrefix.length); if (s.startsWith('-I')) return s.substring(2); @@ -191,7 +191,7 @@ export async function onRegisterClangdProvider(prj: AbstractProject) { const prjConfig = prj.GetConfiguration(); const compilerFlags: string[] = cfg['CompileFlags']['Add'] || []; toolchain.getSystemIncludeList(builderOpts) - .forEach(p => compilerFlags.push(`-I"${p}"`)); + .forEach(p => compilerFlags.push(`${sysIncPrefix}"${p}"`)); toolchain.getInternalDefines(prjConfig.config.toolchainConfig, builderOpts) .forEach(d => compilerFlags.push(`-D"${d.name}=${d.value}"`)); cfg['CompileFlags']['Add'] = ArrayDelRepetition(compilerFlags); From e4bf1cf8b1f759244f61f55175e4a8a0688432ee Mon Sep 17 00:00:00 2001 From: Gyan Date: Tue, 5 May 2026 05:36:17 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20clangd=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=AD=E7=9A=84=20AC5=20/=20SDCC=20/=20GNU=5FSDCC?= =?UTF-8?q?=5FMCS51=20=E7=B3=BB=E7=BB=9F=E5=A4=B4=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E6=A0=BC=E5=BC=8F=EF=BC=8C=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E7=9A=84=E5=BC=95=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clangdConfigProvider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clangdConfigProvider.ts b/src/clangdConfigProvider.ts index e577b328..6182ae59 100644 --- a/src/clangdConfigProvider.ts +++ b/src/clangdConfigProvider.ts @@ -191,9 +191,9 @@ export async function onRegisterClangdProvider(prj: AbstractProject) { const prjConfig = prj.GetConfiguration(); const compilerFlags: string[] = cfg['CompileFlags']['Add'] || []; toolchain.getSystemIncludeList(builderOpts) - .forEach(p => compilerFlags.push(`${sysIncPrefix}"${p}"`)); + .forEach(p => compilerFlags.push(sysIncPrefix + p)); toolchain.getInternalDefines(prjConfig.config.toolchainConfig, builderOpts) - .forEach(d => compilerFlags.push(`-D"${d.name}=${d.value}"`)); + .forEach(d => compilerFlags.push(`-D${d.name}=${d.value}`)); cfg['CompileFlags']['Add'] = ArrayDelRepetition(compilerFlags); // 禁用所有诊断错误,因为 clangd 不支持这些编译器 cfg['Diagnostics'] = { 'Suppress': '*' } From 3f4523f0c4643344af3a75ade46ab1b6d354e2f0 Mon Sep 17 00:00:00 2001 From: Gyan Date: Tue, 5 May 2026 06:06:23 +0800 Subject: [PATCH 7/9] =?UTF-8?q?migrate:=20=E5=88=A0=E9=99=A4=20AC5=20/=20S?= =?UTF-8?q?DCC=20=E5=B7=A5=E5=85=B7=E9=93=BE=E7=9A=84=20`.clangd`=20?= =?UTF-8?q?=E4=B8=AD=EF=BC=8C=E6=97=A7=E7=89=88=E6=9C=AC=20EIDE=20?= =?UTF-8?q?=E5=BC=95=E5=85=A5=E7=9A=84=E9=94=99=E8=AF=AF=E5=9C=B0=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E4=BA=86=E5=BC=95=E5=8F=B7=E7=9A=84=20flag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clangdConfigProvider.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/clangdConfigProvider.ts b/src/clangdConfigProvider.ts index 6182ae59..3c800320 100644 --- a/src/clangdConfigProvider.ts +++ b/src/clangdConfigProvider.ts @@ -189,7 +189,18 @@ export async function onRegisterClangdProvider(prj: AbstractProject) { else if (toolchain.name == 'AC5' || toolchain.name == 'SDCC' || toolchain.name == 'GNU_SDCC_MCS51') { const builderOpts = prj.getBuilderOptions(); const prjConfig = prj.GetConfiguration(); - const compilerFlags: string[] = cfg['CompileFlags']['Add'] || []; + let compilerFlags: string[] = cfg['CompileFlags']['Add'] ?? []; + // 删除旧版本错误使用了引号的 flag + const flagPrefixesToRemove = ['-I"', '-D"']; + compilerFlags = compilerFlags.filter(f => { + for (const prefix of flagPrefixesToRemove) { + if (f.startsWith(prefix) && f.endsWith('"')) { + return false; + } + } + return true; + }); + // 重新添加系统头路径和预定义宏 toolchain.getSystemIncludeList(builderOpts) .forEach(p => compilerFlags.push(sysIncPrefix + p)); toolchain.getInternalDefines(prjConfig.config.toolchainConfig, builderOpts) From 7fb70323691c455a90cd3fbf43507d48a73c3f2b Mon Sep 17 00:00:00 2001 From: Gyan Date: Tue, 5 May 2026 06:57:09 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20clangd=20=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E9=85=8D=E7=BD=AE=E4=B8=AD=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E9=99=90=E5=88=B6=E5=92=8C=20AC5=20=E4=B8=93?= =?UTF-8?q?=E6=9C=89=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clangdConfigProvider.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/clangdConfigProvider.ts b/src/clangdConfigProvider.ts index 3c800320..3169f55e 100644 --- a/src/clangdConfigProvider.ts +++ b/src/clangdConfigProvider.ts @@ -205,7 +205,30 @@ export async function onRegisterClangdProvider(prj: AbstractProject) { .forEach(p => compilerFlags.push(sysIncPrefix + p)); toolchain.getInternalDefines(prjConfig.config.toolchainConfig, builderOpts) .forEach(d => compilerFlags.push(`-D${d.name}=${d.value}`)); + // 移除错误数量限制,避免 fatal_too_many_errors 错误 + compilerFlags.push("-ferror-limit=0"); cfg['CompileFlags']['Add'] = ArrayDelRepetition(compilerFlags); + // 移除 AC5 的专有参数,避免 clang 报错 + let removeFlags = cfg['CompileFlags']['Remove'] ?? []; + removeFlags = removeFlags.concat([ + "--apcs=interwork", + "--cpu", + "--li", + "--c99", + "--split_sections", + "--diag_suppress=*", + "--no_depend_system_headers", + "--depend", + "--strict", + "--enum_is_int", + "--gnu", + "--apcs=*", + "--signed_chars", + "--split_ldm", + "--execute_only", + "-Otime", + ]); + cfg['CompileFlags']['Remove'] = ArrayDelRepetition(removeFlags); // 禁用所有诊断错误,因为 clangd 不支持这些编译器 cfg['Diagnostics'] = { 'Suppress': '*' } } From 88d5e5027d14693e738ea650e216893336174ada Mon Sep 17 00:00:00 2001 From: Gyan Date: Tue, 5 May 2026 07:04:26 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20clangd=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=AD=E5=A4=9A=E4=BD=99=E7=9A=84=20AC5=20=E4=B8=93?= =?UTF-8?q?=E6=9C=89=E5=8F=82=E6=95=B0=20"--apcs=3Dinterwork"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clangdConfigProvider.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/clangdConfigProvider.ts b/src/clangdConfigProvider.ts index 3169f55e..90ccf44d 100644 --- a/src/clangdConfigProvider.ts +++ b/src/clangdConfigProvider.ts @@ -211,7 +211,6 @@ export async function onRegisterClangdProvider(prj: AbstractProject) { // 移除 AC5 的专有参数,避免 clang 报错 let removeFlags = cfg['CompileFlags']['Remove'] ?? []; removeFlags = removeFlags.concat([ - "--apcs=interwork", "--cpu", "--li", "--c99",