Giter VIP home page Giter VIP logo

vsconan's Introduction

VSConan - Conan Extension for Visual Studio Code

Marketplace VSConan Build and Test Rating Install Download GitHub stars License: MIT Donate

VS Code Windows Linux Mac OS

Introduction

The VSConan extension helps you manage the conan local cache on your machine. It gives you easy access to your local cache and allows you to manage it by using integrated explorer in the Visual Studio Code without typing a single line of command in the terminal. VSConan provides variety of features, including a quick overview of installed packages, renaming and duplicating profiles, enabling and disabling remotes and more. For more information see Extension Features.

Recording of VSConan Explorer

Prerequisites

  1. Python with conan installed using pip
  2. Conan installed on your system using alternative installations

How To Start

VSConan contributes to official VS Code configurations (settings.json), where you can configure the environment to use this extension. As a starting point you can configure following settings, that are the core settings and provide you a high flexibility to use this extension:

  • vsconan.conan.profile.configurations
    In this section of settings you can store multiple configuration profiles, that contain necessary information to use conan from your system. Let's take a look at the following example:

    "vsconan.conan.profile.configurations": {
        "foo": {
            "conanVersion": "1",
            "conanPythonInterpreter": "/home/user/.venv2/bin/python",
            "conanExecutable": "/home/user/.venv2/bin/conan",
            "conanExecutionMode": "pythonInterpreter",
        },
        "bar": {
            "conanVersion": "2",
            "conanPythonInterpreter": "python",
            "conanExecutable": "conan",
            "conanExecutionMode": "conanExecutable",
            "conanUserHome": "/home/user/workspace/bar/.conan2"
        }
    }

    In the example above, we defined the foo and bar profile to start using this extension. Each profile has different configuration for the python interpreter and the conan executable. One thing that we notice here is that we can select the conan version, we want to use, 1 or 2. This information is crucial for the extension in order to get the correct API.

    NOTE: Make sure you combine the conanVersion and its binary accordingly. Otherwise it will have strange behaviours or things might even not work properly.

    Using conanUserHome we can overwrite the current conan user home directory. This attribute is optional and has default value of null. In the example of foo, conanUserHome is not defined, which means that the conan user home directory uses the default path or predefined environment variable (See Environment Variables).

  • vsconan.conan.profile.default
    After defining foo and bar profiles, now it is time for us to choose which configuration we want to use currently.

    "vsconan.conan.profile.default": "foo"

Extension Features

The VSConan extension contains two major groups of features, one of them is the Conan Explorer, where you can use to manage your local cache, and the other one is Conan Workspace, where you can save your configuration of different conan flow commands in your VSCode workspace.

Conan Explorer

Recording of VSConan Explorer

The VSConan extension contributes a Conan Explorer view to VS Code. The Conan Explorer lets you examine and manage important assets of your conan local cache, such as recipe, binary packages, profile and remote.

Conan Recipe

In the Conan Recipe explorer you can have an overview of the installed conan recipe in your local cache.

As you can see in the picture above, there are several inline options on each item in the treeview.

  • Information
    Open a web view in VS Code editor, that contains information about this selected recipe. Currently the web view only shows a plain JSON text, that is obtained from the Conan CLI.
  • Open in Explorer
    Open the the recipe path in the explorer
  • Open in VS Code
    Open the selected recipe in a new VS Code window
  • Remove
    Remove the selected recipe

Conan Binary Package

By selecting the recipe, the corresponded binary packages will be shown in this treeview.

Each item of this treeview has following options to offer:

  • Open in Explorer
    Open the selected binary package in the explorer
  • Open in VS Code
    Open the selected binary package in a new VS Code window
  • Remove
    Remove the selected binary package

Conan Profile

All the profiles that you saved on your machine will be listed in this explorer. By pressing + button on top right corner of the treeview, you can create a new empty profile.

As the other treeviews, each item of this treeview contains several functionalities:

  • Edit
    Open the selected profile in the VS Code editor
  • Open in Explorer
    Open the selected profile in the file explorer
  • Rename
    Rename the selected profile
  • Duplicate
    If you want to change a small detail from a certain profile but you do not want to lose the original profile, we provide you this duplicate option to fulfill your purpose.
  • Remove
    Remove the selected profile

Conan Remote

Finally we come to the last part of this explorer, which is the explorer of the conan remote.
The explorer itself provides you following options:

  • Edit
    Since the collection of remotes in conan is defined in one file called remotes.json, this option is not available of each remote item in the treeview. This will open remotes.json file in the VS Code editor instead.
  • Add
    Add a new remote

As other treeview, each item is equipped with several options, that you can use to maintain your remotes.

  • Rename Remote
    Rename the selected remote
  • Update URL
    Modify the URL in the selected remote
  • Enable Remote
    Enable the selected remote. Enabled remotes can be seen from the icon next to the remote name. The remote conancenter in the picture above is enabled.
  • Disable Remote
    Disable the selected remote. Disabled remotes can be seen from the icon next to the remote name. The remote anyOtherRemote in the picture above is disabled.
  • Remove Remote
    Remove the selected remote

Conan Workspace

The Conan Workspace feature provides you configuration file, that can be used to execute predefined conan flow command and its arguments. The configuration will be stored under .vsconan folder in your workspace.
If you work a lot with conan and use VS Code as your IDE, this feature can be really beneficial for you. It can spare you some seconds by avoiding to type same command, maybe with different arguments in your terminal over and over again. Instead you can save the command that you want to execute in the configuration and reuse in the next execution. In addition to that, the configuration file is reusable, and can be distributed to other people, if you work in a team.

Recording of VSConan Workspace

VSConan Extension will detect your workspace as conan workspace, if it contains a conanfile.py or conanfile.txt, and will a show dialog box as following

If you choose yes, VSConan will generate a default configuration file in your workspace to start with.
If you want to configure your workspace manually, we also provide you possibility to create a default configuration file using VS Code command VSConan: Create Workspace Configuration (JSON).

Currently supported conan command for configuration file:

  • create
  • install
  • build
  • source
  • package
  • export-pkg

The execution of the conan command will be done by the interpreter / conan executable from the profile that you selected. This configuration can be used for Conan version 1 and 2.

The default configuration file can be seen as following. You can extend the list of each command to have different name, description, user, channel and many other details.

{
  "commandContainer": {
    "create": [
      {
        "name": "create",
        "description": "Create command",
        "detail": "Create command detail",
        "conanRecipe": "conanfile.py",
        "profile": "default",
        "user": "",
        "channel": "",
        "args": []
      }
    ],
    "install": [
      {
        "name": "install",
        "description": "Install command",
        "detail": "Install command detail",
        "conanRecipe": "conanfile.py",
        "installFolder": "install",
        "profile": "default",
        "user": "",
        "channel": "",
        "args": []
      }
    ],
    "build": [
      {
        "name": "build",
        "description": "Build command",
        "detail": "Build command detail",
        "conanRecipe": "conanfile.py",
        "installFolder": "install",
        "buildFolder": "build",
        "packageFolder": "package",
        "sourceFolder": "source",
        "args": []
      }
    ],
    "source": [
      {
        "name": "source",
        "description": "Source command",
        "detail": "Source command detail",
        "conanRecipe": "conanfile.py",
        "installFolder": "install",
        "sourceFolder": "source",
        "version": "",
        "user": "",
        "channel": "",
        "args": []
      }
    ],
    "pkg": [
      {
        "name": "pkg",
        "description": "Package command",
        "detail": "Package command detail",
        "conanRecipe": "conanfile.py",
        "installFolder": "install",
        "buildFolder": "build",
        "packageFolder": "package",
        "sourceFolder": "source"
      }
    ],
    "pkgExport": [
      {
        "name": "pkg_export",
        "description": "Package export command",
        "detail": "Package export command detail",
        "conanRecipe": "conanfile.py",
        "installFolder": "install",
        "buildFolder": "build",
        "packageFolder": "package",
        "sourceFolder": "source",
        "user": "",
        "channel": "",
        "args": []
      }
    ]
  }
}

Additional Support Features

  • VSConan: Create Workspace Configuration (JSON)
    Create workspace configuration file
  • VSConan: Open Workspace Configuration (JSON)
    Open the workspace configuration file in the editor

Further information of currrent supported features is available here.

Release Notes

Detailed release notes are available here.

Contributing

See the contribution guidelines for ideas and guidance on how to improve the extension.

Code of Conduct

See Code of Conduct.

Donation

If this extension is useful and can save some of your time during your productive day, I would really appreciate a cup of coffee to keep me awake to continue developing this extension.

Credits

Demonstration video for GIF was recorded using Chronicler.

License

MIT

vsconan's People

Contributors

afri-bit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vsconan's Issues

View package settings per release

It would be great if we could click on a binary package release and see both the local cache "settings" (what make up the hash) as well as the settings of corresponding packages on the remote.

Basically, a wrapper around "conan search -r /@" so that we can identify easily if binary packages are missing settings.

Feature idea: Modify VSCode environment to match `conanbuild.sh`/`conanrun.sh`

Hi afri-bit!

First of all: I like your extension! The quality looks really good. 👍

In the company I'm working for, we're also using Conan (2) to manage C and C++ dependencies (most of the times using CMake).
We want to provide our developers a very smooth development experience. More precisely we want to have all extensions working within an Conan environment.
For e.g. VSCode CMake extension this works out of the box by the presets generated by Conan itself. But if other extensions (or even the Terminal) rely on some PATHs entries (or other environment variables) we don't have a sound solution at the moment.
Our workaround at the moment is: I've written a small generator that creates a .env-File and use direnv to modify the VSCode environment.

Are you interested to add such a feature to your extension? For sure, I would implement and test the feature (And discuss the approach with you upfront). 🤓
What do you think?

Managing editable packages

First of all, thanks a lot for writing this extension! VS Code has been lacking a good Conan extension but this one already looks very promising and it's just the first release.

I'd like to suggest a feature to create/list/delete editable packages. Managing editable packages is rather cumbersome to do on the command-line because you have to type a lot. It would be great if the extension could make that easier by

  • showing a list of all packages that are currently in editable mode
  • offering an option to make the package in the workspace editable (supporting conanlayout.ini would be a plus)
  • offering an option to remove any package from the editable list

Whitespaces not supported in workspace names

Whitespaces are not supported in workspace names.

vsconan/src/conans/conan/commandBuilder.ts creates the cmd as an array, but then does a join, concatenating it to a string:

 public override buildCommandCreate(wsPath: string, cfg: ConfigCommandCreate): string | undefined {
        // Initialized the command in array of string. Later on will be converted to plain string.
        let cmd: Array<string> = [];

        cmd.push("create");

        // One of mandatory attributes is the path to the conanfile.py
        // If this is empty the whole command build process will be cancelled.
        if (cfg.conanRecipe !== "" && cfg.conanRecipe !== undefined) {
            cmd.push(utils.workspace.getAbsolutePathFromWorkspace(wsPath, cfg.conanRecipe));
        }
        else {
            return undefined;
        }

        ...

        return cmd.join(" ");
    }

vsconan/src/utils/utils.ts has the whole cmd as string, instead of an array, what https://nodejs.org/api/child_process.html#child_processspawncommand-args-options appaerently would support.

