Giter Club home page Giter Club logo

Comments (7)

davidlattimore avatar davidlattimore commented on June 15, 2024 1

There isn't currently, but it's a good idea. Not sure when I'd be likely to get to it though, so if you or anyone else would like to have a try at implementing it let me know and I'll try to provide some guidance

from evcxr.

baiguoname avatar baiguoname commented on June 15, 2024

I have tried to read HOW_IT_WORKS.md and source code several times before, but by lack of familiarity with rust, the command_context.rs is still like a magic to me for now. Could you give me path of learning how it works? Before I read the source code, should I know the detail of how rust-analyzer works?

from evcxr.

davidlattimore avatar davidlattimore commented on June 15, 2024

Yep, I suspect most of the work would likely be figuring out how to get the information out of rust-analyzer.

The evcxr code that uses rust-analyzer is in rust_analyzer.rs. Having a look through that is probably worthwhile to see how it's working.

Looking at rust-analyzer, I think the code that shows documentation is in hover/render.rs

There's two options I can see.

  1. Generate some rust code containing the snippet that's after the :doc command, then call Analysis::hover
  2. Query the definition of MyStruct using something like Semantics::resolve_path then call some other methods to get the docs from the definition.

from evcxr.

davidlattimore avatar davidlattimore commented on June 15, 2024

Another useful thing to look at would be how completions work. In particular, look at the completions method in eval_context.rs. I suspect integration with hover could work in a similar way.

If you have any questions, do ask.

from evcxr.

baiguoname avatar baiguoname commented on June 15, 2024

I write a method hover_info righter after the mothond completions of RustAnalyzer in rust_analyzer.rs:
图片
And then I try print out to find what can I get from this method in eval_context.rs, like this:
图片
The input code is this:
图片
But the hover_info can't get anything, while method completion works fine. I cann't figure it out, can you give me a clue?

from evcxr.

davidlattimore avatar davidlattimore commented on June 15, 2024

Maybe use code.user_offset_to_output_offset(offset) like is done in completions. If you use that for the start and end of the identifier that you're trying to get the hover for, then hopefully you'll end up with offsets that rust-analyzer will be able to make use of.

Have a look at the completions method in eval_context.rs, which calls completions in rust_analyzer.rs. The one in eval_context.rs does stuff like calling self.analyzer.set_source(code.code_string())?; which is important for making sure you're analyzing the code that the user wrote.

from evcxr.

davidlattimore avatar davidlattimore commented on June 15, 2024

Just wanted to say, nice work implementing this @baiguoname, it's a neat feature! (PR)

from evcxr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.