Vscode-cpptools: Request: Smart indentation on preprocessor directives

Created on 1 Aug 2017  路  5Comments  路  Source: microsoft/vscode-cpptools

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.

Feature Request Language Service more votes needed

Most helpful comment

Our formatting is currently configurable via a .clang-format file, but I'm not aware of a setting that increases the indentation inside of #ifdef blocks (it will indent based on the surrounding {} block). It sounds like @horvay has formatOnPaste set to true. Formatting the #endif to match the indentation of the #if sounds like it might be implementable via the VS Code autoindent rules (which we don't have support for yet).

All 5 comments

Do you have any special formatting settings?

When I copy and paste your example bottom example and autoformat, it properly outdents the #endif

If fact, for me it's making all the preprocessor stuff go completely to the left, and the body is tabbed according to the rest of the document.

So I get this:

template <typename T, typename V>
void generateRand(T start, T end, V startValue)
{
    std::iota(start, end, startValue);

    // deprecated in C++14:
    // std::random_shuffle(start, end);

    std::random_device rd;
    std::mt19937 gen(rd());
    std::shuffle(start, end, gen);

#ifdef _SOME_COND_
    xxx;
    yyyy;
    zzzzz;
#endif
}

#ifdef _SOME_COND_
xxx;
yyyy;
zzzzz;
#endif

Our formatting is currently configurable via a .clang-format file, but I'm not aware of a setting that increases the indentation inside of #ifdef blocks (it will indent based on the surrounding {} block). It sounds like @horvay has formatOnPaste set to true. Formatting the #endif to match the indentation of the #if sounds like it might be implementable via the VS Code autoindent rules (which we don't have support for yet).

@sean-mcmanus : Thank you for your reply.

@horvay : The editor's behavior of typing in the code is different from copying/pasting.

This feature request is being closed due to insufficient upvotes. When enough upvotes are received, this issue will be eligible for our backlog.

Was this page helpful?
0 / 5 - 0 ratings