-
Notifications
You must be signed in to change notification settings - Fork 97
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
Configurable source dirs for file parsing #386
Comments
I think the idea of using an option to control the default sources makes good sense, given that I was trying to implement #382 to handle
With these thinking, handling |
Great! What do you think about having an exclusion list in addition to the source dirs list? It would allow something like:
A bit of fancy footwork somewhere to avoid parsing R folder twice in some cases, possibly just by making files to be parsed |
I guess an important use case is to specify a regex or glob pattern to choose a collection of files, both could be handled by |
Also, I find > Sys.glob("*.R")
character(0)
> Sys.glob("**/*.R")
[1] "R/call_hierarchy.R" "R/capabilities.R" "R/color.R"
[4] "R/completion.R" "R/definition.R" "R/diagnostics.R"
[7] "R/document.R" "R/folding.R" "R/formatting.R"
[10] "R/handlers-general.R" "R/handlers-langfeatures.R" "R/handlers-textsync.R"
[13] "R/handlers-workspace.R" "R/highlight.R" "R/hover.R"
[16] "R/interfaces.R" "R/languagebase.R" "R/languageclient.R"
[19] "R/languageserver.R" "R/link.R" "R/log.R"
[22] "R/namespace.R" "R/protocol.R" "R/references.R"
[25] "R/rename.R" "R/selection.R" "R/session.R"
[28] "R/signature.R" "R/symbol.R" "R/task.R"
[31] "R/utils.R" "R/workspace.R" "man-roxygen/document.R"
[34] "man-roxygen/id.R" "man-roxygen/position.R" "man-roxygen/self.R"
[37] "man-roxygen/tdpp.R" "man-roxygen/uri.R" "man-roxygen/workspace.R"
[40] "tests/testthat.R"
> Sys.glob("R/*.R")
[1] "R/call_hierarchy.R" "R/capabilities.R" "R/color.R"
[4] "R/completion.R" "R/definition.R" "R/diagnostics.R"
[7] "R/document.R" "R/folding.R" "R/formatting.R"
[10] "R/handlers-general.R" "R/handlers-langfeatures.R" "R/handlers-textsync.R"
[13] "R/handlers-workspace.R" "R/highlight.R" "R/hover.R"
[16] "R/interfaces.R" "R/languagebase.R" "R/languageclient.R"
[19] "R/languageserver.R" "R/link.R" "R/log.R"
[22] "R/namespace.R" "R/protocol.R" "R/references.R"
[25] "R/rename.R" "R/selection.R" "R/session.R"
[28] "R/signature.R" "R/symbol.R" "R/task.R"
[31] "R/utils.R" "R/workspace.R"
> Sys.glob(c("R/*.R", "tests/**/*.R"))
[1] "R/call_hierarchy.R" "R/capabilities.R"
[3] "R/color.R" "R/completion.R"
[5] "R/definition.R" "R/diagnostics.R"
[7] "R/document.R" "R/folding.R"
[9] "R/formatting.R" "R/handlers-general.R"
[11] "R/handlers-langfeatures.R" "R/handlers-textsync.R"
[13] "R/handlers-workspace.R" "R/highlight.R"
[15] "R/hover.R" "R/interfaces.R"
[17] "R/languagebase.R" "R/languageclient.R"
[19] "R/languageserver.R" "R/link.R"
[21] "R/log.R" "R/namespace.R"
[23] "R/protocol.R" "R/references.R"
[25] "R/rename.R" "R/selection.R"
[27] "R/session.R" "R/signature.R"
[29] "R/symbol.R" "R/task.R"
[31] "R/utils.R" "R/workspace.R"
[33] "tests/testthat/helper-utils.R" "tests/testthat/test-call-hierarchy.R"
[35] "tests/testthat/test-codeunits.R" "tests/testthat/test-color.R"
[37] "tests/testthat/test-completion.R" "tests/testthat/test-definition.R"
[39] "tests/testthat/test-folding.R" "tests/testthat/test-formatting.R"
[41] "tests/testthat/test-highlight.R" "tests/testthat/test-hover.R"
[43] "tests/testthat/test-langauagecilent.R" "tests/testthat/test-link.R"
[45] "tests/testthat/test-lintr.R" "tests/testthat/test-null-root.R"
[47] "tests/testthat/test-references.R" "tests/testthat/test-rename.R"
[49] "tests/testthat/test-search.R" "tests/testthat/test-selection.R"
[51] "tests/testthat/test-signature.R" "tests/testthat/test-stdio.R"
[53] "tests/testthat/test-symbol.R" "tests/testthat/test-tcp.R"
[55] "tests/testthat/test-unicode-path.R"
> Sys.glob("**/language*.R")
[1] "R/languagebase.R" "R/languageclient.R" "R/languageserver.R" |
Okay I quite like this. So the options could be globs? I'm going to have a go at an implementation and see how this feels. |
Not quite ready for a PR, but it seems to be working well: https://github.com/MilesMcBain/languageserver/tree/config-src-globs |
Please feel free to send a PR anytime. |
@MilesMcBain Do you intend to finish this PR? If not, what were the issues that you ran into? |
The main issue I had was writing tests for the code. The change itself wasn't too hard although code mat have drifted now. |
@sebffischer to answer the first part of the question for you, I'm not currently working on it and have no plans to pick it up. |
@randy3k & @renkun-ken , Just wanted to say it would be amazing if someone could pick this up again :( This limitation in particular causes pain when writing large packages with significant testthat/ code in vscode as it means you can't reliably depend on the reference finding when re-factoring code + tests. Even if the full feature isn't implemented it would be great to have tests/ added as a default directory that is scanned alongside the R/ directory. (obligatury thank you guys for your work, this package makes a huge difference to doing R based development) |
I'd like to summarize what we need to consider for this issue:
|
I mean my personal preferance would be to go down the route similar to
|
I'm digging up this issue because that's a feature that most (if not all) people of our research team want/need. The way our projects are organized makes it very difficult to use I made the following choices for the implementation:
I do have a working version in my fork at https://github.com/celbig/languageserver but no tests for now. If you are interested, I'm willing to do a proper PR with your suggestions and requirements. Considering tests, I'm not sure of what to test but I'm willing to implement whatever you find necessary. I hope this can help enhancing this package since this feature seems to be requested regularly |
Just adding my voice to request this feature. Something like |
It is a well known issue that the languageserver only parses files other than those that it is notified are opened in the case that it detects the workspace root is a package.
#253
This means that the way that workspace symbols and definitions work are not how many people expect and seem to deviate a little from the protocol specification: https://microsoft.github.io/language-server-protocol/specification#workspace_symbol.
There is also a related issue that, even in open files,
source()
is not understood as something that affects the workspace namespace:https://github.com/REditorSupport/vscode-r-lsp/issues/65
I believe a pretty cheap solution to this is to allow users to configure directories that the server should parse E.g.
options(languageserver.r.source.dirs = c("R", "scripts")
would causeworkspace$load_all()
parse R files in those two top level folders, even if it cannot identify the project as a package.Another possibly nicer alternative is for the option to work as an exclusion list, so parsing starts at
"."
and any paths containing folders with names defined in the option are ignored. But there seems to a lot of inertia behind the "no parse by default" position.The implementation would be pretty cheap:
in:
workspace$load_all
could take a vector of paths to parse.E.g.
workspace$load_all(self, source_paths)
So then we'd just need to build the vector of paths which is whatever
languageserver.r.source.dirs
says unioned with "R" in the case that the project is a package.The change to
workspace$load_all
is minimal too, sincefile.path
andlist.files
are already vectorised:I'd also argue for
recursive = TRUE
inlist.files
.The text was updated successfully, but these errors were encountered: