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

Implement c_cpp_properties.json file generator fixes #1201 #1205

Merged
merged 12 commits into from
Sep 30, 2022

Conversation

nx10
Copy link
Contributor

@nx10 nx10 commented Sep 23, 2022

What problem did you solve?

This PR implements a command "Generate c_cpp_properties.json" that generates the file by collecting information from invoking the compiler and from the DESCRIPTION file.
This enables code completion, IntelliSense, etc. for C/C++ files in R packages.

The issue is described in more detail here: #1201

Demo

Code_rcwvV3zBYQ.mp4

TODO

  • This seems to work under Windows and Ubuntu for the projects I tried it with, it should however be tested on more packages and platforms before it's merged.
  • At some point it might make sense to suggest to the user to run this when the Makevars or DESCRIPTION files change.
  • The command could be renamed to something like 'Configure R-extension for C/C++' to be more descriptive.

@nx10
Copy link
Contributor Author

nx10 commented Sep 23, 2022

I just realized: With some packages you need to run ./configure before running the command (and might want to run ./cleanup after) in order to capture all includes and defines. I will add an automation of this later.

Should be working as expected now.

@renkun-ken
Copy link
Member

renkun-ken commented Sep 27, 2022

I came across this tweet which points to /~https://github.com/r-lib/usethis/blob/main/R/vscode.R, but it does not look like general enough. Not sure if it is helpful here.

@nx10
Copy link
Contributor Author

nx10 commented Sep 27, 2022

I came across this tweet which points to /~https://github.com/r-lib/usethis/blob/main/R/vscode.R, but it does not look like general enough. Not sure if it is helpful here.

Thanks, this captures LinkingTo detectives from the DESCRIPTION and general R paths, but this PR also compiles dummy files to capture everything in configure and Makevars (defines, local includes, system dependencies, ...). I imagine the usethis script is meant to be edited manually later.

(I'm not sure why the CI fails, it might be an unrelated issue)

@renkun-ken
Copy link
Member

I tried it with latest httpgd on macOS, and the following file is produced (an empty includePath is present):

{
  "configurations": [
    {
      "name": "Mac",
      "defines": [
        "NDEBUG",
        "BOOST_NO_AUTO_PTR",
        "FMT_HEADER_ONLY"
      ],
      "includePath": [
        "${workspaceFolder}/src",
        "/Library/Frameworks/R.framework/Versions/4.2/Resources/include",
        "${workspaceFolder}/src/lib",
        "/usr/local/include",
        ""
      ],
      "compilerPath": "/usr/bin/clang++",
      "cStandard": "${default}",
      "cppStandard": "gnu++14",
      "intelliSenseMode": "macos-clang-x64"
    }
  ],
  "version": 4
}

with the following error:

image

@nx10
Copy link
Contributor Author

nx10 commented Sep 29, 2022

I tried it with latest httpgd on macOS, and the following file is produced (an empty includePath is present):

{
  "configurations": [
    {
      "name": "Mac",
      "defines": [
        "NDEBUG",
        "BOOST_NO_AUTO_PTR",
        "FMT_HEADER_ONLY"
      ],
      "includePath": [
        "${workspaceFolder}/src",
        "/Library/Frameworks/R.framework/Versions/4.2/Resources/include",
        "${workspaceFolder}/src/lib",
        "/usr/local/include",
        ""
      ],
      "compilerPath": "/usr/bin/clang++",
      "cStandard": "${default}",
      "cppStandard": "gnu++14",
      "intelliSenseMode": "macos-clang-x64"
    }
  ],
  "version": 4
}

with the following error:

image

That has probably to do with the the escaping of the small R code that collects the library paths, I will put it in an R file shortly.

R code is executed at many parts of the extension in different ways, maybe there should be a unified interface for that. If I have time I will prepare a separate PR.

Edit: Should work now. Can you test again?

@renkun-ken
Copy link
Member

If the command is executed in a package that does not require c/c++ compilation (e.g. lintr), the following error shows up:

image

It would be nice to have more understandable error messages regarding such case.

@nx10
Copy link
Contributor Author

nx10 commented Sep 30, 2022

If the command is executed in a package that does not require c/c++ compilation (e.g. lintr), the following error shows up:

image

It would be nice to have more understandable error messages regarding such case.

This is a bug, even when no C/C++ is used, the action should generate a config as you should be able to run it prior to adding C/C++ files.

Can you try again? I don't get this error but have added stricter null checks everywhere (7d4ade3).

A bit off-topic but what's the consensus on tsconfig.json "compilerOptions": { "strict": true }?

Copy link
Member

@renkun-ken renkun-ken left a comment

Choose a reason for hiding this comment

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

I tried it with httpgd, languageserver, and RMariaDB and all work nicely!

LGTM
Thanks for the nice work!

@nx10
Copy link
Contributor Author

nx10 commented Sep 30, 2022

Thank you for your comments and the review!

@renkun-ken renkun-ken merged commit ad20fdc into REditorSupport:master Sep 30, 2022
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.

2 participants