-
Notifications
You must be signed in to change notification settings - Fork 162
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
feature request: xref jump to C source for function if src installed #499
Comments
I might be able to take a stab at this next week if it was deemed worthy. |
how would you find out which |
I guess https://github.com/jimhester/lookup is able to do it so it should be possible. Then you just need a TAGS file in the R source and use xref to jump to the right definition. |
you're right, I currently use a TAGS file generated with universal-ctags and it doesn't always jump to the correct locations to be sure. It does seem to do a pretty decent job though, and the xref interface to list possible jump points is pretty helpful. Honestly, I haven't really thought to through to much, I just thought it would be a pretty sweet feature. The R source follows a pretty standardized naming scheme right? Would it be good enough to use the naming scheme to determine jump points? |
I don't think so.
Agreed it would be nice. I guess for internal functions you'd first jump to the closure wrapper in |
Ok that's a bummer, I had thought there was a convention as you mentioned previously like |
I think this might be a huge complication. I would prefer to keep tags separately from our xref backend. TAGS could be anywhere and multiple tag files (R sources + package sources) could be active at the same time. Users might have several versions of R source repo lying around etc. We really don't want to get into tag file management. There have been endless discussions on emacs devel about how to properly aggregate backends and the crux is that it's not possible to have a satisfactory solution. Add to this that either functions could be named identically in R and C code or, there is no perfect mapping between R and C level symbols and various indirections exists (core R do_ scheme or exports automatically generated by Rcpp) and one quickly ends up in a mess. So my suggestion would be to stick with different shortcuts for different lookup mechanisms (I use |
There should be only one kind of TAGS file in the R-source (for C files) so I don't think that's where the difficulty lies. There would be no xref disambiguation menu in the scheme I'm imagining. But how do you map the base function symbols to their R source, and how do you find out about the relevant C symbol is the hard part. As for compiled code in packages that's another separate messy issue, but here again the difficulty is not xref but finding out about relevant symbols. |
One for R itself, one for each package. I have always multiple tag files loaded at the same time.
I use same function names in C files and R wrappers. So does Rcpp::compileAttributes when generating exports. So, for 99% of the users who develop with Rcpp the disambiguation menu will pop up. When you are on .Internal(print.default(x, digits, quote, na.print, print.gap, do you want to src of R's
"Relevant" in what sense? Do you have in mind jumping from R code from .Call or .Primitive invocations? If so, then I could see how current xref etags backend could be improved a bit by falling back on apropos and searching for the partial match at point (not always works, as with
Most of the users will be interested in C/C++ locations of their packages and not not in R sources. So, if implemented, it should first work within current package as the baseline.
It's not a problem with xref as long as you use it for one type of lookup, but once you start using it for a bunch of things which are impossible to disambiguate from context then you quickly end up with problems or, in best case scenario, with a disambiguation menu. |
We'd detect Given how good srcrefs lookup is, I'm thinking typical workflow would never rely on R symbols in a TAGS file ad there'd only be one such files relevant at any moment. I no longer think we need to combine the xref backends to have a good workflow.
I agree package lookup is more useful but if someone wants to implement R lookup they're welcome to do it. |
We could also detect Edit: And then we can have an option to automatically rejump from there. And if you wanted to see the closure wrapper you'd run |
Also jumping on the right entry of the definition table in |
This could be doable if we could identify package from where the symbol originates. PACKAGE arg is optional in .Call. Please take into account what happens when
Combining backends or doing it ourselves, we have to solve same issue - how to combine and disambiguate. By "disambiguation menu" I meant how do we make distinction between R symbol and C symbol with the same name within our own backend. I might want to jump to
Not all functions using .Call are wrappers. Some might use multiple .Calls.
Then let's stick to this minimal plan. Let's make C symbol lookup within current package work first. Ideally with automatic TAGS generation whenever possible. |
How do you actually jump afterwards? |
By moving the cursor on the function pointer and calling xref gain. In that C file the xref backend uses TAGS. But it's probably easy to write some regex that detects the function pointer and jump automatically. Those tables are well standardised.
Hmm I didn't think of that. But that interface will be deprecated in the long term I think, R is shifting towards native symbol pointers. I think it's ok to only support the new interface.
That doesn't seem like good practice. Is that a widespread idiom? If you're on the R side you can afford one indirection and call a wrapper. Anyway we can detect multiple
My feeling is that we'd actually have better experience by not combining all symbols from different languages. If you're in a R file you'd only get the R symbols, and in a C/C++ file you'd only get the native symbols. Then if we can pull off the UI I suggested above, and you want to go to the native side, you'd jump to the closure wrapper and ESS would automatically get you to the right place on the native side. If you want to jump to a function that is not exposed on the R side you'd just switch to a native file (e.g. with projectile) and jump from there. |
> On Sat, Mar 10 2018 18:21, Lionel Henry wrote:
> Some might use multiple .Calls.
the R side you can afford one indirection and call a wrapper.
Maybe, but a lot of code doesn't use wrappers. You often see long functions with
.Call at the end. The automatic jumping to the .Call inside a function doesn't
sound at all right. If I xref to a function I expect to be placed at the
beginning of it.
My feeling is that we'd actually have better experience by not combining all
symbols from different languages.
Looks like a marginal improvement over what we have right now. xref-etags does a
decent job there.
If you want to jump to a function that is not exposed on the R side you'd just
switch to a native file (e.g. with projectile) and jump from there.
Awkward. To come back to the original point you pop the xref mark and then
projectile again? In my mind such UI and the trickeries which you proposed are
inferior to the simple two-shortcuts solutions what I use currently.
For starters we should have two xref jumpers, one to R and one to native. Once
that's done I am sure we will figure how to combine those and if it makes sense
in the first place.
We could be quite flexible with the native-xref regarding pointer position. For
instance if we are within a function containing .Call we trigger the jump to the
native symbol of the closest .Call, or ask if there are multiple .Calls within
the boundaries of the function.
|
Let's not discuss at length about the details. The important feature is to be able to jump to the right place from a jump within
What you call trickeries I call DWIM. I don't think it's inferior, it's orthogonal. Indeed having multiple keybindings for different xref backends is a legit workflow and trivial to implement. It might make sense to provide keybindings for this in ESS. |
The new support for xref is great. It would be cool if xref would jump to C source as well, as it does in emacs-lisp. For example if an equivalent variable like
C-source-directory
was available to search from.The text was updated successfully, but these errors were encountered: