-
Notifications
You must be signed in to change notification settings - Fork 130
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
Feature request: better auto indent #62
Comments
@adamaltmejd Thank you for your good idea! |
It looks like the formatter API should do the trick. Here's the example in the docs: // 👍 formatter implemented using API
vscode.languages.registerDocumentFormattingEditProvider('foo-lang', {
provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] {
const firstLine = document.lineAt(0);
if (firstLine.text !== '42') {
return [vscode.TextEdit.insert(firstLine.range.start, '42\n')];
}
}
}); We could probably use this as the first step towards a variable viewer as well. vscode.languages.registerDocumentFormattingEditProvider('foo-lang', {
provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] {
const lastLine = document.lineAt(getLastLineNumber());
if (lastLine.indexOf('<-')) {
const rVariable = getVariableFromLine(lastLine);
addVariableToDisplay(rVariable);
}
}
}); |
Another question, I just want to make sure this is not just on my end. Is the auto-indenting also not working with other multi-line constructs? E.g. this is what I get when I do the following:
When it should be:
Just want to make sure this is also a current non-feature. Thanks! |
Bump! Just want to ^ above, @Ikuyadeu - wondering if its something I should look into helping with. Thanks! |
The version of the language server on GitHub supports customised I think customised indenting should be supported via the |
An alternative point of view is that the requested indentation is a widely used standard for R, rather than being a customization that should be delegated to another tool. The two other tools that I have used for editing R code (RStudio and PyCharm) both implement this indentation out of the box. For me, having this standard indentation supported by the plugin without requiring external restyling would be a really valuable enhancement. |
I'm thinking that a fast indention formatter would be nice, at least it could be faster than the indention created by the languageserver on-type-formatting implemented by REditorSupport/languageserver#209. I use styler to create the indention mainly to walk-around the complexity of the expression detection but it clearly relies on the correctness of the syntax of the expression under cursor but it is not trivial to cover some cases. Moreover, there's a significant lag between hitting the key ( |
I agree with the MarkCButler's view that this can be considered an appropriate default. Perhaps a nice starting point is the following https://github.com/kbrose/vsc-python-indent which does the requested for Python code! |
Just found an extension called "Indent To Bracket" that would do indent to open bracket. |
The extension is nice, |
I still seem to be running into this formatting issue. Has there been any update on this, or is there a way to customise the indentation options to align with other IDEs, like @MarkCButler suggested? Thanks! |
@robertamezquita --- did you ever find a workable solution? A few years down the line & it looks like mirroring RStudio's formatting in VS Code still isn't possible (& I find the formatting in |
Would be really great if the autoIndent worked better, preferably according to standard style guides. (see https://google.github.io/styleguide/Rguide.xml and http://adv-r.had.co.nz/Style.html)
When a line ends with an open bracket of some sort (
(, [, {
) indentation kicks in according to whatever setting you have. This example already works as it should:However when a bracket is open, but there is something after it on the same line, indentation should be all the way to the opening bracket, not just the default number of spaces. For example:
bad way:
correct:
That is, when pressing enter after the
&
sign, indent should be 7 spaces instead of 2. Right now, when one presses enter after the&
sign, no indent is applied at all.Maybe one could implement the styler package to do it automatically (http://styler.r-lib.org) using the formatOnSave option in VsCode.
The text was updated successfully, but these errors were encountered: