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

Clangd cannot complete concepts correctly #1103

Closed
24bit-xjkp opened this issue Apr 11, 2022 · 5 comments
Closed

Clangd cannot complete concepts correctly #1103

24bit-xjkp opened this issue Apr 11, 2022 · 5 comments
Assignees

Comments

@24bit-xjkp
Copy link

Clangd cannot intellisense concepts even if I set "std=c++20" in the compile_commands.json
For example,

#include <concepts>
template <typename T>
concept A = std::same_as<T, int>;

and the .vscode/compile_commands.json

[
{
 "directory": "C:\\Users\\Administrator.SKY-20190521TXE\\source\\repos",
 "arguments": ["clang.exe", "-c", "-Qunused-arguments", "-std=c++20"],
 "file": "Test.cpp"
}
]

and the clangd arguments

"clangd.arguments": [
  "--background-index",
  "--compile-commands-dir=.vscode",
  "-j=8",
  "--query-driver=clang",
  "--clang-tidy",
  "--completion-style=detailed",
  "--pch-storage=memory",
  "--inlay-hints",
  "--header-insertion=never",
  "--function-arg-placeholders"
]

clangd will not autocomplete the c++ key word "concept" and list the concepts in .
Of cause,clang++ can compile the file correctly.
And after I finished the code segment manually,clangd did not report any errors, color the words correctly except concepts.
Logs
Well,clangd is running normally.There is no error in the output windows.

System information
clangd version:14.0.0 (https://github.com/llvm/llvm-project 329fda39c507e8740978d10458451dcdb21563be)

Editor:vscode-insiders
LSP plugs:clangd0.1.15

Operating system:Windows

@HighCommander4
Copy link

Could you elaborate on the bolded part please:

clangd will not autocomplete the c++ key word "concept" and list the concepts in .

Other than auto-completion for the concept keyword itself, is there another place where completion is not working as expected? Please be specific about where the cursor is when you invoke completion, and what completion proposals you're expecting.

@HighCommander4
Copy link

Keyword completion is tracked in #89.

@24bit-xjkp
Copy link
Author

Other than auto-completion for the concept keyword itself, is there another place where completion is not working as expected? Please be specific about where the cursor is when you invoke completion, and what completion proposals you're expecting.

image
As you see,clangd cannot find the existed concepts in the files.And if I finished the sentence manually

image
clangd do not color it,since the concept will be recognized as a type template and colored green by the plug Microsoft C/C++.

@ilya-biryukov ilya-biryukov self-assigned this Apr 12, 2022
@HighCommander4
Copy link

clangd do not color it

clangd does give concept names a semantic token, but it uses a dedicated concept semantic token type rather than typeParameter. This token type is non-standard and therefore not included in most themes, but you can define a color for it by adding the following to your vscode settings:

  "editor.semanticTokenColorCustomizations": {
    "enabled": true,
    "rules": {
      "concept": {
        "foreground": "#AABBCC",
      },
    }
  }

@sam-mccall sam-mccall changed the title Clangd cannot intellisense concepts correctly Clangd cannot complete concepts correctly Apr 13, 2022
@ilya-biryukov
Copy link

ilya-biryukov commented Apr 26, 2022

I have prepared a change to fix completion and find references: https://reviews.llvm.org/D124441 (has not landed yet)
A list of things that we still need to look at:

  • rename and semantic highlighting for concepts (i.e. the code for findExplicitReferences )
  • go-to and find references for concepts at declaration specifier position Concept auto i = .... This probably involves changing the AST or RecursiveASTVisitor to expose concept as a separate node.
  • code completion should not add template argument list in some cases. In particular, non-expression positions, e.g. template<std::is_integral T> and std::is_integral auto i = ...
  • hover

hyp pushed a commit to apple/llvm-project that referenced this issue May 24, 2022
…sions

Add support for concepts and requires expression in the clang index.
Genarate USRs for concepts.

Also change how `RecursiveASTVisitor` handles return type requirement in
requires expressions. The new code unpacks the synthetic template parameter
list used for storing the actual expression. This simplifies
implementation of the indexing. No code seems to depend on the original
traversal anyway and the synthesized template parameter list is easily
accessible from inside the requires expression if needed.

Add tests in the clangd codebase.

Fixes clangd/clangd#1103.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D124441
hyp pushed a commit to apple/llvm-project that referenced this issue May 25, 2022
…sions

Add support for concepts and requires expression in the clang index.
Genarate USRs for concepts.

Also change how `RecursiveASTVisitor` handles return type requirement in
requires expressions. The new code unpacks the synthetic template parameter
list used for storing the actual expression. This simplifies
implementation of the indexing. No code seems to depend on the original
traversal anyway and the synthesized template parameter list is easily
accessible from inside the requires expression if needed.

Add tests in the clangd codebase.

Fixes clangd/clangd#1103.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D124441
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants