mesonbuild / vscode-meson

Meson for VisualStudio Code
Apache License 2.0
99 stars 49 forks source link

Switch from multiple builddir to required builddir #233

Open zenshosan opened 1 month ago

zenshosan commented 1 month ago

Hi I have recently started using meson. I'd like to add the following feature to vscode-meson.

What

When developing software using compiled languages such as c++ or rust, it often happens to switch between multiple build configurations such as so-called 'release' and 'debug'.

In meson, this is supposed to be done by creating multiple builddirs and switching between them. (see Using multiple build directories)

In vscode-meson, switching between builddirs requires rewriting mesonbuild.buildFolder in settings.json, which is not very convenient.

I would like to be able to switch this easily.

How to work

I will explain how these can be realized given the knowledge gained from reading the threads and source code below. (because I'm new)

https://github.com/mesonbuild/vscode-meson/issues/201 https://github.com/mesonbuild/vscode-meson/pull/195 https://github.com/mesonbuild/vscode-meson/pull/188 https://github.com/mesonbuild/vscode-meson/pull/179 https://github.com/mesonbuild/vscode-meson/issues/101 https://github.com/mesonbuild/vscode-meson/pull/22 https://github.com/mesonbuild/vscode-meson/pull/103

Currently vscode-meson reactivates itself by calling reloadWindow when sourceDir is selected or mesonbuild.buildFolder is changed.

Although reloading is generally an undesirable behavior, I'd like to follow this behavior for the time being to minimize source code changes by reloading when switching buildDirs. (Avoiding reloads should be a separate issue.)

Specification overview

  1. Automatic launch of selection UI at first startup
    Basically, add a buildDir selection flow after the user selects sourceDir. This also includes leaving sourceDir as is and selecting only buildDir.

    • buildDir selection UI
      Unlike sourceDir selection, it does not search the file system to collect existing buildDir. User enters the path manually or selects from previous entries.

    • Saving sourceDir selection
      This buildDir selection is permanently remembered in memento, just like sourceDir. On the next time startup, these values ​​will be applied and the user does not need to make a selection.

  2. Explicit selection UI launch from command or builddir selection via MesonProjectExplorer Users can also launch the selection UI from the command palette or select a builddir directly from the MesonProjectExplorer in the side panel.

  3. Save format of buildDir
    I expect that "mesonbuild.buildFolder" is probably unnecessary or a less important setting. The buildDir selected by the UI is permanently saved in the format below. Please note that multiple buildDirs are stored per sourceDir, and the most recently used one is placed at 0th.

type BuildConfig = {
    buildDir: string;     // path to builddir
    friendlyName: string; // for displaying of MesonProjectExplorer
  };
type BuildConfigMap = {
    [sourceDir: string]: BuildConfig[] // multiple builddirs per sourceDir
};

// example
let buildDirsMap: BuildConfigMap = {
    "path/to/sourceDir1": [
        {
            buildDir: "path/to/sourceDir1/build_dbg",
            friendlyName: "x64_dbg",
        },
        {
            buildDir: "path/to/sourceDir1/build_rel",
            friendlyName: "x64_rel",
        },
    ],
    "path/to/sourceDir2": [
        {
            // It can also happen if buildDir is outside of sourceDir.
            buildDir: "path/to/out/of/sourceDir2/build_dbg",
            friendlyName: "x64_dbg",
        },
        {
            buildDir: "path/to/out/of/sourceDir2/build_rel",
            friendlyName: "x64_rel",
        },
    ],
};

workspaceState.update("mesonbuild.buildDirsMap", buildDirsMap);

We need to discuss the details further, but for now I would like to hear everyone's opinions.

Thank you.

tristan957 commented 1 month ago

I think what you are proposing sounds reasonable. It would be good to make the automatic popup optional via a setting

zenshosan commented 1 month ago

I think what you are proposing sounds reasonable. It would be good to make the automatic popup optional via a setting

Thank you. I have considered about it. It is better to integrate buildDir selection into the sourceDir selection UI. Therefore, in this case, the popup settings should just follow the existing mesonbuild.selectRootDir. (No need to introduce mesonbuild.selectBuildDir)

However, if you have sourceDir and only select buildDir, we will need to switch the popup wording.

So, is it like this?

if (!hasSourceDir) {}
    showInformationMessage("Multiple Meson projects detected, select one?");
} else {
    showInformationMessage("Build directory is not set. Do you want to set it?");
}

This might be somewhat confusing for users. This is because if you reply "Never" to the former message, the latter message will also no longer be displayed. Personally, this is acceptable.