-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basedpython, clangd extensions
- Loading branch information
Showing
5 changed files
with
146 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters