Skip to main content

Create VSCode Extensions with python

Project description

vscode logo

Maintenance Downloads PyPI version GitHub stars Code style: black

About

Create vscode extensions and color themes 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(keybind="ALT+5")
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

Color Theme Example

import vscode

theme = vscode.ColorTheme(name='my-theme', display_name='My Theme', version='0.0.1')
theme.set_colors(
    background='#12171F',
    foreground='#EFEFEF',
    accent_colors=['#399EF4', '#DA6771', '#4EB071', '#FFF099']
)
vscode.build_theme(theme)

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vscode-ext-1.5.1.tar.gz (25.6 kB view details)

Uploaded Source

File details

Details for the file vscode-ext-1.5.1.tar.gz.

File metadata

  • Download URL: vscode-ext-1.5.1.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.10.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.8.5

File hashes

Hashes for vscode-ext-1.5.1.tar.gz
Algorithm Hash digest
SHA256 ff60ee9baca7823b63313548573397d4fca660b0df91cd5b4a1b15140af0fd9a
MD5 ea13c99db00b7d9793d3e22790e1392b
BLAKE2b-256 bcec3ccbb8cb9d9a1be35d295c2aefe864cbf8e139bd378b9bd371401958f996

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page