microsoft / microsoft/vscode-cpptools

c_cpp_properties.json support for environment variables defined in ~/.bashrc used in "includePath" and "compilerPath"

Open
#11,186 4 comments 29 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature Request Feature: Configuration Language Service
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Feature Request

I have a project compiled with g++. I have two Windows PCs, with one connected to local WSL and the other to a remote server. The path to g++ and the path of a third-party library needed in the includePath are different on the two devices.

So I set different environment variables in .bashrc on both devices:

export GCC_PATH = /path/to/gcc
export MY_LIB_PATH = /path/to/my/lib/

In c_cpp_properties.json, use the following settings:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "${env:MY_LIB_PATH}/include"
            ],
            "compilerPath": "${env:GCC_PATH}/bin/g++",
            "cStandard": "gnu23",
            "cppStandard": "c++20",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

Then the following problems occured:

  1. It seems that intellisense currently doesn't recognize using environment variable in compilerPath. There are squiggles under "${env:GCC_PATH}/bin/g++".

  2. Although there are no squiggles under "${env:MY_LIB_PATH}/include" in includePath, the intellisense still can't find the header that needs to be included in the .cpp file. So when I open a .cpp file, squiggles appear.

This should not be due to a flaw in defining environment variables in .bashrc, as this link suggests that VSCode should now auto-detect environment variables in .bashrc.

I noticed and browsed a lot of issues about environment variable support, but still can't find a solution for this problem, so I consider it as a request that may be added.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the configuration in c_cpp_properties.json using environment variables from ~/.bashrc in both includePath and compilerPath. Start by checking how IntelliSense resolves these two settings; done means the compilerPath produces no squiggle and headers under the environment-based includePath resolve without diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, cpp
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.