-
Notifications
You must be signed in to change notification settings - Fork 280
Q: racer integration, find_definition usage #422
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
Comments
@birkenfeld: @phildawes mentioned you might have some thoughts on this. |
Hi @jwilm , The &str arg to find-definition is a bit historical and needs cleaning up, I didn't even realise it was still there! Basically racer loads source from disk lazily and is expecting there to be a file there. Recently @birkenfield added a cache for source artifacts in the Session object. The current racer plugins supply a filename and optionally a tmpfile to load the source from. e.g. In the main.rs find_definition() function racer loads source from a tmpfile, using the session let session = core::Session::from_path(&fpath, &substitute_file);
let src = session.load_file(&fpath);
let pos = scopes::coords_to_point(&src, linenum, charnum);
core::find_definition(&src, &fpath, pos, &session).map(|m| match_fn(m, &session)); I think the way to solve your problem is to load the source text into the session before calling find_definition. You'll probably want to add a new method to Session to load source text if that is how racerd is going to work. |
Btw, I agree re: Having said that, panic backtraces are really handy, especially if you compile with debugging to get line numbers. |
Good news, everyone! I've made some serious progress on racerd and the YCM integration. Here's a quick completion demo. Of course, this wouldn't be possible with all the work you've done here on racer; thank you! There is one challenge I've run into that may not be a simple fix. One thing that I've done in racerd is keep a The problem here is that I cannot get a mutable reference to the Do you guys have any thoughts on how to make this work and keep the niceness of using an Thanks again! |
Hi @jwilm, This looks awesome! |
Well, the point of the In a long running process, I think you'll have to use a two-layered structure: an object (that we don't have currently) that is kept alive between requests, and an object (like the Session) that persists throughout one request. One way I can think of right now is to have the arena append-or-invalidate-only during a request, and to clean it out after/before the next one, in the code that mutably owns the cache. This likely requires a specialized |
@birkenfeld is the idea with the two-layered object is that we know no references are handed out once the Session is destroyed? That's the issue I keep coming back to with a mutable file cache in the current setup. |
Yep, that's the idea. |
I started looking into separating out the FileCache and Session as a proof-of-concept before going and making an Arena with recyclable members, and I ran into some unexpected lifetime errors. Here are the changes. The
The lifetime issues are surprising in the first place since the find_definition doesn't return a reference to anything. Normally I would go through a little more trial and error to figure out the problem, but updating all of the tests for each change is cumbersome even with vim macros. I appreciate any time you can spare to look at this. Thanks! |
The issue is that the SessionRef type is defined as A (possible) fix is here: https://github.com/birkenfeld/racer/tree/wip-reusable-cache (I would probably further rename the |
Actually, once you untie these two lifetimes, there is no reason for SessionRef to exist anymore, and it can just be |
ugh! I looked right as SessionRef and didn't think anything of it 😳 Thanks for helping with this @birkenfeld; you saved me a lot of time banging my head against the wall 😁. |
I have a prototype of reusable allocations implemented within the This approach has a soundness issue; since the The next step here is where I struggle a bit. We need an arena implementation which supports the What do you guys think? |
Closing this since all of the discussions have been resolved. Will open new issues as necessary. Thanks again for all the help. |
I recently started integrating racer for YouCompleteMe support, and this is the first of what I'm sure will be many questions 😄. This question regards
find_definition
.One of the arguments is a source buffer. If I don’t write the buffer to disk first, I get a panic (full bt below).
However, writing the buffer to disk completely resolves that problem. It seems to me that, given a buffer, reading the initial file should be unnecessary. Is this a requirement? I would like to change the behavior to not do that if possible. I actually couldn’t find where it was doing that IO, either. Additionally, since this method is doing I/O, maybe it should return a Result instead of panicking while indexing a slice.
Backtrace
The text was updated successfully, but these errors were encountered: