GithubHelp home page GithubHelp logo

codewithswastik / vscode.py Goto Github PK

View Code? Open in Web Editor NEW
178.0 4.0 29.0 1 MB

Create VSCode Extensions with python

Home Page: https://vscodepy.readthedocs.io/

License: MIT License

Python 94.79% JavaScript 5.21%
vscode python python-library

vscode.py's Introduction

vscode.py logo

Maintenance Downloads PyPI version Code style: black

About

Create vscode extensions with python.

Installation

Stable version:

pip install vscode.py

Why use vscode.py?

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

  • vscode.py 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.py provides a pythonic way of creating the extension. Python has some powerful modules that Javascript doesn't and you can include these with vscode.py
  • vscode.py extensions work perfectly with vsce and you can publish your extensions just like you would publish any other extension.

Example Extension

import vscode
from vscode import InfoMessage

ext = vscode.Extension(name="Test Extension")

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


@ext.command()
async def hello_world(ctx):
    return await ctx.show(InfoMessage(f"Hello World from {ext.name}"))

ext.run()

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

Step 3

Run the python file. It will build the required extension 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.py

Here's a list of some extensions built using vscode.py. 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.py works and what it offers!

vscode.py's People

Contributors

codewithswastik avatar dorukyum avatar driftasimov avatar grace-codes avatar makiyu-py avatar nicholas-schaub avatar skullcrusher0003 avatar sohamghugare avatar tducret avatar timskovjacobsen avatar truemyst avatar vincederprince avatar yo56789 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

vscode.py's Issues

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

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.

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

Lower extension activation time

When the extension is activated for the first time it takes at a long time depending on the number of python packages to install.

Possible Solution: Instead of installing the python packages, they should be bundled with the extension

Error in setting up the virtual environment...

Version: 2.0.0a5

Setting up the virtual environment... 
Traceback (most recent call last):
  File "c:\Users\smart\Desktop\PappuAI\Pappu.py", line 15, in <module>
    ext.run()
  File "C:\Python310\lib\site-packages\vscode\extension.py", line 178, in run
    build(self)
  File "C:\Python310\lib\site-packages\vscode\compiler.py", line 132, in build
    venv.create("./venv", with_pip=True)
  File "C:\Python310\lib\venv\__init__.py", line 412, in create
    builder.create(env_dir)
  File "C:\Python310\lib\venv\__init__.py", line 75, in create
    self._setup_pip(context)
  File "C:\Python310\lib\venv\__init__.py", line 298, in _setup_pip
    subprocess.check_output(cmd, stderr=subprocess.STDOUT)
  File "C:\Python310\lib\subprocess.py", line 420, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Python310\lib\subprocess.py", line 501, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Python310\lib\subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Python310\lib\subprocess.py", line 1435, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

`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.

Cogs

Hey,

If vscode-ext could have some sort of system to use cogs like in discord.py that would be amazing. It is a bit bunched up to the whole ext in one file. This isn't necessarily needed, but would be a nice update

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?

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?

Almost nothing works

Got the main example working somehow, but most of the examples do not work, nor any of the external plugins. Code apparently is written for an incompatible old version.

Async

Hi, I am wondering if there are plans or things in the works to allow this library to use asynchronous functions etc. If not I think this would be great to add

Add a way to make us freely edit package.json

I've been trying to add a license key and editing the engines.vscode value (on the package.json) but it keeps getting overridden every build.

Could you guys add a way that prevents this from happening?

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'])

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.