Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SmartIndent capability #16998

Open
IntelOrca opened this issue Dec 9, 2016 · 6 comments
Open

Add SmartIndent capability #16998

IntelOrca opened this issue Dec 9, 2016 · 6 comments
Assignees
Labels
api editor-autoindent Editor auto indentation issues feature-request Request for new features or functionality
Milestone

Comments

@IntelOrca
Copy link

Visual Studio has an extensibility point called SmartIndent:
https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.text.editor.ismartindent.aspx

This allows a language service to provide the editor, given a line, what the indentation level should be. If you click on a blank line in Visual Studio, it will automatically place the caret at the correct indent level based on the code above. This also works when using the arrow keys to move the caret. Currently in VSCode, it will place the caret at column 0 for blank lines.

This may come hand-in-hand with implementing virtual space (see #13960) as Visual Studio will not insert spaces, but just place the caret at the correct column in virtual space.

One thing to note is that in Visual Studio, when clicking on a blank line, the X position that you click at must be greater than the expected indentation column in order for this to work, otherwise it will place the caret at column 0. With the arrow keys, unless you are at column 0, your caret will always move to the correct indentation level for that blank line.

@sharwell
Copy link
Member

sharwell commented Dec 9, 2016

This is a good feature to have. I was disappointed to learn that ISmartIndent was quite limited in its abilities. In particular, the interface doesn't allow a language to define something like the Comment Continuation Mode I describe in Smart Indent (Draft).

📝 Since publishing that paper, I've managed to define behavior for Smart Indent in more generalized scenarios. However, the paper remains a good overview for the general functionality that a ISmartIndent interface needs to support.

@IntelOrca
Copy link
Author

IntelOrca commented Dec 9, 2016

@sharwell Your paper talks about splitting a line which suggests you expect SmartIndent to define not just the indent for blank lines but also on what it does when pressing RETURN. This sounds like its also related to automatic doc-comment continuation and automatic generation of end constructs (for example end if in VB.NET). When developing this logic for a Visual Studio extension, I had to use a command filter to override the RETURN behaviour. This is what Roslyn uses as well.

In Visual Studio, the ISmartIndent only works with blank lines, but perhaps if implemented in VSCODE it could also allow overriding the behaviour for non-blank lines so that the right caret position can be set inside comment blocks.

And if special logic is needed for the RETURN action, then another method to override that behaviour.

@sharwell
Copy link
Member

💭 I thought in Visual Studio, ISmartIndent works both on blank lines and in the case of splitting a line in the middle, but only for the purpose of determining the indentation. I could be wrong though, it's been a while since I worked on that component.

To me, Smart Indent deals with two things:

  1. What happens when you move the caret to a blank line, either by clicking on a blank line or by hitting the up or down arrows (or page up/page down)?
  2. What happens when you press Enter?

I don't necessarily have an obvious idea for what the interface should look like, but I can tell you what should happen when Enter is pressed provided the interface exists for extensions. In Visual Studio, the answer could probably be provided in terms of a ITextEdit (for the modifications) and a VirtualSnapshotPoint (for the caret placement). But that's just one possibility. 😄

@IntelOrca
Copy link
Author

IntelOrca commented Dec 10, 2016

I thought in Visual Studio, ISmartIndent works both on blank lines and in the case of splitting a line in the middle, but only for the purpose of determining the indentation.

That's correct, I thought you also expected it to perform a text edit like how it trims the line or inserts a new comment prefix etc.

@sharwell
Copy link
Member

Ah, no. I'm saying that I like your idea of supporting Smart Indent in new languages in VS Code, but I'd like to see it go one step farther than ISmartIndent because that interface isn't able to express some pretty useful behavior of a smart indent feature.

@claybford
Copy link

Hi, are there any updates on this issue? It makes vscode much harder to use with typical mouse interaction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api editor-autoindent Editor auto indentation issues feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

5 participants