xndcn/symbols-tree-view

Extension for R?

Opened this issue ยท 19 comments

Hi,

I see it won't work for R. Is there any way to extend it? I would be happy enough if it could just detect the function definitions which follow the format <- function (...)

Thanks!

Based on this answer I have added (experimental) support for R in my experimental fork package. You can try it (caution, disable symbols-tree-view then install symbols-tree-nav; once done, when you want to get back to symbols-tree-view, disable symbols-tree-nav before re-enabling symbols-tree-view). I am not sure it will work, I don't know R and cannot try it myself.

Second reason why I am not sure it will work is that I don't know what use symbols-tree-view makes of the .ctags file. So, if you still get the same result with symbols-tree-nav, you might yet have an alternative to get it to work if you have an alternative ctags parser. If it's not already installed, you can install exuberant ctags (should be already installed if you use Linux) and provide its path in the symbols-tree-nav's setting "AlternativeCtagsBinary" (the last one, in the bottom). On my Linux box, this path is /usr/bin/ctags.

Tell me if it works with symbols-tree-nav:

  • without the need of an alternative ctags parser (then I'll create a PR on symbols-tree-view),
  • or only when using the alternative ctags parser,
  • or if it does not work at all (would be sad, but don't know what I could do more :-/ ).

Wow this is terrific @nicolashainaux ! I wasn't expecting such a fast response. It will help me immensely. I will give it a try right now!

@nicolashainaux It does seem to work! But it currently doesn't show the icons so it is still a bit tricky to navigate. Would showing the icons be something minor? I just got started on atom 2 days ago so I don't know much about it. In fact I am not sure myself of what this plugin (the original) supposed to list. I see functions, variable assignments and some imports. Insofar, it seems to be capturing them but a bit hard to diagnose without the icons.

Here is a screenshot:

screenshot 2017-04-01 19 16 30

screenshot 2017-04-01 19 16 43

One way or the other, much better than an entire blank panel! Thanks a bunch!!

Do you mean the icons are gone with symbols-tree-nav? Can you check the "Show Icons" option is on in symbols-tree-nav's settings? (It should be, by default, the same as symbols-tree-view behaviour).

Also, you can attach a R file to test, so I can see what happens.

It is enabled (that is why the python tab has it in one window). Any other ideas why it wouldn't show just for R?

It may have something to do with the icon classes, and maybe the parser results. I would need to check whether it's related to the changes I have done in symbols-tree-nav or not.

To get a precise idea, I would need a R file. Could you post one? Then I could check if I get the same problem here or not, and maybe discover why.

Sure!

Here is the one I have been taking screenshots of:

https://gist.github.com/carlosviansi/f7bb4b8875ae80b7fac8ed45088e1879

OK, so, same problem shows up both in symbols-tree-view and symbols-tree-nav. I investigate further...

Problem is not too complicated: the parsers return tags that match no icons. So, to support R language, there's more than this simple langdef addition in ctags file. I will add a small patch in symbols-tree-nav to handle:

  • Functions tags as function,
  • globalVar, GlobalVars, functionVar, and FunctionVariables as variable (maybe that will be not enough accurate, but so far, there is only one icon for variables)

As to library and source tags, there are no icons, so I can by default let the namespace icon be used for them. It would be better to add proper library / source icons.

With symbols-tree-nav, Show Icons enabled, Colors From Syntax Theme enabled and the alternative exuberant ctags parser I get this on your example file:
capture d ecran_2017-04-02_10-49-12

(the default parser lists almost all items, don't know if it's practical to use).
Neither of these parsers properly gives trees representations (like the variable belonging to functions could be folded inside functions etc.). If anyone knows of a good one, it could be used to parse r files (maybe tweaking the AlternativeCtagsParser option?).

Note that you can use custom colors instead of the default ones from syntax theme (and set a different color for icons or no-icon view, see here).

As this is only a dirty patch (only checking and arranging things if language is r), I will not create a PR for symbols-tree-view (the best would be to add the proper icons). (Moreover I need to rework on my forked version of symbols-tree-view in order to be able to create PRs now...).

Moreover the R tags make the use of context menu (right click in the panel) not very effective. There's some more work to deal correctly with it.

If that's still better than nothing as it is now, I will release a new symbols-tree-nav patch. Tell me.

Looks terrific! I look forward your release. Please let me know when you do! I think this is more than enough for me to navigate this code with easy :-) As you can see there is quite a lot of functions and parameters and having a panel like the one you are showing is certainly much faster to make sense (there is a dozen more files like this one!) ๐Ÿ‘ Please let me know when you do it!

That's online. Let me know if if's ok.

I uninstall and install again? I didn't get an update request this time around.

You can press the "Check for updates" button in atom settings (Updates tab).

0.15.1 right? For some reason i still can't see the icons in R!

Yes, 0.15.1. After having performed the update and restarted, it works as in the screenshot above.

I think I was missing the restart. I changed for ctags but it doesn't work with that on my end, despite having it on my OS X on the suggests usr/bin/ctags place. The default does the trick! :-) Thank you so much, you were a life saver on several hours of scrolling in this code sea!

It is sad R is so poorly supported in atom. The highlight of R itself was discontinued too.

Glad I could help and it finally works! Yes, having an extension that allows to navigate easily through the code is precious!
The problems with the parser's binary provided in symbols-tree-view has been spotted by Linux users, and it looks like the one for OS X works fine.
It's sad that there's only a poor support for R in atom. It requires time from a R user, so it's understandable too. I hope there will be someone that will take over R support in atom.

@carlosviansi I have run the universal ctags binary provided by symbols-tree-view in order to know which languages are supported, and R language belongs to the list: $ ./universal-ctags-linux --list-languages so it should be supported by default. Strange, that it was actually not the case.

@carlosviansi Hi, I come back here again because I just updated the patch in the dev branch and will certainly publish it in the next patch release. You can tell me if it still looks alright. Dedicated topic here.