-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Position of the cursor after sending []TextEdit through provideOnTypeFormattingEdits
#3088
Comments
@yageek IMHO this does not really fit a format edit. A format edit should do transformations that do not affect the program logic (mostly adding/removing whitespace). Maybe what you want can be achieved (a lot easier) with
|
Could be. I saw in the API that there is also an I would like to perform this addition but only if the next line contains some specific keywords. For example, with a try for the but nothing is appended to the source code. |
The var x = 3|45;
// beforeText: "var x = 3"
// afterText; "45;" I mean those are the values that are matched against the regexes |
If your logic doesn't match the |
Closing this for now as it is unclear to me what is the use case. If none of our concepts fit the use case, an extension could register a keybinding rule for 'Enter' and do all the logic for 'Enter' on its own. |
@alexandrudima Here's a use-case (it's been requested by users of vscoq and is a feature in the equivalent emacs extension; language: coq): Before: * tactic.| After * tactic.
| Effect: the cursor is indented to a position that is dependent on the previous line. |
@alexandrudima another use-case:
After:
For this case, languages.setLanguageConfiguration(modeID, {
onEnterRules: [
{ // insert comment on new line while preserving the indent
beforeText: /^\s*(\/\/\s*)\S.*$/,
action: { indentAction: IndentAction.None, appendText: '${1}' }
}
]
}); |
And to support the use-case for aligning to the tactic after a bullet, onEnterRules: [
{ // align indent to prior-line's tactic
beforeText: /^\s*(\*\s*)\S.*$/,
action: { indentAction: vscode.IndentAction.None, appendText: (beforeMatches) => ' '.repeat(beforeMatches[1].length) }
}
] |
@siegebell I found the idea to support capture groups really good. I've opened a new issue #17281 to track this. The idea to support a callback is IMHO unrealistic because the callback is defined in the extension host process and the handling of pressing enter and of the rules is running on the renderer process (i.e. cannot invoke |
@alexandrudima I agree - It seems to me that the existence of That said, here's another use-case (3): const x = 'some ' +
'long ' +
'string '; and (4) const x = 'some '
+ 'long '
+ 'string '; Maybe there needs to be a more flexible way to specify an alignment point. For example: onEnterRules: [
{ // case (3): align indent to after the prior-line's = or + if it is not terminated by ';' or is terminated by +, ||, or &&
beforeText: /^.*(?:=|\+)\s*.*(?:[^;]|[+]|\|\||&&)$/,
action: { indentAction: vscode.IndentAction.Align, alignTo: /^.*=\s*(.)/ }
},
{ // case (4): align indent to prior-line's = or + if it is terminated by a string and no ';'
beforeText: /^.*(?:=|\+)\s*.*['"`]\s*$/,
action: { indentAction: vscode.IndentAction.Align, alignTo: /=\+/, appendText: '+ ' }
},
{ // case (1): align indent to prior-line's tactic
beforeText: /^\s*\*+\s*\S.*$/,
action: { indentAction: vscode.IndentAction.Align, alignTo: /^\s*\*+\s(\S)/ }
}
] The behavior of |
Would it be possible to reopen this ticket ? I think I am experiencing the same problem but with
provideOnTypeFormattingEdits
.I would like to automatically add
//
after the user has returnedEnter
.To do so, I subscribe with
registerOnTypeFormattingEditProvider
and I provide a listener with this implementation:'use strict';
import { OnTypeFormattingEditProvider, TextDocument, Position, FormattingOptions, CancellationToken, TextEdit , Range} from 'vscode';
The problem here is that the final position of the cursor is the following:
What I would like to achieve:
EDIT: I think it is related to #755
The text was updated successfully, but these errors were encountered: