AdaCore / ada_language_server

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

Override toolchain to work with Alire #1063

Closed Joebeazelman closed 1 year ago

Joebeazelman commented 1 year ago

Environment

OS and Version: MacOS 12.6 (21G115) VS Code Version: 1.72.2 (Universal)

Issue

The Ada extension can't build the project because it's unaware of Alire's environment variables. To get around this issue, I overrode the extension's default task to call Alire instead (see Configuration below).

So far, the project builds, but unlike extensions default build task, whenever there's a build error, clicking on any of the errors results in VSCode claiming it can't find the file with an option to create it. I also overrode the extension's ProblemMatcher inside my build task to use a relative location as displayed in the error message, but it still cannot find them. Oddly enough, option clicking from in the terminal window works flawlessly. What could be the problem? This is a major issue for developers working with Alire and VS Code.

Configuration


{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "alire: Build project",
      "command": "alr",
      "args": ["build"],
      "problemMatcher": {
        "base": "$ada",
        "fileLocation": ["autoDetect", "${workspaceRoot}"]
      },
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}

Here's my workspace file (located inside .vscode folder in root of project):

{
  "folders": [
    {
      "path": "../"
    }
  ],
  "settings": {
    "ada.projectFile": "main.gpr",

    // Set a workspace-specific environment for Linux/OSX platforms
    "terminal.integrated.env.linux": {
      //  Set MAIN_NUMBER scenario variable to MAIN_2 directly from the environment
      "MAIN_NUMBER": "MAIN_2",

      //  Optionally, you can append the Ada toolchain of your choice to the PATH environment variable
      //  if you want to use a different toolchain.
      //  "PATH": "<PATH_TO_TOOLCHAIN>:${env:PATH}",

      //  Append the path to the directory containing print_utils.gpr project file dependency to
      //  the GPR_PROJECT_PATH environment variable
      "GPR_PROJECT_PATH": "./imported:${env:GPR_PROJECT_PATH}"
    }
  }
}

Originally posted by @Joebeazelman in https://github.com/microsoft/vscode-cpptools/issues/10021

AnthonyLeonardoGracio commented 1 year ago

Hello @Joebeazelman ,

We plan to integrate Alire to our VS Code extension during the next months. Basically we want it to be trasnparent for users: if we detect an Alire project in the workspace, we set everything that is needed (environment etc.) to make it work out of the box.

We'll let you know once it's implemented.

Joebeazelman commented 1 year ago

Thanks. I already have it working with Alire.

AnthonyLeonardoGracio commented 1 year ago

Yes (and congrats for this!) but we want it to be more "plug-and-play" let's say ;)

Joebeazelman commented 1 year ago

In the meantime, it would be nice if there were workarounds. I figured out how to build in VSCode using Alire, but the issue with setting the environment variables is still a pain. The Ada extension requires a number of environment variables that are not set unless the user launches the project using "alr edit." If I at least know what variables the extension is looking for, I could at least implement a fix.

GavinRay97 commented 1 year ago

Just out of curiosity, based on this comment:

      //  Optionally, you can append the Ada toolchain of your choice to the PATH environment variable
      //  if you want to use a different toolchain.
      //  "PATH": "<PATH_TO_TOOLCHAIN>:${env:PATH}",

If I have a source-built GCC toolchain at /usr/local/gcc-dev that isn't on my path, would adding it in this way make it override and take precedence?

TamaMcGlinn commented 1 year ago

If I at least know what variables the extension is looking for

alr printenv is your friend

Joebeazelman commented 1 year ago

I've been working with the version of ALS for Visual Studio and it's a great improvement! Keep up the good work! While it no longer requires executing "alr edit" before launching Visual Studio, it still doesn't build the project using Alire. The documentation says you should execute Alire from a shell, so I added the following configuration to my tasks:

{
    "version": "2.0.0",
    "tasks": [
     {
          "label": "Alire Build",
          "type": "shell",
          "command": "alr build -- -cargs -gnatef",
          "group": {
              "kind": "build",
              "isDefault": true
           },
           "problemMatcher": {
                "base": "$ada"
           }
       }
    ]
}

Now, Alire finally works seamlessly with VSCode and ALS. Hopefully, ALS will no longer require this convoluted configuration and execute Alire directly without any issues.

reznikmm commented 1 year ago

Should be fixed in 23.0.15