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

VS Code extension is not aware of sources managed by Alire #668

Closed 1ma closed 1 year ago

1ma commented 3 years ago

Scenario

A project bootstrapped by Alire can depend on "crates" from the Alire registry through the usual with "crate.gpr"; statements in your GPR file. Then, if instead of building your project with gprbuild you use alr build, Alire takes care of downloading any dependencies into the project root directory (under alire/) and silently sets the appropriate GPR_PROJECT_PATH for gprbuild so that your GPR file can see and build these sources as if they were in any well-known location of your system.

However, the Ada extension can't see this third party code that lives inside the project's working directory.

Real Example

https://github.com/1ma/radatracer

The repository is organized in 2 project files, one for library code and another for executable programs. The latter depends on the library GPR file and "aunit.gpr", managed by Alire. If we clone the repository and run alr build Alire will download AUnit 21.0.0 under alire/cache/dependencies/aunit_21.0.0_d6561681 and build the executables successfully, including aunit_harness. But if we open VSCode the plugin will show this error, and navigation for AUnit types and functions will not work:

example

(Note: the ada.projectFile setting is enforced to executables.gpr in .vscode/settings.json)

1ma commented 3 years ago

A nasty side effect of this error I didn't notice before: it breaks code navigation for all sources (Ctrl+Clicking symbols).

Edit: In the meantime, using the full relative path to the third party GPR files instead of just with "crate.gpr"; seems to fix the issue. Of course, each time a dependency is updated the path needs to change, too.

example

reznikmm commented 3 years ago

Hello @1ma This issue duplicates #503, I guess. How should ALS find that the project uses alire?

1ma commented 3 years ago

Sorry, I saw it but I thought it was more of a philosophical discussion and didn't want to hijack it with an issue.

Regarding your question, maybe ALS could check if the current project contains any alire.toml file, and do something from there.

Fabien-Chouteau commented 3 years ago

Alire has a alr edit command that can start you favorite editor in the context of the crate. The default is to use GNATstudio, but you can configure it to start VScode. If that helps.

pyjarrett commented 3 years ago

I've been using alr config --set editor.cmd "code ." pretty successfully, since it sets the environment prior to startup, including GPR_PROJECT_PATH. The big issue I run into is that the GPR project file for the extension is per-workspace, so I have to change the GPR when I work on different projects, but it works well when it is set.

pyjarrett commented 2 years ago

@Fabien-Chouteau is it possible to set up a way to feed the project-specific GPR from Alire to the extension? I'd like to make a "Modern Ada with Alire" tutorial, but hand-modifying the project GPR on a per-project basis is a bit rough of a stumbling block for new programmers, and an irritant to more seasoned programmers.

0rzech commented 2 years ago

IMHO, it would still be better to make ALS Alire-aware. The reason are polyglot IDEs and editors. Launching such programs with a language-specific command seems a bit awkward, given one can switch to an entirely different kind of project inside running a instance. Also, many people launch IDEs and editors with GUI launchers and such workaround forces these people to alter the launchers or to create command aliases. @1ma's suggestion to detect alire.toml seems the right way to do it. At least this is how rust-analyzer does it with Cargo.toml, AFAIK.

reznikmm commented 1 year ago

Please try VS Code Ada extension 23.0.15. It should work now.