AdaCore / ada_language_server

Server implementing the Microsoft Language Protocol for Ada and SPARK
GNU General Public License v3.0
229 stars 54 forks source link

[Bug]: Editing source from another (dependency) project within the same workspace is painful #1201

Open Lucretia opened 1 month ago

Lucretia commented 1 month ago

Environment

Bug Summary and Reproducer

Bug Summary: Keep getting failure popups and crash logs to console

Steps to reproduce: Create a workspace, set the project gpr to the main project, add dependencies, edit source from dependency.

Expected behavior: I expect it to work as normal.

Configuration and Logs

... (too much to log)
[Error - 00:10:25] Request textDocument/documentSymbol failed.
Error: selectionRange must be contained in fullRange
    at f.validate (/home/laguest/opt/VSCode-linux-x64/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:152:18197)
    at new f (/home/laguest/opt/VSCode-linux-x64/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:152:18411)
    at qt (/home/laguest/.vscode-insiders/extensions/adacore.ada-24.0.6/out/src/extension.js:65:72241)
    at qt (/home/laguest/.vscode-insiders/extensions/adacore.ada-24.0.6/out/src/extension.js:65:72418)
    at o (/home/laguest/.vscode-insiders/extensions/adacore.ada-24.0.6/out/src/extension.js:65:46654)
    at Object.WL [as map] (/home/laguest/.vscode-insiders/extensions/adacore.ada-24.0.6/out/src/extension.js:65:46740)
    at Object.yr [as asDocumentSymbols] (/home/laguest/.vscode-insiders/extensions/adacore.ada-24.0.6/out/src/extension.js:65:72208)
    at u (/home/laguest/.vscode-insiders/extensions/adacore.ada-24.0.6/out/src/extension.js:69:56048)
    at async f.provideDocumentSymbols (/home/laguest/opt/VSCode-linux-x64/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:154:98866)
[Error - 00:14:45] Request textDocument/documentSymbol failed.
Error: selectionRange must be contained in fullRange
    at f.validate (/home/laguest/opt/VSCode-linux-x64/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:152:18197)
    at new f (/home/laguest/opt/VSCode-linux-x64/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:152:18411)
    at qt (/home/laguest/.vscode-insiders/extensions/adacore.ada-24.0.6/out/src/extension.js:65:72241)
    at qt (/home/laguest/.vscode-insiders/extensions/adacore.ada-24.0.6/out/src/extension.js:65:72418)
    at o (/home/laguest/.vscode-insiders/extensions/adacore.ada-24.0.6/out/src/extension.js:65:46654)
    at Object.WL [as map] (/home/laguest/.vscode-insiders/extensions/adacore.ada-24.0.6/out/src/extension.js:65:46740)
    at Object.yr [as asDocumentSymbols] (/home/laguest/.vscode-insiders/extensions/adacore.ada-24.0.6/out/src/extension.js:65:72208)
    at u (/home/laguest/.vscode-insiders/extensions/adacore.ada-24.0.6/out/src/extension.js:69:56048)
    at async f.provideDocumentSymbols (/home/laguest/opt/VSCode-linux-x64/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:154:98866)

Other VS Code Extensions

No response

Additional context

No response

AnthonyLeonardoGracio commented 1 month ago

Hello @Lucretia,

It would be useful to have the logs of the Ada Language Server itself, in order to know what the server's response on textDocument/symbol request. For that, just create a ~/.als/traces.cfg file with the following contents:

>ada_ls_log.$T.log:buffer_size=0
ALS.MAIN=yes
ALS.IN=yes
ALS.OUT=yes

This will produce ada_ls_log.<timestamp>.log files for each Ada Language Server instance that is launched (one for Ada code, another one for GPR files). Could you try to reproduce the failures once you have created this traces.cfg file and send us the logs?

Regards,

Lucretia commented 1 month ago

You might want to look near the end as it wasn't until then I tried F12 on the GL.Convert symbol, which is from another project in the workspace.

You can find the source here. I've been working from the ch2/<dir> project dirs.

als-logs.zip

AnthonyLeonardoGracio commented 1 month ago

Hello,

In one of the logs I see:

[ALS.MAIN] GPR2.PROJECT_ERROR - /home/laguest/src/mine-new/self-learning/cgpiogl/ch2/2.4_files/./filesgpr: fatal error, cannot load the project tree
[ALS.MAIN] [/home/laguest/.vscode-insiders/extensions/adacore.ada-24.0.6/x64/linux/ada_language_server]
...
[ALS.MAIN] /home/laguest/src/mine-new/self-learning/cgpiogl/ch2/2.4_files/./filesgpr project file "/home/laguest/src/mine-new/self-learning/cgpiogl/ch2/2.4_files/./filesgpr" not found

So it seems that the path your have specified for ada.projectFile does not exit (at least the server does not find it). I would suggest to double-check that first, it might be the primary cause for the requests' failures.

Regards,

Lucretia commented 1 month ago

Yeah, I fixed that. But the error I reported was NOT on that project, it was on the earlier ones, where the GPR file was correct.

Lucretia commented 1 month ago

I suggest you grab my sources, add sdl, then open the ch2/<project>/.vscode/?.code-workspace then try to edit gl.ads, just add something at the end. You'll get no end of popups with errors in them.

AnthonyLeonardoGracio commented 1 month ago

I am missing a lot of dependencies in order to properly load your sources, it would be great if you could attach a self-contained archive, or at least tell me how to grab all the missing dependencies.

Lucretia commented 1 month ago

You don't need sdlada_image, just delete that from toml.

You can uncomment the url line for sdlada and it should build, that is the only dependency. The opengl source is within the same repo, ../../ back.

AnthonyLeonardoGracio commented 1 month ago

And where can I find with "config/first_config.gpr";, which is included for instance in ch2/2.1_first/first.gpr ?

Lucretia commented 1 month ago

That's generated by alire.

AnthonyLeonardoGracio commented 1 month ago

It still fails after uncommenting the sdlada line and doing alr build. Please provide a smaller reproducer, either based on Alire or not, but that works from scratch: it will make debugging way easier for us.

Lucretia commented 1 month ago

Did you remove the other sdlada line with the path?

Lucretia commented 2 weeks ago

An easier way for you to test is to create a project, open it in vscode, add a dependency and then add that dependency as a folder within the workspace, then try to get any kind of assistance, auto-complete, go to symbol, etc. Won't work.

AnthonyLeonardoGracio commented 1 week ago

An easier way for you to test is to create a project, open it in vscode, add a dependency and then add that dependency as a folder within the workspace, then try to get any kind of assistance, auto-complete, go to symbol, etc. Won't work.

Add a dependency in the Alire .toml file?

Lucretia commented 1 week ago

In my case it was a dependency on the project added to the workspace, so I could edit that at the same time.

AnthonyLeonardoGracio commented 1 week ago

In my case it was a dependency on the project added to the workspace, so I could edit that at the same time.

if you add anew dependency you should reload the project from VS Code, otherwise the navigation won't work: this is expected. Also you should make sure to set the ada.projectFile setting, in order to specify what root project the Ada Language Server should use if there are multiple .gpr files in the same workspace

Lucretia commented 1 week ago

This isn't hard. Just try it. Create a project, add sdlada (or some other project) as a dependency, then add them both into the workspace, and set the gpr profect in settings, try editing the project which isn't the main one.

AnthonyLeonardoGracio commented 1 week ago

If we ask for a detailed reproducer it's because what you are describing works fine in usual cases, as you can see in the attached screenshot: here I have a default.gpr root project (located in a folder called basic_prj) that imports a to_import.gpr project file located in another directory (../to_import). I have then added the imported project's source directory in my workspace as you have described (via the Ada: Add Missing Source Directories To Worskpace command).

Screenshot 2024-09-02 at 11 59 17

I can perfectly edit the imported project's sources: I have completion, tooltips and all other expected features. So there must be something specific with your configuration: having a proper reproduced with detailed steps (or a self containex archive) would greatly help. I understand that it's some work for you and I am very sorry for that, but it would be hard to solve that issue otherwise.