Skip to content

Commit

Permalink
Start removing Tree Sitter Code
Browse files Browse the repository at this point in the history
Commit 1 in a series removing Tree Sitter Support from Salve in favor of Albero.
  • Loading branch information
Moosems committed Jul 25, 2024
1 parent 66a40a8 commit 201a699
Show file tree
Hide file tree
Showing 16 changed files with 4 additions and 685 deletions.
38 changes: 0 additions & 38 deletions examples/logging_tree_sitter_example.py

This file was deleted.

56 changes: 0 additions & 56 deletions examples/simple_mapping_example.py

This file was deleted.

32 changes: 0 additions & 32 deletions examples/simple_tree_sitter_highlights_example.py

This file was deleted.

2 changes: 0 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
pygments
pyeditorconfig
beartype
tree-sitter

# Testing
pytest
salve_dependency_hub

# Formatting
ruff
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pygments
pyeditorconfig
beartype
tree-sitter
2 changes: 0 additions & 2 deletions salve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
DEFINITION,
EDITORCONFIG,
HIGHLIGHT,
HIGHLIGHT_TREE_SITTER,
REPLACEMENTS,
Response,
)
from .server_functions import ( # noqa: F401, E402
Token,
generic_tokens,
is_unicode_letter,
make_unrefined_mapping,
)
6 changes: 0 additions & 6 deletions salve/ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from pathlib import Path
from random import randint

from beartype.typing import Callable

from .misc import (
COMMAND,
COMMANDS,
Expand Down Expand Up @@ -119,8 +117,6 @@ def request(
text_range: tuple[int, int] = (1, -1),
file_path: Path | str = Path(__file__),
definition_starters: list[tuple[str, str]] = [("", "before")],
tree_sitter_language: Callable[[], int] | Path | str | None = None,
mapping: dict[str, str] | None = None,
) -> None:
"""Sends the main_server a request of type command with given kwargs - external API"""
self.logger.debug("Beginning request")
Expand All @@ -147,8 +143,6 @@ def request(
text_range=text_range,
file_path=file_path,
definition_starters=definition_starters,
tree_sitter_language=tree_sitter_language,
mapping=mapping,
)

def cancel_request(self, command: str) -> None:
Expand Down
11 changes: 2 additions & 9 deletions salve/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"highlight",
"editorconfig",
"definition",
"highlight-tree-sitter",
]

COMMAND = str
Expand All @@ -21,8 +20,6 @@
HIGHLIGHT: COMMAND = COMMANDS[2]
EDITORCONFIG: COMMAND = COMMANDS[3]
DEFINITION: COMMAND = COMMANDS[4]
HIGHLIGHT_TREE_SITTER: COMMAND = COMMANDS[5]


class Message(TypedDict):
"""Base class for messages in and out of the server"""
Expand All @@ -38,18 +35,14 @@ class Request(Message):
file: str
expected_keywords: NotRequired[list[str]] # autocomplete, replacements
current_word: NotRequired[str] # autocomplete, replacements, definition
language: NotRequired[str] # highlight, highlight-tree-sitter
language: NotRequired[str] # highlight
text_range: NotRequired[
tuple[int, int]
] # highlight, highlight-tree-sitter
] # highlight
file_path: NotRequired[Path | str] # editorconfig
definition_starters: NotRequired[
list[tuple[str, str]]
] # definition (list of regexes)
tree_sitter_language: NotRequired[
Callable | Path | str
] # highlight-tree-sitter
mapping: NotRequired[dict[str, str]] # highlight-tree-sitter


class Notification(Message):
Expand Down
45 changes: 1 addition & 44 deletions salve/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from pathlib import Path
from time import sleep

from beartype.typing import Callable
from pyeditorconfig import get_config
from tree_sitter import Language, Parser

from .misc import (
COMMANDS,
Expand All @@ -21,8 +19,6 @@
get_definition,
get_highlights,
get_replacements,
lang_from_so,
tree_sitter_highlight,
)


Expand Down Expand Up @@ -123,9 +119,7 @@ def handle_request(self, request: Request) -> None:
command: str = request["command"]
id: int = self.newest_ids[command]
file: str = request["file"]
result: (
list[str | tuple[tuple[int, int], int, str]] | dict[str, str]
) = []
result: list[str | Token] | dict[str, str] = []
cancelled: bool = False

match request["command"]:
Expand Down Expand Up @@ -161,43 +155,6 @@ def handle_request(self, request: Request) -> None:
request["definition_starters"], # type: ignore
request["current_word"], # type: ignore
)
case "highlight-tree-sitter":
self.logger.info("Getting Tree Sitter highlights for request")

self.logger.debug("Getting language function")
language_function: Callable[[], int] | Path | str = request[
"tree_sitter_language"
] # type: ignore
if isinstance(language_function, Path):
self.logger.info("Language function is pathlib.Path")
lang = lang_from_so(
str(language_function.absolute()),
request["language"], # type: ignore
)
self.logger.debug("Language created")
elif isinstance(language_function, str):
self.logger.info("Language function is str")
lang = lang_from_so(
language_function,
request["language"], # type: ignore
) # type: ignore
self.logger.debug("Language created")
elif callable(language_function):
self.logger.info("Language function is actual function")
lang = Language(language_function())
self.logger.debug("Language created")

self.logger.debug("Creating Parser")
parser = Parser(lang)
self.logger.debug("Getting highlights from parser")
result = tree_sitter_highlight( # type: ignore
self.logger,
self.files[file],
request["language"], # type: ignore
request["mapping"], # type: ignore
parser,
request["text_range"], # type: ignore
)

case _:
self.logger.warning(f"Command {command} not recognized")
Expand Down
3 changes: 0 additions & 3 deletions salve/server_functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
Token,
generic_tokens,
get_highlights,
lang_from_so,
make_unrefined_mapping,
tree_sitter_highlight,
)
from .misc import is_unicode_letter # noqa: F401
from .replacements import get_replacements # noqa: F401
5 changes: 0 additions & 5 deletions salve/server_functions/highlight/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
from .highlight import get_highlights # noqa: F401
from .tokens import Token, generic_tokens # noqa: F401
from .tree_sitter_funcs import ( # noqa: F401
lang_from_so,
make_unrefined_mapping,
tree_sitter_highlight,
)
Loading

0 comments on commit 201a699

Please sign in to comment.