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

Accessing VS Code settings in R #743

Merged
merged 17 commits into from
Aug 11, 2021

Conversation

ElianHugh
Copy link
Collaborator

@ElianHugh ElianHugh commented Aug 6, 2021

proof of concept

This PR allows loading R-related vsc settings in R. This reduces the reliance on
setting options in the .Rprofile, and means that you don't need to have settings that have no effect outside of VSC-R. This also allows maintainers to restrict invalid inputs.

This could also be used for increased customisation E.g., as outlined by @renkun-ken, this could be extended to modify .Rprofile execution order

Note: .Rprofile settings (intentionally) have higher priority over VSCode settings, and will overwrite when necessary

Caveats:

  • The default value of a setting must be identical to the R option default, as VSCode settings are not written to the settings.kson unless the default value is changed.
  • May require an environment term to locate the settings.json in some cases
  • Could have issues with malformed settings.json files

Screenshot

image


Note: this PR is a proof-of-concept, and is a little rough around the edges. I'd love to hear whether this is something that is useful, and any ideas/issues with the implementation

ElianHugh and others added 4 commits August 5, 2021 22:12
@ManuelHentschel
Copy link
Member

Is this meant to completely replace/overwrite the options set in .Rprofile?

@ElianHugh
Copy link
Collaborator Author

Is this meant to completely replace/overwrite the options set in .Rprofile?

I think ideally this would just be a more user-friendly way of setting options, and would be overwritten by the user's .Rprofile options

R/init.R Outdated
# Attach to vscode
exports$.vsc.attach()

# Import VSC-R settings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some settings (e.g. vsc.plot, vsv.use_httpgd, vsc.rstudioapi) must be set before the init.R is sourced.

@renkun-ken
Copy link
Member

I move loading settings from init.R after attach to vsc.R before any option is used (e.g. vsc.plot, vsc.use_httpgd).

Also, each time attach() is called, the settings are loaded again so that some settings could take effect immediately (e.g. vsc.str.max.level, and those view column settings).

R/vsc.R Outdated
# settings.json can result in errors if read via fromJSON
vsc_settings <- suppressWarnings(
unlist(
jsonlite::fromJSON(paste(readLines(settings_file), collapse = ""))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use jsonlite::read_json()? Could you provide a case where "settings.json can result in errors if read via fromJSON"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think this was fixed since relying on the ~/.vscode-r settings.json. Can no longer replicate issues with readJSON

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Let me refine the code a bit so that naming conventions are more consistent.

@renkun-ken renkun-ken marked this pull request as ready for review August 11, 2021 01:51
@renkun-ken renkun-ken changed the title *Proof of concept* accessing VSC settings in R Accessing VS Code settings in R Aug 11, 2021
Update the viewColumn item's description
@ElianHugh
Copy link
Collaborator Author

Thank you for updating the code @renkun-ken, it's working quite nicely now!

@ManuelHentschel
Copy link
Member

Works nicely, thanks!

@renkun-ken renkun-ken merged commit 6d3590b into REditorSupport:master Aug 11, 2021
ElianHugh added a commit to ElianHugh/vscode-R that referenced this pull request May 12, 2022
* PoF accessing VSC settings

** proof of concept **

Load R-related vsc settings and set as R option

* Update getSettings.R

* Fiddle with configurations

* Setup example usage

* Write settings.json to .vscode-R folder

* Source vscode settings first

* Move import back to init, only replace ops if null

* Update package.json

* Descriptive names, move settings under categories

* Change setting names

* Load settings before attach

* Refine load_settings

* Fix

* Update viewColumn setting

Update the viewColumn item's description

* Minor typos

* Use expression mapping

* Use quote list

Co-authored-by: Kun Ren <[email protected]>
Co-authored-by: Manuel Hentschel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants