-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add IntelliSense for C++20 modules importing #6302
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
Comments
Is there any way to get it somewhat working or does it not parse |
@cjwijtmans It may work with msvc mode with .ifc files for cl.exe, but it's not officialy supported yet. We process /headerUnit, /ifcSearchDir, /reference, and /stdIfcDir in compilerArgs. |
I don't know if it's only for me, but #6290 just goes to 404 error... But the compiler has no complains.... |
@Bigous It's not officially supported, but we do have code that processes various modules command lines. Can you provide the command line args you're using in compilerArgs, particularly those that are modules-related? |
Hi @sean-mcmanus , actually I'm using the CMake to build... but essentially it's It's a project to learn what C++20 brings and I really liked the module feature. I think it will save tons of time in compile. I just uploaded the project to github so you can see all easily |
|
@Bigous Good news -- it works correctly with 1.9.2 (Pre-Release), i.e. the 0.41 version error goes away. |
@Bigous However, I'm seeing what appears to be an incorrect IntelliSense error: "expression preceding parentheses of apparent call must have (pointer-to-) function type" -- I'm looking into filing a bug on that against our shared VS parser... |
@Bigous Our VS parser team is still actively developing the IntelliSense feature for modules, so incorrect IntelliSense errors like that are "expected" at this point (and possibly other IntelliSense issues). |
Hi @sean-mcmanus , thanks for the effort! |
Do you guys have some time frame when we can expect it working? I tried it a few days ago but it was incredibly slow, or not working at all. It felt like it was kinda random. Same in Visual Studio 2022. I think the modules are one of the most exiting changes in C++20 because having to maintain both source and header file is at least for me effort that could be avoided. |
@str0yd It's being actively developed. I don't know of any set timeframes, i.e. it could be a year or so. We get updates periodically. I'm guessing the VS C++ team might release a blog or something when they get IntelliSense modules support "finished". |
I set the /ifcSearchDir for .ifc files. |
Is there now support for c++20 modules for gcc/clang in addition to ifc? |
@waruqi Not yet. |
Seeing as there hasn't been many updates for a while, I would suggest a solution similar to below: For support with GCC and Clang, I would personally take the approach adding support for the C++ module mapper API used by GCC, as documented partially here in the GCC documentation (And its references) and implemented in libcody. With that support, an implementation of a smart build system (Which does not include CMake, as it currently generates module dependency files, which are incredibly inefficient) can create a service which talks to the C++ language server and tells it where modules are. This would be preferrable to requiring a build system to generate lots of files or a module dependency tree or resolution file, which is not desirable and should not be done. We could also with the ability to talk to a module mapper/build service, do things like file-specific compilers or configuration queries via more protocol extensions, as the protocol implemented by libcody can be easily extended with new commands if need be. sequenceDiagram
Language Service->>Build Tool: MODULE-SOURCE foo.bar
Build Tool->>Language Service: PATHNAME /workspace/dependencies/foo/src/bar.cpp
Language Service->>Build Tool: FILE-CONFIGURATION /workspace/dependencies/foo/src/bar.cpp
Build Tool->>Language Service: PATHNAME /tmp/configuration-7aee052f0c19772a6e436d184816ad7d
Language Service->>Build Tool: FILE-UPDATE /workspace/src/kaz.cpp <start offset>:<end offset> <start offset>:<end offset> <start offset>:<end offset>
Note right of Build Tool: The build tool rebuilds the module
Build Tool->>Language Service: ERRORS 182:"Variable 'foo' not found" 173:"Undefined reference to function 'bar'"
Language Service->>Build Tool: RUN-TESTS
Build Tool->>Language Service: BOOL TRUE
The advantage of such a system is that a build system like CMake can easily add new features without waiting for LSP support, and allowing the build tool to be aware of the language service and rebuild files in the background, which would greatly accelerate the developer experience. {
"C_Cpp.backend": "|foobarservice $(ProjectDir)", // Run foobarservice and talk the module mapper/build tool service protocol using stdin/stdout A fallback implementation for file list-style module dependency resolution files would need to implemented as a seperate service for support with current versions of CMake, and this would likely require further integration between CMake and its build system (Most of the time Makefiles or Ninja) for any real kind of effect. Some answers I want to put out there so there won't be needless useless discussion (In Q&A format): Take this not as a "we must implement this now!", but as an idea to throw out there into the void to see what people who actually work on the LSP think of this. |
There's no need to extend existing facilities. CMI/BMI files are enough for a language front end to do IntelliSense. Cpptools can't provide it, simply because the vendor of its front end hasn't finished this feature. It doesn't only concern reading a new file format, but also involves quite a few problems on C++ itself, and some parts of the front end's basic structure. Clangd has finished its support for modules a while ago, which you can definitely try. I don't feel this is the place for some long, arrogant, cocky, and error-prone (I hope it's not) lectures. But you don't have an email or something like that, so I'll have to reply here. If my reply disturbs/annoys anybody, or it's wrong (God, I hope not), please do inform me. |
Move on guys, it takes too long and waiting won't speed up anything. I am starting to suspect that this feature may even never come to vscode. |
It appears that the processing of The following gives a "cannot find module file" error:
whereas this does not:
Also rather annoyingly, it seems if I point the extension to a |
Problems with modules are not only in IDEs, but also in compilers, everything is heading towards modules being "deprecated" in the next C++ standards |
Eah, modules being poorly designed by committee and overtimed by some compiler/parser vendors. Sad that C++ rushing for new useless features leaving old structural weaknesses behind. |
Happy new 5th year without modules support! |
What C++ committee does, how the language and its ecosystem evolves looks like a controlled Jaguar into terrain these days. |
I tried to get things working with cl.exe, CMake, & Ninja on Windows. I got importing working by specifying But, if I modify my CMakeLists.txt to remove the option or update it to a nonexistent directory, then I can recompile fine, then manually switch it back to the ifc folder to get Intellisense working again. It's a really heavy workaround but it does work. In my CMakeLists.txt:
This works since by default the ifc files are produced in the root of the binary dir. Then to recompile, just change it to:
Then recompile and after the compile succeeds, change it back and recompile again, and no error squigglies on imports. I wonder why IntelliSense held the .ifc files open indefinitely (even after completing its work) and if there's any workaround to stop that behavior. Edit: I checked using Process Explorer and the thing that has the .ifc file open preventing it from updating is Edit 2: I hadn't added my .ixx files to the CXX_MODULES FILE_SET. Once I did that it fixed the odd behavior! |
@sargon2 the current implementation by EDG holds the file handle. When we get a cross-plat implementation of modules IntelliSense from them next year, this issue will be taken care of and you won't have to do anything special. For now, my CMake example uses an |
@bobbrow Thank you a ton. I was able to get it working without having to use the install target:
This seems to work okay and lets me do the copy after a normal F7 build is done. Edit: I set it up so it compares the folders, and if there's a change attempts the copy, and only if the copy fails it performs the taskkill and retries. I can post that code if anyone wants it. |
Related on Stack Overflow: How to enable proper C++ linting for modules in VS Code. |
Hi, I have a few questions regarding this issue:
Thanks for your help! |
I have a fully working C++23 devcontainer project template here using CMake, Conan, doxygen-awesom-css, Catch2 and Boost, implemented with modules and FYI for others: the LLVM clangd extension has better module support than IntelliSense - you might want to try that instead |
Adding to what @rdong8 mentioned, clangd has good module support but you need to add this line to the args passed to clangd:
(source). Also this is what I've found your
Mileage may vary here though. Hopefully we can add full module support to |
I'm very interested in improving syntax highlighting for C++20 modules in VS Code. What is the best way I could contribute? Here's a brief description of the current state of syntax highlighting in my sample project: OS: IDE: Toolchain: Behavior: Highlighting for a module file itself seems to be working nice: Importing a module in other source files results in syntax errors in the IDE (but compilation is successful). I'm building a library containing this module in the following way:
|
I need the code, post it please😄 |
In
Invoke like:
|
Thank you very much.😊 |
@gwankyun remove your spam, please. Votes/emojis exist. |
See the previous Windows/cl.exe-only issue at #6290 (UPDATE: the issue was deleted, see #8256 (comment) ).
NOTE: C++20 modules importing works for cl.exe if you set /ifcSearchDir (and possibly other modules args if necessary); however the IntelliSense support is still in active development so there are lots of known issues/bugs still.
This is dependent on IntelliSense parser changes from VS (i.e. open file Linux solutions in VS don't have module importing support for IntelliSense either).
EDIT: example here: #6302 (comment)
The text was updated successfully, but these errors were encountered: