How to have RStudio recognize CUDA .cu files as C++?

I've been getting into mixing C++ with R again lately, now starting to work with CUDA. I'd like to continue using RStudio as my IDE, even when doing purely C++/CUDA things. The terminal works well enough for running the nvcc compiler on CUDA code, but the compiler does insist on files ending in .cu instead of .cpp in order to compile correctly. Unfortunately RStudio does not recognize that .cu files are essentially C++ so I get no syntax highlighting or code completion. Is there a config somewhere that I can just add the .cu extension to be treated the same as .cpp?

Digging into the source code on GitHub, might have found a place to add it, right after this line:

Maybe like this?

public static final TextFileType CU = new CppFileType("cu", ".cu", new ImageResource2x(ICONS.iconCpp2x()), true, true);

Now I'm tempted to download the source and try it, but it seems like RStudio IDE is a pretty big project for me to go building from source just to try out a feature I want.

If you use Linux and have Docker installed, you can build from source with one shell command. More here:

We also welcome PRs! :slight_smile:

Well I had been meaning to try out Docker, so I went for it. I did the first build without changing any source and installed the .deb and everything worked, but then I added the line I suggested above and re-built and re-installed the .deb and nothing changed -- a .cu file still just looks like plain black and white text with no auto-completion or other decorations that normally go with c++/R files, like the code tools wand or the source button.

It feels like this line is part of the solution but it also needs something added somewhere else. I'll keep poking around but if anyone has any suggestions I'd appreciate it. I'm also thinking the source button and source on save wont actually work unless I can get this filetype to point to the nvcc compiler instead of g++. That is a secondary concern, but if I'm going to do a pull request probably should get that functionality happening too.

And if I had just scrolled down in that very same file it appears I should be adding a line around here as well:

And still probably some more to-do beyond that, I'll keep at it..

Here's a commit I made a couple of months ago that you can use as a template (it adds a new file extension and doesn't do much else).

1 Like

Thank you, Jonathan. That did help me find a few more edits to try but for some reason .cpp files have code completion while .cu files still do not. My changes did manage to get code highlighting working, just not the completion. I'll revisit it at some point I'm sure but moving on for now.

Meanwhile, I am greatly enjoying building and re-building RStudio, tweaking the UI colors and such, so thank you for that! I went from the blue palette to an earthy brown..

1 Like

I'm hoping to tinker with the UI styles a bit once I submit, so I'm keen to see you go with that, @brianstamper :smiley:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.