question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow more powerful onEnterRules for cursor alignment

See original GitHub issue

In the Python extension, we’d like to add support for variable-length indents on enter to better support PEP8 formatting (Microsoft/vscode-python#481 and others). For example:

def func(a,
         |

Hitting enter on the first line should stick the cursor where | is, not just a single indent. In this second case, it should do a single indent:

def func(
    |

There appears to only be two ways to handle this:

  • onEnterRules
  • On-type formatting

We’d like to avoid the latter, as we currently support both Jedi and our own language server, which means implementing on-type formatting in two different places (since a single language cannot have multiple on-type formatting providers). Plus, on-type formatting is not enabled by default nor is very popular (and enables a slew of formatting rules other than cursor alignment), so forcing users to enable on-type formatting as a whole would be good to avoid.

The other candidate is onEnterRules, but it’s not powerful enough to be able to do something like this, as:

  • The “actions” work in terms of indents, whereas these cursor positions may not be a round multiple of an indent, meaning appendText would be required, but…
  • appendText is only allowed to be a static string, and cannot be generated on the fly.
  • Rules are applied using regex to deduce context, which gets unweildy, and even more difficult without #50952.
  • Even with something like #17281, there wouldn’t be a way to convert a capture group to “whitespace of the same length of the capture group” (plus the issue of tab indents).

My initial thought was to allow a function to be provided in onEnterRules instead of just specifying appendText. For example, something like:

{
    beforeText: /\s+def\s+\w+\(\w+/,  /* not the real regex */
    action: {
        indentAction: IndentAction.None,
        appendText: (document, position, formatOptions, ... /* something */) => calculateIndent(...) // returns a string
    }
}

However, on closer inspection of how onEnterRules works, it appears that it needs to be serializable, so I’m not sure it’d be able to have a callback like the above.

Is there something that can be added to allow more powerful rules on-enter? Or, is there something that already exists that we’ve missed?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:47
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
kbrosecommented, Mar 20, 2019

Hi, can we get an update on this? Is this actively being worked on or currently somewhere in the backlog?

2reactions
MikhailArkhipovcommented, Jan 14, 2019

@jriekenSomething like an indentation provider?’ - yes, exactly. It does can feel sticky if extension is badly written 😃 (happens in VS IDE). But generally it is up to the extension to decide and deal with how to do it fast, IMO.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mouse pointer alignment - Microsoft Community
Hello, I'm running Windows 10 on a Toshiba Satellite E55-A5114. I recently connected it to a Sceptre monitor to extend the display.
Read more >
cursor - CSS: Cascading Style Sheets - MDN Web Docs
The cursor CSS property sets the mouse cursor, if any, to show when the mouse pointer is over an element.
Read more >
How to use multiple cursors in VS Code - YouTube
Multiple cursors is a powerful way to edit text, but the concept is a bit intimidating. Once you see them in action, they...
Read more >
Multiple-Cursor Magic in VSCode – 3 Approaches - Atomic Spin
Working with Multiple Cursors in Visual Studio Code ... multi-cursor mode can be used for column-mode editing, it is much more powerful!
Read more >
SPARC T5-4 Server Product Notes
Mouse Pointer Is Not Aligned With the Cursor in a Remote Window (BugID 15798251) ... and enables you to perform steps that result...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found