Skip to content

Commit

Permalink
Merge pull request #644 from kylebutts/master
Browse files Browse the repository at this point in the history
Add `nline_to_break_succession` as option (#643)
  • Loading branch information
renkun-ken committed Jan 6, 2024
2 parents 7f7605b + 3cbffd4 commit 924840f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
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
12 changes: 12 additions & 0 deletions R/folding.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ get_comment_folding_ranges <- function(xdoc) {
perl = TRUE
)
]
# For code chunks in plain `.R` files.
# This messes up folding when you have `#|` options
# or just comments on next line after code chunk
comments <- comments[
!grepl(
paste0(
"(", "#\\s*%%", ")\\s*"
),
xml_text(comments, trim = FALSE),
perl = TRUE
)
]
if (identical(length(comments), 0L)) {
return(NULL)
}
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

0 comments on commit 924840f

Please sign in to comment.