microsoft / microsoft/vscode-cpptools

Request: Smart indentation on preprocessor directives

Open
#933 7 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi,

Sometimes I would like to write some code like this:

#ifdef _SOME_COND_
    xxx;
    yyyy;
    zzzzz;
#endif

However currently in VS Code the "closing" directives are not automatically outdented, so I end up something like this:

#ifdef _SOME_COND_
    xxx;
    yyyy;
    zzzzz;
    #endif

I hope the directives like #else, #elif, #endif can be automatically aligned to the nearest #if, #ifdef, or other corresponding "opening" directives.

Please consider this. Thank you.

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

No file or test is named. Start by locating the VS Code C/C++ extension's indentation handling for preprocessor directives, then trace how #if, #ifdef, #else, #elif, and #endif are recognized. Done means closing and alternate directives align with their corresponding opening directive in the demonstrated C example.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, typescript, vscode
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.