microsoft / microsoft/vscode-cpptools
Issue with includes when they are defined by preprocessor macros
まだ誰も着手していません。
- 主要言語
- TypeScript
- スター
- 6.2k
- フォーク
- 1.7k
- 平均マージ
- 14時間 46分
- マージ済み PR(30日)
- 61
説明
Type: LanguageService
Describe the bug
- OS and Version: Windows 10 1909, 18363.752
- VS Code Version: 1.43.2 user setup
- C/C++ Extension Version: 0.27.0
- Other extensions you installed (and if the issue persists after disabling them):
- Does this issue involve using SSH remote to run the extension on a remote machine?:
- When I use the preprocessor to define a header to include, and that header file is in a different folder, Intellisense seems unable to find it, even though said folder is correctly included in the C/C++ config file
Steps to reproduce
I attach a zip file with a workspace where the issue can be reproduced. It's the bare minimum to make it appear. It contains a base folder with one .c (main.c) file and two headers (header1.h and header2.h), and a subfolder with another .c file (anotherfile.c), where the issue is present. New folder.zip
Project
├── main.c
├── header1.h
└── header2.h
. └── Test
. └── anotherFile.c
- Create a header in a folder (header1.h)
- Create a .c file in a different folder (anotherFile.c in Test)
- AnotherFile.c must have an include determined by a preprocessor directive:
#include HEADER_NAME - Use the C/C++ Properties file to give a value to that preprocessor Macro:
"HEADER_NAME=\"header1.h\"" - See additional context to see on which situations the issue is fixed.
Expected behavior
As header1.h is in my includePath, I expect it to find header1.h
Logs
-------- Diagnostics - 07/04/2020, 11:24:20
Version: 0.27.0
Current Configuration:
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"HEADER_NAME=header1.h"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64",
"compilerArgs": [],
"cStandard": "c99",
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
Translation Unit Mappings:
[ C:\Users\joel.santos\New folder\test\anotherfile.c ]:
C:\USERS\JOEL.SANTOS\NEW FOLDER\TEST\ANOTHERFILE.C
Translation Unit Configurations:
[ C:\Users\joel.santos\New folder\test\anotherfile.c ]:
Process ID: 26344
Memory Usage: 11 MB
Compiler Path: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe
Includes:
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\BUILDTOOLS\VC\TOOLS\MSVC\14.16.27023\INCLUDE
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.17763.0\UM
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.17763.0\UCRT
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.17763.0\SHARED
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.17763.0\WINRT
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.17763.0\CPPWINRT
C:\USERS\JOEL.SANTOS\NEW FOLDER
Defines:
_DEBUG
UNICODE
_UNICODE
HEADER_NAME=header1.h
Standard Version: c99
IntelliSense Mode: msvc-x64
Total Memory Usage: 11 MB
Screenshots
Additional context
There are a number of situations where the issue disappears. For example, if I include another header on the same directory than the one that "can't be found", Intellisense can find the header. See anotherFile.c, there's a commented include. If that line is uncommented, Intellisense can find header1.h
Also, if I define the relative path to the header in the macro, Intellisense can find the header:
"defines": [
[...]
"HEADER_NAME=\"..\header1.h\"" //This works
[...]
],
My c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"HEADER_NAME=\"header1.h\""
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
main.c、header1.h、header2.h、Test/anotherFile.c、および提供された c_cpp_properties.json または ZIP ワークスペースを使用して問題を再現します。まず C/C++: Log Diagnostics を実行し、相対パスがある場合とない場合のマクロ展開された include ケースを比較します。HEADER_NAME がその名前に展開されたときに、IntelliSense が includePath から header1.h を解決できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, cpp, typescript, vscode
- 領域
- devtools, tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100