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 nline_to_break_succession as option (#643) #644

Merged
merged 3 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Error in Neovim: “attempt to compare string with number” (#609)
- On-type formatter adds extra indentations after pipes (#607)
- Add `nline_to_break_succession` option to control section collapsing (#643)

**Merged pull requests:**

Expand Down
14 changes: 9 additions & 5 deletions R/section.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ section_level_regex <- paste0(
"[", paste0("\\", section_level_prefix, collapse = ""), "]*+"
)

# options, number of blank lines to break sections or binary ranges
# default 2L, the same with markdown
nline_to_break_succession <- 2L

#---------------------------r document utils functions------------------------#
get_r_document_sections_and_blocks <- function(content, xdoc, symbol = FALSE) {
block_lines_list <- extract_document_block_lines(xdoc)
Expand Down Expand Up @@ -173,6 +169,10 @@ get_r_document_section_ranges <- function(content, line_numbers) {
}

get_r_document_binary_ranges <- function(content, line_numbers, block_lines_list) {
# options, number of blank lines to break sections or binary ranges
# default 2L, the same with markdown
nline_to_break_succession <- lsp_settings$get("nline_to_break_succession")

is_binary_line <- is_binary_line(content[line_numbers])
if (any(is_binary_line)) {
start_lines <- line_numbers[is_binary_line]
Expand Down Expand Up @@ -316,9 +316,13 @@ extract_document_section <- function(line_numbers, line_content) {
NULL
}

#' two or more blank lines out of block ranges should break sections succession
#' `nline_to_break_succession` or more blank lines out of block ranges should break sections succession
#' @noRd
extract_document_section_breaks <- function(line_numbers, line_content) {
# options, number of blank lines to break sections or binary ranges
# default 2L, the same with markdown
nline_to_break_succession <- lsp_settings$get("nline_to_break_succession")

blank_lines <- line_numbers[
grepl("^\\s*$", line_content, perl = TRUE)
]
Expand Down
3 changes: 2 additions & 1 deletion R/settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Settings <- R6::R6Class("Settings",
max_completions = 200,
lint_cache = FALSE,
server_capabilities = list(),
link_file_size_limit = 16L * 1024L^2
link_file_size_limit = 16L * 1024L^2,
nline_to_break_succession = 2L
)
),
public = list(
Expand Down
Loading