castwide / solargraph

A Ruby language server.
https://solargraph.org
MIT License
1.89k stars 158 forks source link

Help Developing Plugin: How can I show integrated documentation of a Pin added by a Convention? #636

Open brettimus opened 1 year ago

brettimus commented 1 year ago

Hi! I am developing a plugin, and I'm not sure if I'm doing things the correct way.

Mainly, I just want to provide additional documentation for certain methods or symbols.

As a first step, I was trying to simply show a tooltip on hover. I created a pin for a token in the AST, and added a random doc string.

I couldn't seem to get anything to show up in the VS Code extension.

I verified that

Whenever solargraph looked for definitions given a cursor position, I noticed that the source_map pins that it looked for did not include the pin that my plugin added.

I was able to resolve this by having SourceMap::Clip#define also consider the pins of the source_map's environment: source_map.environ.pins.

More specifically, I changed the line that I linked to above to be the following:

        result.concat((source_map.pins + source_map.environ.pins + source_map.locals).select{ |p| p.name == cursor.word && p.location.range.contain?(cursor.position) }) if result.empty?

I made this change since all the Pins added by Conventions are stored on the source_map's environ property, but not on the source_map's pins attr. (See: here)

To me, this seems like expected behavior. If my plugin creates a Pin with additional documentation for something in the file, then it should be able to be picked up by the language server, right?

Thanks for reading!