-
Notifications
You must be signed in to change notification settings - Fork 108
Code section support #163
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
Code section support #163
Conversation
|
We will need to check if the client has the See: https://github.com/REditorSupport/languageserver/blob/master/R/languageserver.R#L29 |
|
If the client does not have |
|
For section titles, perhaps it makes sense to keep the leading #'s to distinguish them from regular symbols. We also need to remove the |
|
Or simply ignore all the section titles. |
|
As requested, this is the previous comment from [Feature request] Support for code sections #76 @renkun-ken Thank you very much for implementing this pull request. Coming from RStudio, I have been missing this feature badly. Navigating large file without code sections is a nightmare for me. I can't you tell how much I really appreciate this feature! First questionIn Code section support #163, I see it supports one level of nested hierarchy. # section 1----
fun1 <- function() {...}
fun2 <- function() {...}does it support nested hierarchy with multiple levels? A common use case # section 1----
fun1 <- function() {...}
fun2 <- function() {
# case A----
if
# case b----
else if
# case c----
else
}Second questionIs it possible to also support R-friendly heading sections for Rmarkdown (*.rmd)? This format shows no outline at all. # Rmarkdown heading
```{r}
plot(iris)
# ``` <- annotate "triple backticks" by commenting it out because it won't show up in Github markdown formatWith the same code, and in Additionally, can the hash sign |
|
@mik3y64 Thanks for posting your question here.
It's not hard to support two-level sections like the following: # section1 ####
fun1 <- function(x, y) {
cat(x, "\n")
# subsection 1 ####
x + y
# subsection 2 ####
x + y
}
# section 2 ####
fun2 <- function(x, y) {
cat(x, "\n")
# subsection 3 ####
x + y
# subsection 4 ####
x + y
res <- local({
x + y
# subsubsection 5 ####
x + y
})
x + y
}which has the following outline: I think is it's good enough for me. In this case, it is sections and subsections. The range of sections span to the next section while the range of subsections only spans a single line or otherwise the range can be hardly determined without relying on parsed document. Do you view subsection support is a positive addition, @randy3k?
Currently, I don't handle the Rmd case, which I believe requires special handling in symbol provider which should extract markdown titles instead of such comments. Maybe we should file another PR for this later. |
|
As for the fact that some clients may not have But if client has |
|
It looks great! Subsection support will help navigating complex functions and large files. Two levels cover most of the use cases in R-programming. Well done. Thank you very much! (For the edge cases, if needed, it can always be improved later. It is still early days for R-lsp) Yes, Rmarkdown sections is more complicated because the leading |
|
We still cannot merge this because some editors might not have |
|
I'm not sure about what the outline might look like if the editor does not have If the editor does not have |
|
I am okay with ignoring the section symbols if an editor does have |
|
Now section symbols are provided only if client has |

Closes #160
Closes REditorSupport/vscode-R#76
Closes REditorSupport/vscode-R#193
This PR is a simple support of code section using DocumentSymbolProvider. It matches all comment lines that starts with # and ends with at least four #, +, -, = and show the string in-between as symbol.
This also addresses the comment at REditorSupport/vscode-R#76 (comment) by using unified document symbol provider (all in languageserver), and the symbol information of each code section starts from the first line and ends before the next code section so that a hierarchy of code section containing symbol definitions can be presented.
Following is a screenshot in VSCode: