Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
mkdocs-material
mkdocstrings
mkdocstrings
pydantic
websockets
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
websockets
websockets
pydantic
68 changes: 31 additions & 37 deletions vscode/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@
import json
import venv
import inspect
from typing import TYPE_CHECKING
from pathlib import Path

if TYPE_CHECKING:
from vscode.extension import Extension
from vscode.extension import Launch

__all__ = ("build",)

COMMAND = {"title", "category", "command"}


def create_package_json(extension) -> None:
package = {
"name": extension.name,
"displayName": extension.display_name,
"main": "./extension.js",
"contributes": {
"commands": [cmd.to_dict() for cmd in extension.commands],
"commands": [
cmd.dict(include=COMMAND, exclude_unset=True)
for cmd in extension.commands
],
},
"activationEvents": [
"onCommand:" + cmd.extension_string for cmd in extension.commands
],
"activationEvents": ["onCommand:" + cmd.command for cmd in extension.commands],
"dependencies": {
"ws": "^8.4.0",
}
},
}
first_info = {
"version": "0.0.1",
Expand Down Expand Up @@ -56,44 +58,30 @@ def create_package_json(extension) -> None:


def create_launch_json():
launch_json = {
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
},
],
}

cwd = os.getcwd()

vscode_path = os.path.join(cwd, ".vscode")
os.makedirs(vscode_path, exist_ok=True)
os.chdir(vscode_path)

with open("launch.json", "w") as f:
json.dump(launch_json, f, indent=2)
vscode_path = Path.cwd().joinpath(".vscode")
vscode_path.mkdir(exist_ok=True)

os.chdir(cwd)
with open(vscode_path.joinpath("launch.json"), "w") as f:
f.write(Launch().json(indent=2))


REGISTER_COMMANDS_TEMPLATE = """
context.subscriptions.push(
vscode.commands.registerCommand("{}", () =>
commandCallback("{}")
vscode.commands.registerCommand("{command}", () =>
commandCallback("{name}")
)
);
"""


def get_vsc_filepath(file):
return os.path.join(os.path.split(__file__)[0], file)
return Path(__file__).with_name(file)


def create_extension_js(extension):
js_code_path = get_vsc_filepath("extcode.js")
if os.path.isfile(js_code_path):
if js_code_path.exists():
with open(js_code_path, "r") as f:
code = f.read()
else:
Expand All @@ -106,8 +94,7 @@ def create_extension_js(extension):
imports = imports.replace("<filepath>", file)
commands_code = "function registerCommands(context) {\n\t"
for cmd in extension.commands:
args = cmd.extension_string, cmd.name
commands_code += REGISTER_COMMANDS_TEMPLATE.format(*args)
commands_code += REGISTER_COMMANDS_TEMPLATE.format(**cmd.dict())

commands_code += "\n}"

Expand All @@ -120,7 +107,12 @@ def build(extension) -> None:
start = time.time()

if not os.path.isfile("requirements.txt"):
print(f"\033[1;37;49mA requirements.txt wasn't found in this directory. If your extension has any dependencies kindly put them in the requirements.txt", "\033[0m")
print(
f"\033[1;37;49mA requirements.txt wasn't found in this directory. If your extension has any dependencies kindly put them in the requirements.txt",
"\033[0m",
)

# TODO: Add websockets requirement
with open("requirements.txt", "w") as f:
f.write("git+https://github.com/CodeWithSwastik/vscode-ext@main")

Expand All @@ -134,7 +126,6 @@ def build(extension) -> None:
python_path = os.path.join(os.getcwd(), "venv/bin/python")
os.system(f"{python_path} -m pip install -r requirements.txt")


create_launch_json()
print(f"\033[1;37;49mCreating package.json...", "\033[0m")
create_package_json(extension)
Expand All @@ -147,4 +138,7 @@ def build(extension) -> None:

end = time.time()
time_taken = round((end - start), 2)
print(f"\033[1;37;49mBuild completed successfully in {time_taken} seconds! ✨", "\033[0m")
print(
f"\033[1;37;49mBuild completed successfully in {time_taken} seconds! ✨",
"\033[0m",
)
5 changes: 4 additions & 1 deletion vscode/extcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
);
}

pyVar = path.join(venvPath, process.platform == "win32" ? "Scripts/python.exe": "bin/python");
pyVar = path.join(
venvPath,
process.platform == "win32" ? "Scripts/python.exe" : "bin/python"
);
let py = spawn(pyVar, [pythonExtensionPath, "test"]);

py.stdout.on("data", (data) => {
Expand Down
Loading