vscode-cpptools
vscode-cpptools copied to clipboard
Add IntelliSense for C++20 modules importing
See the previous Windows/cl.exe-only issue at https://github.com/microsoft/vscode-cpptools/issues/6290 (UPDATE: the issue was deleted, see https://github.com/microsoft/vscode-cpptools/issues/8256#issuecomment-941809096 ).
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: https://github.com/microsoft/vscode-cpptools/issues/6302#issuecomment-1930791901
Is there any way to get it somewhat working or does it not parse .ifc
files at all?
@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... The intellisense is not working for imports at all.
The definition:
And whe we use it:
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 /std:c++latest /experimental:module /EHsc /MD
.
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
- You currently need to change it to something like
target_compile_options(cpp20 PRIVATE "/experimental:module" "/ifcSearchDir\"C:\\pathTo\\build\""
), i.e. see https://devblogs.microsoft.com/cppblog/standard-c20-modules-support-with-msvc-in-visual-studio-2019-version-16-8/ . - But I'm seeing error "IFC file "C:\pathTo\build\Utils.Numbers.ifc" has unsupported version 0.41", so I'm looking into that...
@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! If I can help with anything, you can count on me.
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. For my module "Math" the line: import Math; Got error "Can't find module file ***/Math.edgm" No idea what is .edgm file. And it is not generated in my project directory. But "Go To Definition" works for names exported from module.
Is there now support for c++20 modules for gcc/clang in addition to ifc?
@waruqi Not yet.
Ifc file version 0.42 is not supported
@RimuruChan It's fixed in our pending 1.13.1 update -- maybe for Tuesday next week.
@RimuruChan It's available now in 1.13.1 (the IFC file version 0.42): https://github.com/microsoft/vscode-cpptools/releases/tag/v1.13.1
Hi @sean-mcmanus , I switched to the pré-release version, but it still complains when importing a mudule, but now about a edgm
file:
@Bigous, there is something suspicious about that error message. How are you specifying the path to the IFC files? It looks like there is an extra set of quotes in the path.
Is there no way to write modules in a .cpp file? why should cpp code be written in a file named ixx wtf does that even mean
Right now if I do the hacks needed to compile modules in .cpp files I still can't use intellisense
@Kirchesch I don't think it needs to be named with the .ixx extension, see https://learn.microsoft.com/en-us/cpp/cpp/tutorial-named-modules-cpp?view=msvc-170 : "you can treat a source file with any extension as a module interface file. Set the Compile As property in the Advanced tab for the source file's properties page to Compile As Module (/interface).". Also, "Module unit implementation files don't end with an .ixx extension. They're normal .cpp files.".
We haven't validated if C++20 modules is usable in VS Code yet -- it's still being developed on the VS side and there might be more work we need to do on our side.
@Bigous, there is something suspicious about that error message. How are you specifying the path to the IFC files? It looks like there is an extra set of quotes in the path.
Hy @bob, it's in my CMakeLists.txt
file:
target_compile_options(cpp20
PRIVATE
/experimental:module
/ifcSearchDir"R:\\Richard\\src\\playground\\c++\\C++20\\build\\cpp20.dir\\Debug"
)
And it's correctly finding the .ifc
files. There is no .edgm
file beeing generated in this directory and it compiles and runs normally. The error message is only in VSCode.
@sean-mcmanus Tks sean. Can I help with something?
@Kirchesch I don't think it needs to be named with the .ixx extension, see https://learn.microsoft.com/en-us/cpp/cpp/tutorial-named-modules-cpp?view=msvc-170 : "you can treat a source file with any extension as a module interface file. Set the Compile As property in the Advanced tab for the source file's properties page to Compile As Module (/interface).". Also, "Module unit implementation files don't end with an .ixx extension. They're normal .cpp files.".
We haven't validated if C++20 modules is usable in VS Code yet -- it's still being developed on the VS side and there might be more work we need to do on our side.
Yes you are right, but I can't declare a module in a .cpp file in visual studio the compiler doesn't allow, unless I specifically tell the compiler that the specific file should be compiled as a module (msvc ofc), and when I do that neither Visual Studio nor vs code can give me intellisense, I was worried Microsoft was trying to force standardization of .ixx as module files..
Btw I get perfectly fine intellisense from vs and vs code when using ixx files, I don't even need to specify any "experimental" feature on cmake or anything, I just treat as a normal library and it works fine. ( I have to delete the output with certain changes but mostly fine )
The problem is i cant specify ifc dir in cmake. This is non standard and changes between compilers generators os etc. Ninja generator should take care of this not cmake.
@Bigous If there is specific modules issue that works correctly in VS 2022 that we're not handling correctly we can look into fixing that.
@Kirchesch @cjwijtmans Can you file an issue on VS (https://developercommunity.visualstudio.com) ? I didn't see an existing issue.
@Kirchesch @cjwijtmans Can you file an issue on VS (https://developercommunity.visualstudio.com) ? I didn't see an existing issue.
There really isnt an issue here because ifc search dir already seems to be correctly defined by the generator and i dont need to do anything, just got confused because someone in the thread said to defined it manually.
In my c++ modules in vscode test project i have a different issue though. When i add a subproject as INTERFACE or OBJECT library that is a dependency the compiler gets confused. When its an INTERFACE project it cant find the module, when its an OBJECT library the module interface seems to exist twice. In both methods there is a compile error. I just wanted to avoid compiling a static library its not neccesary and not desired.
Hi @sean-mcmanus , Visual Studio 2022 Community edition also has the same problem:
And compiles and link and execute and debug the software with no problems... just like vscode.
Ok, some progress:
I've created a new simpler project with one module but this time, I've created from Visual Studio 2022 Community CMake project wizard.
This time Visual Studio has no problem in finding the module (you must compile it twice for it to work properly - because the first time it generates the ifc
files):
VSCode still can't see it:
The CMake project uses presets when created with VS wizards.
In both I can compile, run, and debug normally.
And if I force the /ifcSearchDir
into CMakeLists.txt
VSCode gives me the edgm
error (VS does see the modules and finds the ifc
files without setting this manually in the CMakeLists.txt). I noticed that .command
files were generated in the build destination, and they have all the compilers parameters that are necessary to compile each file. My guess is that VS is using it to correctly generate the Intellisense and find everything.
@Bigous I've moved your issue to https://github.com/microsoft/vscode-cpptools/issues/9965 .