REditorSupport / REditorSupport/languageserver

Formatter not using styler?

Open
#675 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
675
Forks
118
Avg merge
1d 37m
Merged PRs (30d)
11

Description

I might have something wrong with my config but I can't figure out what. I am using vscode with the R extension using the languageserver. R is configured correctly (I think) such that I can run scripts, view plots, etc. Linting works as well.

Formatting does not seem to run through the styler package as expected.

Here is a file before formatting:

library("tidyverse")

tibble(x = 1:12, y = rnorm(12)) %>%
ggplot(aes(x = x, y = y)) +
geom_point() +
geom_smooth(method = "lm")
c(1,2,3)

And after formatting using the languageserver functionality in vscode (Right click > Format Document):

library("tidyverse")

tibble(x = 1:12, y = rnorm(12)) %>%
    ggplot(aes(x = x, y = y)) +
    geom_point() +
    geom_smooth(method = "lm")
c(1, 2, 3)

As you can see, the lack of spaces in the last line is fixed. However, the indentation is using 4 spaces, not 2 spaces. The linter yells at me because of the wrong number of spaces.

If I use styler directly on the file (i.e. by opening an R terminal, and running the command style_file("/path/to/file.R")), I get the following:

library("tidyverse")

tibble(x = 1:12, y = rnorm(12)) %>%
  ggplot(aes(x = x, y = y)) +
  geom_point() +
  geom_smooth(method = "lm")
c(1, 2, 3)

In this case, the indentation is correct.

Any advice?

Contributor guide

No contributing guide indexed for this repository

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

Start by reproducing formatting through the R languageserver in VSCode and compare its output with running styler directly on the same file. Done means the languageserver formatter uses styler-compatible two-space indentation so the formatted code no longer triggers the linter.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.