WolframResearch/vscode-wolfram

'Go to Definition' Support across project

teedr opened this issue · 1 comments

teedr commented

Is this plugin somehow responsible for finding definitions via VSCode's 'Go to Definition'? It seems to work fine within a file, but across a project (especially a project with a wild file structure like mine) it doesn't seem to work. I'm wondering if I can contribute something to either make it work or understand the structure it is expecting currently. Any pointers appreciated.

The VSCode plugin is not responsible per se. The LSPServer paclet is responsible, with the source available here:
https://github.com/WolframResearch/LSPServer

You are correct that it only works within a file and not across a project.

There would be work involved with teaching LSPServer paclet about project structure and how to process the files to get all of the definitions.

The code for hooking up "Go to Definition" is here:
https://github.com/WolframResearch/LSPServer/blob/master/LSPServer/Kernel/Definitions.wl

and relies on the CodeParser paclet to provide the actual definitions:

In[1]:= << CodeParser`

In[2]:= ast = CodeParse["
f[x_] := x + 1
"];
ast[[2, 1, 3, Key["Definitions"]]]

Out[3]= {LeafNode[Symbol, "f", <|Source -> {{2, 1}, {2, 2}}|>]}