Skip to content

Commit 79a26f5

Browse files
committed
move clangd config provider
1 parent f995a25 commit 79a26f5

4 files changed

Lines changed: 300 additions & 86 deletions

File tree

package-lock.json

Lines changed: 105 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"webpack-cli": "^5.1.4"
9797
},
9898
"dependencies": {
99+
"@clangd/vscode-clangd": "^0.0.0",
99100
"iconv-lite": "^0.5.0",
100101
"ini": "^2.0.0",
101102
"jsonc": "^2.0.0",

src/EIDEProjectExplorer.ts

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ import { jsonc } from 'jsonc';
140140
import { SimpleUIConfig, SimpleUIConfigData_input, SimpleUIConfigData_options, SimpleUIConfigData_text, SimpleUIConfigData_table, SimpleUIConfigData_boolean, SimpleUIConfigData_divider, SimpleUIConfigData_tag } from "./SimpleUIDef";
141141
import { StatusBarManager } from './StatusBarManager';
142142
import { doMigration, detectProject } from './EIDEProjectMigration';
143+
import { onRegisterClangdProvider } from './clangdConfigProvider';
143144

144145
enum TreeItemType {
145146
SOLUTION,
@@ -3408,78 +3409,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
34083409
if (this.cppToolsApi)
34093410
return; // 如果 cpptools 激活了,则禁用 clangd,防止两个冲突
34103411

3411-
prj.on('cppConfigChanged', () => {
3412-
3413-
if (!SettingManager.instance().isEnableClangdConfigGenerator()) {
3414-
GlobalEvent.log_info(`ignore update .clangd, because "EIDE.Option.EnableClangdConfigGenerator" is not set`);
3415-
return;
3416-
}
3417-
3418-
// ----------------------
3419-
// setup clangd config
3420-
// ----------------------
3421-
try {
3422-
let cfg: any = {};
3423-
const fclangd = File.fromArray([prj.getProjectRoot().path, '.clangd']);
3424-
if (fclangd.IsFile()) {
3425-
cfg = yaml.parse(fclangd.Read());
3426-
}
3427-
if (!cfg['CompileFlags']) cfg['CompileFlags'] = {};
3428-
if (!cfg['CompileFlags']['Add']) cfg['CompileFlags']['Add'] = []
3429-
if (!cfg['CompileFlags']['Remove']) cfg['CompileFlags']['Remove'] = [];
3430-
//
3431-
cfg['CompileFlags']['CompilationDatabase'] = './' + File.ToUnixPath(prj.getOutputDir());
3432-
const toolchain = prj.getToolchain();
3433-
const gccLikePath = toolchain.getGccFamilyCompilerPathForCpptools('c');
3434-
if (gccLikePath) { // clangd 仅兼容gcc的编译器
3435-
cfg['CompileFlags']['Compiler'] = gccLikePath;
3436-
let clangdCompileFlags = <string[]>(cfg['CompileFlags']['Add']);
3437-
let compilerArgs = prj.getCpptoolsConfig().cppCompilerArgs;
3438-
if (isGccFamilyToolchain(toolchain.name)) {
3439-
const tRoot = toolchain.getToolchainDir().path;
3440-
clangdCompileFlags = clangdCompileFlags.filter(p => !File.isSubPathOf(tRoot, p.substr(2)));
3441-
let li = getGccSystemSearchList(File.ToLocalPath(gccLikePath), ['-xc++'].concat(compilerArgs || []));
3442-
if (li) {
3443-
li.forEach(p => {
3444-
clangdCompileFlags.push(`-I${File.normalize(p)}`);
3445-
});
3446-
}
3447-
} else if (toolchain.name == 'LLVM_ARM') {
3448-
// nothing todo. This is llvm.
3449-
} else {
3450-
clangdCompileFlags.push(`-I${toolchain.getToolchainDir().path}/include`);
3451-
clangdCompileFlags.push(`-I${toolchain.getToolchainDir().path}/include/libcxx`);
3452-
}
3453-
// // add flags
3454-
// if (compilerArgs)
3455-
// compilerArgs.forEach(arg => clangdCompileFlags.push(arg));
3456-
// // add user includes
3457-
// prj.getCpptoolsConfig().includePath
3458-
// .forEach(path => clangdCompileFlags.push(`-I${path}`));
3459-
// // add user defines
3460-
// prj.getCpptoolsConfig().defines
3461-
// .forEach(d => clangdCompileFlags.push(`-D${d}`));
3462-
// del repeat
3463-
cfg['CompileFlags']['Add'] = ArrayDelRepetition(clangdCompileFlags);
3464-
}
3465-
// 其他不受 clangd 支持的编译器要自行设置 -I -D
3466-
else if (toolchain.name == 'AC5' || toolchain.name == 'SDCC' || toolchain.name == 'GNU_SDCC_MCS51') {
3467-
const builderOpts = prj.getBuilderOptions();
3468-
const prjConfig = prj.GetConfiguration();
3469-
const compilerFlags: string[] = cfg['CompileFlags']['Add'] || [];
3470-
toolchain.getSystemIncludeList(builderOpts)
3471-
.forEach(p => compilerFlags.push(`-I"${p}"`));
3472-
toolchain.getInternalDefines(<any>prjConfig.config.toolchainConfig, builderOpts)
3473-
.forEach(d => compilerFlags.push(`-D"${d.name}=${d.value}"`));
3474-
cfg['CompileFlags']['Add'] = ArrayDelRepetition(compilerFlags);
3475-
// 禁用所有诊断错误,因为 clangd 不支持这些编译器
3476-
cfg['Diagnostics'] = { 'Suppress': '*' }
3477-
}
3478-
fclangd.Write(yaml.stringify(cfg));
3479-
} catch (error) {
3480-
GlobalEvent.log_error(error);
3481-
}
3482-
});
3412+
await onRegisterClangdProvider(prj);
34833413

34843414
prj.forceUpdateCpptoolsConfig();
34853415
}

0 commit comments

Comments
 (0)