Create VSCode Extensions with python

Overview

vscode logo

Maintenance Downloads PyPI version GitHub stars Code style: black

About

Create vscode extensions with python.

Installation

Stable version:

pip install vscode-ext

Why use this?

Why should you use this for building VScode extensions when you can use typescript? Here are some reasons:

  • vscode-ext builds the package.json for you! No need to switch between your extension.py and package.json in order to add commands. It also handles adding Activity Bars, Keybinds and Views.
  • vscode-ext provides a more pythonic way of creating the extension. Python also has some powerful modules that Javascript doesn't and you can include these with vscode-ext
  • vscode-ext extensions work perfectly with vsce and you can publish your extensions just like you would publish any other extension.

Example Extension

import vscode

ext = vscode.Extension(name = "testpy", display_name = "Test Py", version = "0.0.1")

@ext.event
def on_activate():
    return f"The Extension '{ext.name}' has started"

@ext.command()
def hello_world():
    vscode.window.show_info_message(f'Hello World from {ext.name}')

@ext.command()
def ask_question():
    res = vscode.window.show_info_message('How are you?', 'Great', 'Meh')
    if res == "Great":
        vscode.window.show_info_message('Woah nice!!')
    elif res == "Meh":
        vscode.window.show_info_message('Sorry to hear that :(')

vscode.build(ext)

Tutorial

Step 1

Create a python file inside a folder.

image

Step 2

Write the code for your extension. For this tutorial we have used the Example Extension

image

Step 3

Run the python file. It will build the files.

image image

Step 4

Press F5. This will run the extension and open a new vscode window in development mode.

Step 5

Finally, test your command.

  • Open the command palette with Ctrl+P in the development window.

image

  • Type >Hello World

image

  • It should show a popup like this in the bottom right corner

image

Extensions built using vscode-ext

Here's a list of some extensions built using vscode-ext. If you'd like to include your extension here feel free to create a PR.

Documentation

The docs are coming soon! In the meantime you can look at the examples in order to learn how vscode-ext works and what it offers!

Comments
  • Added ms-python environment integration

    Added ms-python environment integration

    Summary This PR reworks how Python is called in extension.js so that Python is called from the active Python environment in CS code.

    Background In it's existing form, Python is directly immediately after imports based on architecture, and then in extensions code is generated based on architecture type in compiler.py. This means Python is called based on the system environment, rather than the active environment in VS Code.

    What is Changed This PR grabs the path to the current Python environment from the official Python extension, ms-python. It then replaces the current way that Python is being called with the Python binary associated with the active environment.

    Potential Pitfalls This may be a bad approach for situations where someone designs a fairly code agnostic extension, such as a color theme. For example, if someone installs a color theme designed in vscode-ext but they code in a language other than Python, it's unclear if the active Python environment exists or is even a good option. There may also be an issue if someone doesn't have the official Python extension installed. These should be fixable with a few lines of code, but I think feedback/discussion on this might be useful before additional work is performed.

    Notes I only deleted 6 lines of code and added 3 lines of code at the top of data.py, but git decided to rewrite the whole file ¯_(ツ)_/¯

    I was going to try and merge with your rewrite branch, but that looks like it's still pretty premature.

    Related to #25

    opened by Nicholas-Schaub 3
  • How to get working directory in quick pick?

    How to get working directory in quick pick?

    Hi, I just started with this and thanks for sharing.

    I am trying to implement word completion in quick pick with items which files in working directory.

    thus I tried as like this:

    def search():
        cwd = os.getcwd()     # here, this line has the problem
        file_list = get_files_under(cwd)
        data = list(map(lambda path: vscode.ext.QuickPickItem(path), file_list))
        options = vscode.ext.QuickPickOptions(title='Select file to ...')
        selected = vscode.window.show_quick_pick(data, options)
        if not selected: return
        return selected
    

    As I expected, cwd = '<project root directory as workspace>' like ~/vscode-ext-example/ but actually it is cwd = C:\Users\joonasyoon\AppData\Local\Programs\Microsoft VS Code

    how can I get current directory for that?

    opened by joonas-yoon 3
  • Extension is not compatible with Code 1.56. Extension requires ^1.59. Wrong code.exe used.

    Extension is not compatible with Code 1.56. Extension requires ^1.59. Wrong code.exe used.

    I have multiple versions of VSCode installed locally and the script seems to pick the one in the PATH which is great but I'd like to configure it to provide my own path to VS code.exe of specific version.

    question 
    opened by ashrauma 2
  • Args should be taken as lists instead of strings

    Args should be taken as lists instead of strings

    Make it so display functions should take in args as lists and not strings, so we can pass in complete lists instead of passing the individually list values in the form of strings. Example: vscode.window.show_info_message("Options", ['opt-1', 'opt-2', 'opt-3'])

    enhancement 
    opened by SohamGhugare 2
  • Buggy Example

    Buggy Example

    Just found this project, and thought it was pretty cool. I attempted to run the hello world example and I wasn't getting the info message. I have used the VS Code Yeoman template and have been able to get that running, so I suspect it's something to do with this package. I'm happy to provide any debug information needed.

    I'm running VS Code 1.63 and using Python 3.9.

    opened by Nicholas-Schaub 1
  • Create icon do display in VSCode Activty Bar

    Create icon do display in VSCode Activty Bar

    I could not find the file media/python.svg, so I created the file vscode-ext/examples/media/python.svg. Below you can see the python icon displaying in the activity bar.

    images/media.

    Another recommendation is to change the README.me, with easier directions instructions on how to run directly from the repository.

    1. In VS Code:, open the folder .../vscode-ext/example
    2. pip install virtualenv
    3. python -m virtualenv .venv
    4. .venv\Scripts\activate
    5. pip install ..
    6. python .py
    7. depress F5

    Please not every time you compile ,py, the files extension.p, extension.js,, extension.json and launch.json will change accordingly.

    opened by jeffgoldszer 1
  • Added a way to customize vscode version and categories

    Added a way to customize vscode version and categories

    ~~I'm back~~ The title says it all lmao (sorry for the almost-late-night pr)

    Usage:

    ext = vscode.Extension(
        some_stuff="here",
        categories=["testing"],  # default here is ["Other"]
        vscode_version="^1.56.0",  # default is "^1.58.0" (https://code.visualstudio.com/api/working-with-extensions/publishing-extension#visual-studio-code-compatibility)
        other_stuff=["h", "e", "r", "e"]
    )
    

    I guess this also fixes #26 since you can now customize the min-max vsc version for your extension (also, happy hacktoberfest! :D)

    opened by Makiyu-py 1
  • Added linux binary support for pyEnv

    Added linux binary support for pyEnv

    Currently, the new rewrite code that was recently merged into the repo does not support Linux pathing for the new virtual environment that is created. This PR fixes that.

    opened by Nicholas-Schaub 0
  • Implement `showWorkspaceFolderPick`

    Implement `showWorkspaceFolderPick`

    resolves #31

    ~~pls ignore the first commit ty~~

    Usage

    res = vscode.window.show_workspace_folder_pick()
    
    vscode.window.show_info_message(f"Nice you selected: {res['name']}")
    
    opened by Makiyu-py 0
  • Added Configuration for Extensions

    Added Configuration for Extensions

    Example

    Code

    import vscode
    from vscode.config import Config, ConfigType
    
    c = Config(name='Say', description='Say Something!', input_type=ConfigType.string, default="Hello World!")
    ext = vscode.Extension('speaker','Speaker', '0.0.1', config=[c])
    
    @ext.command()
    def message_say_config():
        vscode.window.show_info_message(ext.get_config('Say') or c.default)
    
    vscode.build(ext)
    

    GIF Output

    opened by Makiyu-py 0
  • Partial Implementation of Pydantic

    Partial Implementation of Pydantic

    This PR converts most extension classes into pydantic classes.

    The Extension class is not converted into a pydantic class because I am investigating a good approach to doing this. Effectively, Extension.py contains all information for package.json. The ideal approach is to get the json schema for package.json and autogenerate the pydantic classes, that way if the schema is updated then it is easy to update the class. However, there is no package.json schema that fits vscode extensions exactly. Rather, vscode uses NPMs package.json schema and then make modifications within the code rather than creating an actual schema.

    What we can do is create an autogenerated package.json class, then make Extension a subclass and make the necessary changes to conform to vscode.

    This PR also enforces some standards outlined in the vscode docs. For example, package versions should follow semantic versioning, so the pydantic classes validate the input version that is supplied to the class.

    opened by Nicholas-Schaub 0
  • `main` repo is incomplete

    `main` repo is incomplete

    I submitted a PR recently and noticed that a bunch of rewrite code as implemented in the main repo. It breaks a lot of functionality, which is fine, but there is no replacement for much of the previous functionality. For example, it was possible for me to add in extensionDependencies when initializing the Extension object. Now you cannot do that, and you cannot set the version either. I understand breaking things when major versions change, but to have only a partial implementation of some of these things in the main repo is usually bad practice because this makes me resistant to work on any new contributions since I am losing functionality when trying to implement fixes or features.

    Do you have a list of features/functionality you intend on implementing? I am happy to help implement some of this stuff, and if there are good reasons to not implement some of the features of the previous version, that's completely understandable. However, it's difficult to try and contribute if I don't know if features are intentionally left out or if they are incomplete.

    opened by Nicholas-Schaub 5
  • Get current open file/project

    Get current open file/project

    Is there a way through the extension to get the filename and path to the currently open file or project in the editor? Something like pathlib.Path.cwd doesn't work if the user navigates to a different project within VSCode

    opened by TTitcombe 2
  • Error: spawn python ENOENT, on Windows

    Error: spawn python ENOENT, on Windows

    vscode-ext: 1.5.4 vscode: 1.62.3 Windows: 21H1 (19043.1348)

    I was getting Error: spawn python ENOENT when running the example https://github.com/CodeWithSwastik/vscode-ext/blob/main/examples/hello_world.py

    [2021-11-21 20:59:10.224] [renderer16] [error] spawn python ENOENT: Error: spawn python ENOENT
    	at Process.onexit (internal/child_process.js:269:19)
    	at onErrorNT (internal/child_process.js:465:16)
    	at processTicksAndRejections (internal/process/task_queues.js:80:21)
    

    Following the suggestions in https://stackoverflow.com/a/54515183 I used the already present osvar to add spawnOptions to all the spawn calls in the generated extension.js

    const osvar = process.platform;
    spawnOptions = {shell: osvar == 'win32'}
    

    I might be able to create a PR to solve this issue. Would the PR be reviewed? Is there any guidance on how to contribute?

    opened by gmeligio 0
  • Python was not found

    Python was not found

    I get an error when I run my function using Shift+Command+P. This is expected since my Python is not globally installed and comes from a virtualenv. How can I define path to Python?

    An Error occurred in the python script: Python was not found c:\Program Files\Microsoft VS Code\1.58.2\resources\app\out\bootstrap-fork.js:5
    An Error occurred in the python script:  but can be installed from the Microsoft Store: ms-windows-store://pdp/?productid=9NJ46SX7X90P
    
    bug 
    opened by ashrauma 4
Owner
Swas.py
Swas.py
An extension for Arma 3 that lets you write extensions in Python 3

An Arma 3 extension that lets you to write python extensions for Arma 3. And it's really simple and straightforward to use!

Lukasz Taczuk 48 Dec 18, 2022
Minos-python - A framework which helps you create reactive microservices in Python

minos-python Summary [TODO] Packages minos-microservice-aggregate minos-microser

Minos Framework 380 Jan 4, 2023
How to create the game Rock, Paper, Scissors in Python

Rock, Paper, Scissors! If you want to learn how to do interactive games using Python, then this is great start for you. In this code, You will learn h

SplendidSpidey 1 Dec 18, 2021
apysc is the Python frontend library to create html and js file, that has ActionScript 3 (as3)-like interface.

apysc apysc is the Python frontend library to create HTML and js files, that has ActionScript 3 (as3)-like interface. Notes: Currently developing and

simonritchie 17 Dec 14, 2022
pyreports is a python library that allows you to create complex report from various sources

pyreports pyreports is a python library that allows you to create complex reports from various sources such as databases, text files, ldap, etc. and p

Matteo Guadrini aka GU 78 Dec 13, 2022
Python Create Your Own Tool Series

Python Create Your Own Tool Series Hey there! This is an additional Github repository that contains the final product files for each video in my Youtu

Joe Helle 21 Dec 2, 2022
uMap lets you create maps with OpenStreetMap layers in a minute and embed them in your site.

uMap project About uMap lets you create maps with OpenStreetMap layers in a minute and embed them in your site. Because we think that the more OSM wil

null 771 Dec 29, 2022
Viewflow is an Airflow-based framework that allows data scientists to create data models without writing Airflow code.

Viewflow Viewflow is a framework built on the top of Airflow that enables data scientists to create materialized views. It allows data scientists to f

DataCamp 114 Oct 12, 2022
Oppia is an online learning tool that enables anyone to easily create and share interactive activities

Oppia is an online learning tool that enables anyone to easily create and share interactive activities (called 'explorations'). These activities simulate a one-on-one conversation with a tutor, making it possible for students to learn by doing while getting feedback.

Oppia 4.7k Dec 29, 2022
A step-by-step tutorial for how to work with some of the most basic features of Nav2 using a Jupyter Notebook in a warehouse environment to create a basic application.

This project has a step-by-step tutorial for how to work with some of the most basic features of Nav2 using a Jupyter Notebook in a warehouse environment to create a basic application.

Steve Macenski 49 Dec 22, 2022
create cohort visualizations for a subscription business

pycohort The main revenue generator for subscription businesses is recurring payments. There might be additional one-time offerings but the number of

Yalim Demirkesen 4 Sep 9, 2022
The only purpose of a byte-sized application is to help you create .desktop entry files for downloaded applications.

Turtle ?? The only purpose of a byte-sized application is to help you create .desktop entry files for downloaded applications. As of usual with elemen

TenderOwl 14 Dec 29, 2022
✔️ Create to-do lists to easily manage your ideas and work.

Todo List + Add task + Remove task + List completed task + List not completed task + Set clock task time + View task statistics by date Changelog v 1.

Abbas Ataei 30 Nov 28, 2022
KUIZ is a web application quiz where you can create/take a quiz for learning and sharing knowledge from various subjects, questions and answers.

KUIZ KUIZ is a web application quiz where you can create/take a quiz for learning and sharing knowledge from various subjects, questions and answers.

Thanatibordee Sihaboonthong 3 Sep 12, 2022
Fetch data from an excel file and create HTML file

excel-to-html Problem Statement! - Fetch data from excel file and create html file Excel.xlsx file contain the information.in multiple rows that is ne

Vivek Kashyap 1 Oct 25, 2021
Allow you to create you own custom decentralize job management system.

ants Allow you to create you own custom decentralize job management system. Install $> git clone https://github.com/hvuhsg/ants.git Run monitor exampl

null 1 Feb 15, 2022
A Linux program to create a Windows USB stick installer from a real Windows DVD or image.

WoeUSB-ng A Linux program to create a Windows USB stick installer from a real Windows DVD or image. This package contains two programs: woeusb: A comm

Longinus 1 Nov 19, 2021
Create or join a private chatroom without any third-party middlemen in less than 30 seconds, available through an AES encrypted password protected link.

PY-CHAT Create or join a private chatroom without any third-party middlemen in less than 30 seconds, available through an AES encrypted password prote

null 1 Nov 24, 2021
Simply create JIRA releases based on your github releases

Simply create JIRA releases based on your github releases

null 8 Jun 17, 2022