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

Text of non-'.Rmd' markdown files is analyzed as R code #930

Closed
allefeld opened this issue Jan 3, 2022 · 9 comments · Fixed by REditorSupport/languageserver#511
Closed
Labels

Comments

@allefeld
Copy link

allefeld commented Jan 3, 2022

I would like to use the VSCode R extension to "knit" plain Markdown files in addition to R Markdown files. To do so, I associated the file extension md with the R Markdown language. In settings.json:

    "files.associations": {
        "*.md": "rmd"
    },

That works, and I can now press Ctrl+Shift+K to knit the document.

However, I get a strange linting (?) error:

image

It seems to be triggered by short words, but only by the first one in the text, later repetitions are ignored.

In this case, the error details are

[{
	"resource": "/home/ca/Store/lab/pandoc-ng/notes.md",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "unexpected symbol",
	"source": "error",
	"startLineNumber": 1,
	"startColumn": 6,
	"endLineNumber": 1,
	"endColumn": 7
}]

Hovering over the word opens documentation for the R function is(object, class2). It therefore appears as if the text is analyzed as R code?

This interpretation is supported by another observation: If I write a few letters and then activate suggestions (e.g. by Ctrl+Space) I get R-language suggestions:

image

Describe the bug

The text of non-'.Rmd' markdown files is analyzed as R code

To Reproduce
Steps to reproduce the behavior:

  1. Create a file with the extension .md and open it.
  2. Associate .md with the language rmd
  3. Write "what is this".
  4. A red squiggle appears under "is".

Do you want to fix by self? (We hope your help!)

I tried to simply disable linting, but couldn't find an option to do so.

(If yes,) what kind of help do you want? (e.g. Which file should I fix, Survey (related documents)

Since this same behavior does not appear for .Rmd files, I suspect that some kind of exception is hard-coded for this file extension. I propose to create an option which allows to configure which file extension(s) are excepted. This would allow to use Markdown processing to be used in VS Code in the same way as it can be used in RStudio.

Environment (please complete the following information):

  • OS: Debian 11.2
  • VSCode Version: 1.63.2
  • R Version: 4.0.4
  • vscode-R version: 2.3.5
@allefeld allefeld added the bug label Jan 3, 2022
@renkun-ken
Copy link
Member

Currently, the language server uses file extension to determine if a file is rmd. If you are editing an rmd, is there a reason you don't use .Rmd but .md?

@allefeld
Copy link
Author

allefeld commented Jan 5, 2022

Currently, the language server uses file extension to determine if a file is rmd.

I understand that the R language server would not treat a file as R Markdown which it does not detect as R Markdown (based on the extension). But why would it treat it as R code (instead of simply not treating it at all)?

Also I think that's somewhat at odds with the language logic in VS Code. File extensions are used to detect languages, but they don't define them. Apart from explicit association of another extension in the configuration, there is also the language chooser in the status bar. This choice should ultimately determine how a file is processed.

If you are editing an rmd, is there a reason you don't use .Rmd but .md`?

A Markdown file that doesn't contain code chunks is not really an Rmd file, it would be semantically wrong to use that extension.

You may say that the extension is not meant for pure Markdown, but the functionality in RStudio (based on rmarkdown) does support editing & processing md files. Is that not the intention, to have the same behavior in both environments?

@renkun-ken
Copy link
Member

I understand that the R language server would not treat a file as R Markdown which it does not detect as R Markdown (based on the extension). But why would it treat it as R code (instead of simply not treating it at all)?

It is because language server treats .Rmd as r markdown file, or otherwise as R file.

In VS Code API, each document (not necessarily a stored file but also untitled document) is associated with a language, in this case rmd. In the language server, we currently are not using the document language.

I check the Language Server Protocol, and we do have access to the language of the document. I think we should respect it if it is specified before checking the document file extension.

A Markdown file that doesn't contain code chunks is not really an Rmd file, it would be semantically wrong to use that extension.

Yes, you are correct. Once we respect the document language via lsp, then the problem should be automatically resolved.

@allefeld
Copy link
Author

allefeld commented Jan 5, 2022

Thanks! It appears that new issue on languageserver covers it, should I close this one?

@renkun-ken
Copy link
Member

No need to close this one. Will close both together in the PR.

@renkun-ken
Copy link
Member

Would you like to try installing REditorSupport/languageserver#511? It should work now.

@allefeld
Copy link
Author

allefeld commented Jan 6, 2022

I would, but I don't know how to install the unpublished modified version of an R package.
Do I just clone renkun-ken/languageserver into ~/.local/lib/R/languageserver?

@renkun-ken
Copy link
Member

Just run the following in your R terminal:

remotes::install_github("REditorSupport/languageserver#511")

@allefeld
Copy link
Author

allefeld commented Jan 6, 2022

The linting error does not occur anymore.

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants