Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I clean these error for C++20 #614

Closed
2 tasks done
Penguin-SAMA opened this issue Apr 3, 2023 · 13 comments
Closed
2 tasks done

How can I clean these error for C++20 #614

Penguin-SAMA opened this issue Apr 3, 2023 · 13 comments
Labels
clangd Clangd(lsp) related issues lsp LSP related issues upstream Upstream (neovim/plugin) issues wontfix This will not be worked on

Comments

@Penguin-SAMA
Copy link

Penguin-SAMA commented Apr 3, 2023

Version confirmation

  • Confirm

Following prerequisites

  • Confirm

Neovim version

NVIM v0.9.0-dev-1312+g908494889

Operating system/version

macos 13.3

Terminal name/version

iTerm2 3.4.19

$TERM environment variable

No response

Branch info

main (Default/Latest)

Fetch Preferences

SSH (use_ssh = true)

Affected language servers

clangd

How to reproduce the issue

编写c++20的新特性代码就会有这些报错,但是电脑自带的clangd以及lsp下载的clangd版本都是支持编译c++20的,有什么解决办法吗?

Actual behavior

image

Expected behavior

No response

Support info

image

image

Logs

[START][2023-04-04 07:09:56] LSP logging initiated
[ERROR][2023-04-04 07:09:56] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:56.410] clangd version 15.0.6 (https://github.com/llvm/llvm-project 088f33605d8a61ff519c580a71b1dd57d16a03f8)\nI[07:09:56.411] Features: mac+grpc+xpc\nI[07:09:56.411] PID: 26668\nI[07:09:56.411] Working directory: /Users/penguinsama/Desktop/test\nI[07:09:56.411] argv[0]: clangd\nI[07:09:56.411] argv[1]: --background-index\nI[07:09:56.411] argv[2]: --pch-storage=memory\nI[07:09:56.411] argv[3]: --query-driver=/opt/homebrew/opt/llvm/bin/clang++\nI[07:09:56.411] argv[4]: --clang-tidy\nI[07:09:56.411] argv[5]: --all-scopes-completion\nI[07:09:56.411] argv[6]: --completion-style=detailed\nI[07:09:56.411] argv[7]: --header-insertion-decorators\nI[07:09:56.411] argv[8]: --header-insertion=iwyu\nI[07:09:56.411] Starting LSP over stdin/stdout\n"
[ERROR][2023-04-04 07:09:56] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:56.412] <-- initialize(1)\n"
[ERROR][2023-04-04 07:09:56] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:56.431] --> reply:initialize(1) 18 ms\n"
[ERROR][2023-04-04 07:09:56] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:56.478] <-- initialized\nI[07:09:56.478] <-- textDocument/didOpen\n"
[ERROR][2023-04-04 07:09:56] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:56.481] --> textDocument/publishDiagnostics\nI[07:09:56.481] Failed to find compilation database for /Users/penguinsama/Desktop/test/test.cpp\nI[07:09:56.481] ASTWorker building file /Users/penguinsama/Desktop/test/test.cpp version 0 with command clangd fallback\n[/Users/penguinsama/Desktop/test]\n/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -resource-dir=/Users/penguinsama/.local/share/nvim/mason/packages/clangd/clangd_15.0.6/lib/clang/15.0.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -- /Users/penguinsama/Desktop/test/test.cpp\n"
[ERROR][2023-04-04 07:09:56] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:56.483] <-- textDocument/semanticTokens/full(2)\n"
[ERROR][2023-04-04 07:09:56] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:56.500] --> workspace/semanticTokens/refresh(0)\n"
[ERROR][2023-04-04 07:09:56] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:56.517] <-- $/cancelRequest\nI[07:09:56.517] <-- textDocument/semanticTokens/full(3)\n"
[ERROR][2023-04-04 07:09:56] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:56.517] <-- reply(0)\n"
[ERROR][2023-04-04 07:09:56] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:56.520] --> textDocument/publishDiagnostics\n"
[ERROR][2023-04-04 07:09:56] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:56.520] --> reply:textDocument/semanticTokens/full(2) 37 ms, error: Task was cancelled.\nI[07:09:56.520] --> reply:textDocument/semanticTokens/full(3) 2 ms\n"
[ERROR][2023-04-04 07:09:56] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:56.759] <-- textDocument/signatureHelp(4)\n"
[ERROR][2023-04-04 07:09:56] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:56.762] --> reply:textDocument/signatureHelp(4) 2 ms\n"
[ERROR][2023-04-04 07:09:57] .../vim/lsp/rpc.lua:734	"rpc"	"clangd"	"stderr"	"I[07:09:57.344] <-- textDocument/documentSymbol(5)\nI[07:09:57.345] --> reply:textDocument/documentSymbol(5) 0 ms\n"

Additional information

No response

@Penguin-SAMA Penguin-SAMA added bug Something isn't working lsp LSP related issues labels Apr 3, 2023
@Jint-lzxy
Copy link
Collaborator

See #585 (comment). Please set -std=c++20 or -std=gnu++20.

@Jint-lzxy Jint-lzxy added usage User-specific issues clangd Clangd(lsp) related issues and removed bug Something isn't working labels Apr 3, 2023
@Penguin-SAMA
Copy link
Author

See #585 (comment). Please set -std=c++20 or -std=gnu++20.

我已经设置了-std=c++20,但依旧是同一个错误提醒。
我猜测是我没有加-fmodules来提供C++20的模块支持,但我应该将这个设置添加在哪里

@Jint-lzxy
Copy link
Collaborator

CompileFlags:
  Add: [-std=c++20, -fmodules]

@Penguin-SAMA
Copy link
Author

还是不行,并且在一段时间后弹出下面这个错误
image

@Penguin-SAMA
Copy link
Author

我又做了一些尝试,似乎是mac自带的clang++与llvm的clang++有冲突
image
不知道是否是这个原因,如果是的话我要在何处修改clang的路径

@Jint-lzxy
Copy link
Collaborator

Yep, Apple Clang does not support most of the C++20 features.

"--query-driver=" .. get_binary_path_list({ "clang++", "clang", "gcc", "g++" }),

Assign --query-driver the output of echo $(brew --prefix llvm)/bin/clang++.

@Penguin-SAMA
Copy link
Author

依旧不行,我尝试了两种修改方案,不知是否是我理解有误,还是其他原因
image
打开编辑器后会显示一秒相同的错误,随后出现如下弹窗
image

@Jint-lzxy
Copy link
Collaborator

Jint-lzxy commented Apr 3, 2023

"--query-driver=<add-your-path-here>",

For example, on my Intel mac:

"--query-driver=/usr/local/opt/llvm/bin/clang++",

@Penguin-SAMA
Copy link
Author

Penguin-SAMA commented Apr 3, 2023

我尝试了你的修改方式,并重新建立了一个文件夹,依旧报错
image
我修改了问题中的lsp.log,不知道是否有用
下面是:LspInfo的输出,似乎修改的-std=c++20'以及-fumodules`都没有生效,
image

@Jint-lzxy
Copy link
Collaborator

After checking the newsletters for Clang and clangd, it turns out that their support for modules is incomplete, especially for clangd:

It would be nice if some of {C++20 modules, clang header modules} worked in clangd.

Essentially no configurations of this work today: occasionally things may happen to work but there are many reported problems and crashes. These are not just bugs that can be fixed, a design and new infrastructure is needed.

Because clang's module functionality can be enabled by setting driver flags, it is possible/easy for people to end up in this broken and unsupportable state, and wasting (their + our) time debugging it. We should consider failing early and explicitly instead.

AFAIK nobody has plans/availability to work on this soon.

I don't think this is something we can address, and after checking other IDEs (e.g., VSCode) that use open-source language server implementations (rather than builtin servers such as CLion), their support for modules is also incomplete (although some have chosen to add several tweaks to cover a small fraction of regular use cases, they are still bug prone due to limitations in the compiler's underlying implementation).

It should be noted that being able to compile is not equivalent to being able to perform static analysis - only adding a new specialized parser for the existing ASTs would solve this problem.

We suggest using such features at least after full support for C++2a, or simply disabling these error checks (not recommended as almost all related features will become unavailable).

@Jint-lzxy Jint-lzxy added wontfix This will not be worked on upstream Upstream (neovim/plugin) issues and removed usage User-specific issues labels Apr 4, 2023
@Penguin-SAMA
Copy link
Author

okay...thx:(

@Jint-lzxy Jint-lzxy closed this as not planned Won't fix, can't repro, duplicate, stale Jun 3, 2023
@yinghaoyu
Copy link

@Penguin-SAMA Are you slove this problem?

@yinghaoyu
Copy link

yinghaoyu commented Nov 8, 2023

In your project root path, create a file named .clangd, then add this:

CompileFlags:
  Add: [-std=c++20]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clangd Clangd(lsp) related issues lsp LSP related issues upstream Upstream (neovim/plugin) issues wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants