Skip to content

Commit

Permalink
Added basedpython, clangd extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Jul 2, 2024
1 parent b77d409 commit 2d46aff
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 23 deletions.
28 changes: 16 additions & 12 deletions TEMPLATE.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,36 @@
# Guide to Extension Development:
# 1. Create a new file in the `biscuit/extensions` folder
# 2. Name it something.py (e.g. hello_world.py)
# 3. Add following lines (for intellisense):
# 3. Make sure you've installed `biscuit-editor` using `pip install biscuit-editor`

from __future__ import annotations

__version__ = "0.2.0"
__version__ = "0.0.1"
__version_info__ = tuple([int(num) for num in __version__.split(".")])

import typing

from biscuit.extensions import Extension

if typing.TYPE_CHECKING:
from biscuit import ExtensionsAPI
from biscuit.api import ExtensionsAPI

# 4. Create a class for your extension as follows:

# 4. Create a class named `Extension` as follows:

class HelloWorld(Extension):
def __init__(self, api: ExtensionsAPI) -> None:
super().__init__(api)

class Extension:
"""Dev Mode extension for Biscuit (author: @billyeatcookies)
self.api.logger.info(f"This is a sample log!")

Contributes:
- notifies user that dev mode is enabled
"""
def install(self) -> None:
self.api.notifications.info(f"Hello world!")

def __init__(self, api: ExtensionsAPI) -> None:
self.api = api

self.api.notifications.info(f"Dev mode is enabled!")
def setup(api: ExtensionsAPI) -> None:
"""Setup the extension"""
api.register("dev", HelloWorld(api))


# 5. Start customizing your extension!
2 changes: 2 additions & 0 deletions extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"Rust":["rust.py", "tomlin7", "Rust support for Biscuit"],
"Clangd":["clangd.py", "tomlin7", "C/C++ intellisense for Biscuit"],
"Ollama": ["ollama.py", "tomlin7", "Use Llama 3, Mistral, Gemma 2, etc for your assistant"],
"TypeScript & JavaScript":["javascript_typescript.py", "tomlin7", "Support for JS & TS projects"],
"basedpython":["basedpython.py", "tomlin7", "Based-pyright extension for Python"],
"Clojure":["clojure.py", "Cid0rz", "Clojure language extension for Biscuit"],
"Black Formatter":["black.py", "tomlin7", "Format your code with Black"],
"Isort":["isort.py", "tomlin7", "Sort your imports with isort"],
Expand Down
39 changes: 39 additions & 0 deletions extensions/basedpython.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from __future__ import annotations

__version__ = "0.0.1"
__version_info__ = tuple([int(num) for num in __version__.split(".")])

import subprocess
import typing

from biscuit.extensions import Extension
from biscuit.language import Languages

if typing.TYPE_CHECKING:
from biscuit.api import ExtensionsAPI


class BasedPython(Extension):
def __init__(self, api: ExtensionsAPI) -> None:
super().__init__(api)

def install(self) -> None:
self.install_based_pyright()
# overrides the default python language server with the based pyright language server
self.api.register_langserver(
Languages.PYTHON, "basedpyright-langserver --stdio"
)

def install_based_pyright(self, *_) -> bool:
try:
subprocess.run(["pip", "install", "basedpyright"], check=True)
except Exception as e:
self.api.notifications.error(
f"Failed to install basedpyright package.",
actions=[("Retry", self.install_based_pyright)],
)


def setup(api: ExtensionsAPI) -> None:
"""Setup the extension"""
api.register("basedpython", BasedPython(api))
76 changes: 76 additions & 0 deletions extensions/clangd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from __future__ import annotations

import threading

__version__ = "0.0.1"
__version_info__ = tuple([int(num) for num in __version__.split(".")])

import subprocess
import typing
import zipfile
from pathlib import Path

import requests

from biscuit.extensions import Extension
from biscuit.language import Languages

if typing.TYPE_CHECKING:
from biscuit.api import ExtensionsAPI


class Clangd(Extension):
def __init__(self, api: ExtensionsAPI) -> None:
super().__init__(api)

self.langservers_path = Path(self.api.base.extensionsdir) / "langservers"
self.zip_path = self.langservers_path / "clangd.zip"
self.clangd_path = self.langservers_path / "clangd_18.1.3"
self.executable_path = self.clangd_path / "bin" / "clangd"
if self.api.sysinfo.is_windows:
self.executable_path = self.executable_path.with_suffix(".exe")

def install(self) -> None:
try:
subprocess.check_call(["clangd", "--version"])
self.api.register_langserver(Languages.CPP, "clangd")
self.api.register_langserver(Languages.C, "clangd")
except:
if not self.clangd_path.exists():
self.notification = self.api.notifications.info(
"Clangd executable not found in system PATH\n\nWould you like to install the Clangd binaries?",
actions=[
("Install", self.start_fetching),
],
)

self.api.register_langserver(Languages.CPP, str(self.executable_path))
self.api.register_langserver(Languages.C, str(self.executable_path))

def start_fetching(self, *_) -> None:
threading.Thread(target=self.fetch_clangd, daemon=True).start()

def fetch_clangd(self) -> None:
self.notification.delete()
self.langservers_path.mkdir(exist_ok=True)
self.api.notifications.info(f"Downloading clangd binaries...")

if self.api.sysinfo.is_windows:
url = "https://github.com/clangd/clangd/releases/download/18.1.3/clangd-windows-18.1.3.zip"
else:
url = "https://github.com/clangd/clangd/releases/download/18.1.3/clangd-linux-18.1.3.zip"

response = requests.get(url)

with open(self.zip_path, "wb") as file:
file.write(response.content)

with zipfile.ZipFile(self.zip_path, "r") as zip_ref:
zip_ref.extractall(self.langservers_path)

self.api.notifications.info(f"Clangd binaries installed successfully.")


def setup(api: ExtensionsAPI) -> None:
"""Setup the extension"""
api.register("clangd", Clangd(api))
24 changes: 13 additions & 11 deletions extensions/statsonbar.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
from __future__ import annotations

import time

__version__ = "0.2.0"
__version_info__ = tuple([int(num) for num in __version__.split(".")])

import threading
import time
import tkinter as tk
import typing

if typing.TYPE_CHECKING:
from biscuit.api import ExtensionsAPI


class StatsOnBar:
"""System stats for Biscuit statusbar (author: @billyeatcookies)
Contributes:
- adds sysinfo to the statusbar
"""

def __init__(self, api: ExtensionsAPI) -> None:
self.api = api
self.statusbar = self.api.statusbar
Expand All @@ -27,15 +21,23 @@ def __init__(self, api: ExtensionsAPI) -> None:
text=self.sysinfo.get_current_stats(),
icon="pulse",
description="CPU and Memory usage",
side=tk.LEFT,
padx=(2, 0),
)
threading.Thread(target=self.update_stats, daemon=True).start()

def update_stats(self) -> None:
while True:
while self.alive:
time.sleep(1)
self.btn.change_text(self.sysinfo.get_current_stats())

def install(self) -> None: ...
def install(self) -> None:
self.alive = True
self.btn.show()
threading.Thread(target=self.update_stats, daemon=True).start()

def uninstall(self) -> None:
self.alive = False
self.btn.destroy()


def setup(api: ExtensionsAPI) -> StatsOnBar:
Expand Down

0 comments on commit 2d46aff

Please sign in to comment.