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

Section collapsing issues #643

Closed
kylebutts opened this issue Nov 24, 2023 · 1 comment · Fixed by #644
Closed

Section collapsing issues #643

kylebutts opened this issue Nov 24, 2023 · 1 comment · Fixed by #644

Comments

@kylebutts
Copy link
Contributor

The language server has preferences over the way sections collapse (namely, collapse up to a set of 2 blank lines:

nline_to_break_succession <- 2L
and

languageserver/R/section.R

Lines 319 to 337 in 7f7605b

#' two or more blank lines out of block ranges should break sections succession
#' @noRd
extract_document_section_breaks <- function(line_numbers, line_content) {
blank_lines <- line_numbers[
grepl("^\\s*$", line_content, perl = TRUE)
]
if (!length(blank_lines)) {
return(NULL)
}
# make continuous blank lines as groups
groups <- split(blank_lines, factor(cumsum(diff(c(0L, blank_lines)) > 1L)))
# how many lines should break off section succession ? ( 2L )
groups <- groups[lengths(groups) >= nline_to_break_succession]
if (length(groups)) {
vapply(groups, min, integer(1L))
} else {
NULL
}
}

I'm wondering if changing this could be part of the available settings? I personally, like extra whitespace, so it would be nice to configure. I would be happy to open a PR. I think the steps would be:

  1. Add nline_to_break_succession option to S6 option Settings
  2. In section.R, use lsp_settings$get("nline_to_break_succession") here:
    nline_to_break_succession <- 2L
@renkun-ken
Copy link
Member

It is perfectly okay to send a PR on this if you find it useful.

kylebutts added a commit to kylebutts/languageserver that referenced this issue Nov 26, 2023
renkun-ken added a commit that referenced this issue Jan 6, 2024
Add `nline_to_break_succession` as option (#643)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants