Open sean-mcmanus opened 4 years ago
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
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/ .@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 .
@sean-mcmanus @cjwijtmans VS 2022 with cmake 3.24 with this exact configuration
cmake_minimum_required(VERSION 3.24)
project(testing-modules-project VERSION 0.1.0)
####
# Ack use of experimental features
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "3c375311-a3c9-4396-a187-3227ef642046")
# Experimental Module support
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
# This setup is MSVC-only for now
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
string(CONCAT CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE
"<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> <SOURCE> /nologo /TP"
" /showIncludes /scanDependencies <DYNDEP_FILE>"
" /Fo<OBJECT>")
set(CMAKE_EXPERIMENTAL_CXX_SCANDEP_DEPFILE_FORMAT "msvc")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "msvc")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG "@<MODULE_MAP_FILE>")
endif()
####
add_library(modules-library STATIC)
target_compile_features(modules-library PUBLIC cxx_std_20)
target_sources(
modules-library
PUBLIC
FILE_SET CXX_MODULES FILES
src/test-module.cpp
"src/test-ixx-module.ixx")
add_executable(testing-modules-project "src/main.cpp")
target_link_libraries(testing-modules-project PUBLIC modules-library)
VS Code with the latest release of cmake in the same project
What I can see is that only ixx files generate ifc's. Another thing is that vscode can't read those ifc's maybe it doesn't know where it is or idk.
@sean-mcmanus @cjwijtmans VS 2022 with cmake 3.24 with this exact configuration
I've discovered a potential solution from my own attempts in another situation. You may try this: copy test-ixx-module.ixx.ifc to test-ixx-module.ifc. Then vscode may be able to read it (restart intellisense for the file or restart vscode to make sure). We could at least benefit for now (while we wait for a real fix) if cpptools can incorpoate some kind of hack-fix base on this, in the event that this "solution" works reliably. Does it work for you?
By the way I'm sure you do also have to add /ifcSearchDir to cmake comple options and this is EXTREMELY FINICKY, example:
target_compile_options(<TARGET> PUBLIC /ifcSearchDir<PATH-TO-IFC>)
Don't put a space between /ifcSearchDir and
Perhaps someone can provide a different solution to automatically have our ixx's named so vscode can read them (for now while we wait). By the way I've noticed sometimes vscode reads an IFC for intellisense purposes and refuses to let go. So when I rebuild the IFC, it fails to write the file because write-access is locked by the operating system (Windows 10). I must kill the cpptools-srv process. Something to look out for as well...
any idea how to fix "edgm file not found" error on vscode? I dont know how those files are generated.
@lunfardo Are you using msvc or gcc/clang IntelliSense mode? Oh, it looks like you may be hitting bug https://github.com/microsoft/vscode-cpptools/issues/9965
At present, the format of the module IFC has not been standardized, why not let me manually specify the source files or set which directories to search for the source files? And other compilers other than mavc do not support IFC, do other compilers generate module binaries in different formats?
For those of you trying experimental cmake support for c++ modules, check out
https://www.kitware.com/import-cmake-c20-modules/
These instructions seems more updated than some of the guidelines above. Works for me with named modules on macosx with cmake@3.26, clang++@16 and recent ninja. Sadly module import in IntelliSense does not work though, but compile, link, run works.
Does clang provide introspection with modules?
Yes, clangd extension can read modules built by clang compiler. I played over the Christmas holidays with waf as a build system (since it's the easiest one to extend). At the time neither clang nor gcc could build standard headers all the way and the server mode for module resolver didn't pay well with compile_commands.json which were used to communicate between the build system and the language servers, so I lost interest. But the integration itself between compiler and LS worked surprisingly well.
@sean-mcmanus @cjwijtmans VS 2022 with cmake 3.24 with this exact configuration By the way I've noticed sometimes vscode reads an IFC for intellisense purposes and refuses to let go. So when I rebuild the IFC, it fails to write the file because write-access is locked by the operating system (Windows 10). I must kill the cpptools-srv process. Something to look out for as well...
I just wanted to confirm this observation, which happens pretty reliably for my setup (VSCode 1.78.2, vscode-cpptools 1.15.4, CMake Tools 1.14.31, CMake 3.26.1 using MSVC Toolset 14.32.31326 due to #10843). Project is generated with CMake using the experimental C++ Module features. Got Intellisense to work as excpected with my own import
ed Modules by adding the ifcSearchDir
compiler argument to c_cpp_properties.json
using an absolute path to where CMake places the .ifc
files:
"compilerArgs": [ "-ifcSearchDirD:/Development/matrix/.build/windows-x64-msvc/CMakeFiles/matrix.dir/debug" ]
Changing any code necessitating rebuilding the .ifc
results in:
[build] D:\Development\matrix\interface\engine\core\math\matrix.ixx(119): error C3474: could not open output file 'CMakeFiles\matrix.dir\debug\engine.core.math-matrix.ifc'
"Clean Reconfigure" in CMake Tools results in:
[rollbar] Unhandled exception: Unhandled Promise rejection: cleanConfigureAll Error: EBUSY: resource busy or locked, unlink 'D:\Development\matrix\.build\windows-x64-msvc\CMakeFiles\matrix.dir\debug\engine.core.math-matrix.ifc' {}
"Clean all projects" in CMake Tools results in:
ninja: error: remove(CMakeFiles/matrix.dir/debug/engine.core.math-matrix.ifc): The process cannot access the file because it is being used by another process.
.ifc
files seem to be in this locked state almost immediately whenever a relevant source file is opened. Restarting VSCode only helps when those source files are closed beforehand (so theyre not automatically opened again).
Im not sure if this is the right area to be asking this but has anyone managed to get intellisense working with modules in GCC/Clang? compilation works just fine, it's just the intellisense that is borked.
@bobbrow I was going to ask if there are any updates on modules but then I remembered to check the EDG site: [REDACTED] If I understand correctly, it's the base for all IntelliSense features.
In that context I have another question: In the case of modules, how are going Documentation comments to be supported? Where should they be placed? Any ideas? I assume we mean Doxygen and the current support in VSCode.
I would really like to be able to continue seeing the help hover dialogs, with documentation strings.
@H-G-Hristov I would expect documentation comments to be picked up for module exports the same way they are for regular types/functions/etc. Does that not happen with the unofficial support today?
I use VScode, Cmake, Mingw and I get this false positive on import. It's currently the only thing that's keeping me from using module. When will they fix it?
Hi @JG-Adams, unfortunately, we don't have a good estimate as to when we will be able to support modules across all the different compilers. When our language server gets the update we will add this issue to a Milestone and enable the support in VS Code.
Growlith1223
did you found out how to do this?
any workaround to enjoy modules in vscode?
any workaround to enjoy modules in vscode?
I use cpptools as the debugger frontend and clangd for IntelliSense (via compile_commands) until the issue and a few others that are important to me are closed. Just know, clangd use caching for Intellisense, like Intelli Idea. It means you can get suggestions from old or irrelevant files. And this doesn't support doxygen-like commands. You just have to choose what is more important to you.
any workaround to enjoy modules in vscode?
I'm using the extension clangd and the program xmake to generate the compile_commands.json (and compile modules).
clangd can work, but there's two small problems.
import
keyword? import
statement.It's surprising that the 'import' feature hasn't been supported yet. What factors need to be considered?"
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