[英]How can I ignore some warning of VSCode's clangd plugin?
I installed a clangd plugin in VSCode to develop C++.我在VSCode中安装了一个clangd插件来开发C++。
This plugin works well, but it shows some code error/waring in our project because we use a deprecated function in <zstd.h>.这个插件运行良好,但它在我们的项目中显示了一些代码错误/警告,因为我们在 <zstd.h> 中使用了已弃用的 function。
deprecated function弃用 function
How can I mask this error without changing the code?如何在不更改代码的情况下屏蔽此错误?
For example, I can ignore some warning in the VSCode's cpplint plugin by modifying.vscode/settings.json:例如,我可以通过修改 .vscode/settings.json 来忽略 VSCode 的 cpplint 插件中的一些警告:
ignore some error on cpplint plugin忽略 cpplint 插件上的一些错误
Can I do something like that to the VSCode's clangd plugin?我可以对 VSCode 的 clangd 插件做类似的事情吗? thanks~
谢谢~
I try to use clang diagnostic
, but it seems not work.我尝试使用
clang diagnostic
,但它似乎不起作用。
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-attributes"
#include <zstd.h>
#pragma clang diagnostic pop
First, note that the reason for the error is not the function being deprecated, it's a parsing error ("an attribute list cannot appear here").首先,请注意错误的原因不是 function 被弃用,而是解析错误(“属性列表不能出现在这里”)。 The note related to deprecation is just a comment that shows up in the hover, unrelated to the error diagnostic.
与弃用相关的注释只是显示在 hover 中的注释,与错误诊断无关。
If you'd like to suppress the error, you can do it using https://clangd.llvm.org/config.html#suppress .如果您想抑制错误,可以使用https://clangd.llvm.org/config.html#suppress来实现。 For example, you could create a
.clangd
file in your project root containing:例如,您可以在项目根目录中创建一个
.clangd
文件,其中包含:
Diagnostics:
Suppress: attributes_not_allowed
(Note, attributes_not_allowed
is the diagnostic code of the error from the first screenshot.) (注意,
attributes_not_allowed
是第一个截图中错误的诊断代码。)
However, suppressing the diagnostic is likely to just paper over an underlying problem that's likely related to your project's configuration.但是,抑制诊断可能只是掩盖了可能与项目配置相关的潜在问题。 A better approach would be to fix the underlying issue.
更好的方法是解决根本问题。 To do that, please review the project setup instructions and ensure your project has a
compile_commands.json
and clangd is finding it;为此,请查看项目设置说明并确保您的项目有
compile_commands.json
并且 clangd 正在找到它; if that doesn't resolve the issue, feel free to post clangd logs for further diagnosis.如果这不能解决问题,请随时发布clangd 日志以进行进一步诊断。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.