export async function executeCommand(cmd: string, channel: vscode.OutputChannel) {
            // const exec = util.promisify(require('child_process').exec);
            // const { stdout, stderr } = await spawn(cmd);
            channel.show();

            const ls = spawn(cmd, [], { shell: true });

Conan recipe dependencies analysis of a conan workspace

If you work on a conan workspace, we would like to provide you a possibility to analysis the conan dependencies from your workspace, and check, whether it's already available in the local cache or not. In case it isn't there will be an option to download and save it your local cache per button click.

Show dependency graph from a recipe

This feature must enable user to see the dependency graph from a selected recipe in the cache or from current conan project in the workspace

Local profile not found using relative path

I have a local Conan profile folder .azuredevops\conan\default and I am configuring the VS Conan install command in .vsconan\config.json as follows:

        "install": [
            {
                "name": "default",
                "description": "Default profile",
                "detail": "Installs ready for development using the project default profile",
                "conanRecipe": "conanfile.py",
                "installFolder": "build/Release/conan",
                "profile": ".azuredevops/conan/default",
                "args": [
                    "-pr:b windows"
                ]
            }
        ]

When i run the Install command I get the error:
ERROR: Profile not found: .azuredevops/conan/default

I am running on a windows PC so, I also tried with "\" and I also tried making relative to the config.json, all with the same result.

I only can get this to work, if I provide the absolute path, which is not an option as I want other users to be able to clone the repo where they like and it still work!

I tried to find some clues in the documentation, but could not find it.

Is it possible to provide a relative path to a local profile? If not please can someone add that feature?

I am using Conan version 1.59.0 with VS Code:

Version: 1.79.0 (user setup)
Commit: b380da4ef1ee00e224a15c1d4d9793e27c2b6302
Date: 2023-06-07T14:26:35.552Z
Electron: 22.5.5
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Windows_NT x64 10.0.19045

and VSConan v0.4.0

Add conan commands to status bar

It would be great if, like the CMake extension, you could add buttons to automatically run "conan install", "conan build", and "conan create".

It would also be great to be able to select different profiles to run from a menu here (also like CMake) so that we could easily switch from debug to release, cross compiling, etc.

Nice extension btw!

Automatic detection of pre installed 'conan' in the environment

Additional execution mode auto should be added to let the extension detect conan in the environment and decide which conan executable from the system should be used for the extension.
This will enable user to use the extension without modifying the settings.json

Support non-pip conan installation

The extension currently fails to function if Conan has been installed using one of the alternative installers, i.e. not as a pip package. E.g. on my system, Conan is at C:\Program Files\Conan\conan\conan.exe and is in the PATH but a command like python -m conans does not work.

If there are technical reasons why a pip installation is required and alternative installers cannot be supported, I suggest to at least make that fact clear in the README and ideally showing a more helpful error message when the pip package cannot be found.

[Error] The "path" argument must be of type string. Received undefined

Hi,

I've got an error when using pythonInterpreter with a python venv and a custom conan user home.

Here my user settings.json:

"vsconan.general.pythonInterpreter": "C:/pyvenv_conan/Scripts/python.exe",
"vsconan.general.conanExecutionMode": "pythonInterpreter",
"vsconan.general.conanUserHome": "C:/Users/user/.conan",

My workspace settings.json is empty.

When I try to refresh I get the error The "path" argument must be of type string. Received undefined. I've also checked using double backslashes for the paths. I assume the problem here is that the conan.exe lies next to the python.exe inside the venv unlike for a normal python installation.

Best regards

show conan remote packages, set package editable

  1. Load and view implementation of Conan packages for selected items in Conan Remote. “vsconan.explorer.treeview.remote.item.selected” is not implemented. You can load all available packages from the repo using the command “conan search “*” -r=conancenter” or other repos.

  2. Implementation of the change package in editable. It would be good if you could change the package to editable.
    'Conan editable, add "path" "package name""
    Path and package name sould be inserted.

Support environment variables set in .bashrc

I am using Ubuntu 20.04 and have customized my CONAN_USER_HOME variable in my bash profile .bashrc. Unfortunately, the extension does not load the bash profile when it invokes conan commands, thus conan uses the default user home and does not find my profiles.

I am not sure if it is feasible for the extension to automatically run conan in the context of my bash profile. If not, another solution could be to allow setting arbitrary environment variables in an extension setting.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.