microsoft / microsoft/vscode-cpptools

Getting function arguments to align automatically when hitting enter

Open
#5,726 4 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Type: LanguageService

Describe the bug

  • OS and Version: Mac OS Mojave 10.14.6
  • VS Code Version: 1.46.1
  • C/C++ Extension Version: 0.28.3
  • Other extensions you installed (and if the issue persists after disabling them):
    • All Autocomplete
    • Microsoft C/C++ official
    • Better C++ Syntax
    • Hungry Delete

The issue persists even when running code --disable-extensions

Supposed I have code like this:

    myFunction(arg1, arg2, arg3);

In Sublime Text, when I put the cursor in front of the arg2 and hit enter, the rest of the function call moves down a line and arg2 lines up with arg1 like so:

    myFunction(arg1, 
               arg2, arg3);

However, if I do the same in VS Code, the arg2 lines up to the current indentation level:

    myFunction(arg1, 
    arg2, arg3);

I can repeatedly hit the tab key to move it over 4 spaces at a time, but since the start of arg1 is 11 spaces away, I either have to deal with a slight misalignment like so:

    myFunction(arg1, 
                arg2, arg3);

or I have to use the spacebar as well as the tab key to align it just right.

If I simply bring arg2 to the next level and use "Format Selection", I get everything to align perfectly. However, I was wondering if there's any way to get this behavior to occur automatically by hitting enter.

Note that I don't want "Format Document" to run automatically; I want to keep the rest of the file as is and just have things line up as I move them to new lines.

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

The issue names no file or test, but identifies the C++ LanguageService and the existing Format Selection behavior. Start by locating handling for Enter/newline indentation and compare it with formatting; done means function arguments align automatically on Enter without formatting the rest of the document.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, typescript
Domain
developer-experience, 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.