-
Notifications
You must be signed in to change notification settings - Fork 93
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
On save, lintr raises "unexpected '/'" error #283
Comments
Could you report the debug log from Atom? Open the devtools console, run |
Here you go: atom_debug.log That's opening Atom, saving the file, modifying the file, saving the file again. Please let me know if I've missed anything, or if anything else would be helpful. |
A simple fix is to use |
Maybe we should go through all these interfaces and see if there are potential risks of partial matching in other places. |
How about switching to https://rdrr.io/cran/xfun/man/strict_list.html? Though I don't know if there will be some overheads. |
I guess |
Somewhere in the R documentation suggests that |
I go through all the interfaces and |
@otherdoug Are you interested in putting up a PR? New contributors are always welcome! |
Sure—I should be able put something together this weekend. |
Fix for #283 - "unexpected '/'" on save
Issue
When saving R script files in Atom,
lintr
called vialanguageserver
output reports an errorunexpected '/'
in line 1 regardless of script content.Otherwise
lintr
output generally works as expected when making inline edits. Further typing without saving runslintr
again, and produces accurate results:Potential cause
The
unexpected '/'
error appears to come from runninglintr::lint
on a file URI that looks like the text of an R script instead of a path to an R script:The did-save / text-sync interface appears to be origin. The interface stores the file URI in
params$textDocument
and stores what I assume is the document content inparams$text
though I have not been able to devise an example that actually stores anything there.languageserver/R/interfaces.R
Lines 378 to 386 in 61259eb
When
text_document_did_save(...)
is called,params$text
partial matches withparams$textDocument
whenparams$text
is undefined. This causescontent
to populate fromstringi::stri_split_lines(text)[[1]]
by splitting the file URI as text, rather than loading the file URI from the pathstringi::stri_read_lines(path)
.languageserver/R/handlers-textsync.R
Lines 63 to 85 in 61259eb
When
lintr::lint
is eventually called oncontent
indiagnose_file(...)
we get theunexpected '/'
error because a file URI likefile:///blah...
isn't valid R syntax, and the unexpected forward-slash is where that's detected.languageserver/R/diagnostics.R
Lines 95 to 97 in 61259eb
Attempted fixes
I've made a hacky substitution of
textContent
fortext
in the two blocks above to avoid partial-matchingtext
withtextDocument
and it appears to resolve the issue. However, I'll be the first to admit I'm not familiar with thelanguageserver
interface, so I don't know what else may be expectingparam$text
to exist.Looking at the surrounding code in
textsync.R
, I also notice thattext_document_did_open
usestext <- textDocument$text
to populatetext
, rather thantext <- params$text
. Perhaps someone more familiar with the spec may be able to say whether this difference is intentional or accidental.languageserver/R/handlers-textsync.R
Lines 5 to 10 in 61259eb
Environment details
I am using Atom 1.48.0 with packages:
Potentially related issues
#250 -- looks like the same lintr error output
The text was updated successfully, but these errors were encountered: