Skip to content

Commit

Permalink
Change line length and reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Moosems committed May 30, 2024
1 parent 41b83fe commit 8f68e62
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 20 deletions.
3 changes: 2 additions & 1 deletion examples/simple_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
context = IPC()

context.update_file(
"test", "test file with testing words which should return test then testing"
"test",
"test file with testing words which should return test then testing",
)

context.request(
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[tool.black]
line-length = 88
line-length = 79

[tool.isort]
line_length = 88
line_length = 79
profile = "black"
multi_line_output = 3

[tool.ruff]
line-length = 125
line-length = 79
2 changes: 1 addition & 1 deletion salve_ipc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .highlight import Token, tokens_from_result, generic_tokens # noqa: F401
from .highlight import Token, generic_tokens, tokens_from_result # noqa: F401
from .ipc import IPC # noqa: F401
from .misc import COMMANDS, Request, Response # noqa: F401
from .server_functions import is_unicode_letter # noqa: F401
7 changes: 6 additions & 1 deletion salve_ipc/highlight/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
from .highlight import Token, get_highlights, tokens_from_result, generic_tokens # noqa: F401
from .highlight import ( # noqa: F401
Token,
generic_tokens,
get_highlights,
tokens_from_result,
)
1 change: 1 addition & 0 deletions salve_ipc/highlight/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
@dataclass
class Token:
"""Generic Token class that makes highlighting files simple and easy"""

start_index: tuple[int, int] # line, column
token_length: int
highlight_type: str
Expand Down
14 changes: 7 additions & 7 deletions salve_ipc/ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

class IPC:
"""The IPC class is used to talk to the server and run commands ("autocomplete", "replacements", and "highlight"). The public API includes the following methods:
- IPC.ping()
- IPC.request()
- IPC.cancel_request()
- IPC.update_file()
- IPC.remove_file()
- IPC.kill_IPC()
"""
- IPC.ping()
- IPC.request()
- IPC.cancel_request()
- IPC.update_file()
- IPC.remove_file()
- IPC.kill_IPC()
"""

def __init__(self, id_max: int = 15_000) -> None:
self.used_ids: list[int] = []
Expand Down
11 changes: 8 additions & 3 deletions salve_ipc/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,38 @@

class Message(TypedDict):
"""Base class for messages in and out of the server"""

id: int
type: str # Can be "ping", "request", "response", "cancelled", "notification"


class Request(Message):
"""Request results/output from the server with command specific input"""

command: str # Can only be commands in COMMANDS
file: str
expected_keywords: NotRequired[list[str]] # autocomplete, replacements
current_word: NotRequired[str] # autocomplete, replacements
language: NotRequired[str] # highlight
expected_keywords: NotRequired[list[str]] # autocomplete, replacements
current_word: NotRequired[str] # autocomplete, replacements
language: NotRequired[str] # highlight


class Ping(Message):
"""Not really different from a standard Message but the Ping type allows for nice differentiation"""

...


class Notification(Message):
"""Notifies the server to add/update/remove a file for usage in fulfilling commands"""

filename: str
remove: bool
diff: NotRequired[str]


class Response(Message):
"""Server responses to requests, notifications, and pings"""

cancelled: bool
command: NotRequired[str]
result: NotRequired[list[str]]
1 change: 1 addition & 0 deletions salve_ipc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class Handler:
"""Handles input from the user and returns output from special functions designed to make the job easy. Not an external API."""

def __init__(self) -> None:
set_blocking(stdin.fileno(), False)
set_blocking(stdout.fileno(), False)
Expand Down
15 changes: 11 additions & 4 deletions salve_ipc/server_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,22 @@ def find_autocompletions(
]

relevant_words = [
word for word in words_after_original_removal if word.startswith(current_word)
word
for word in words_after_original_removal
if word.startswith(current_word)
]

no_usable_words_in_text: bool = not relevant_words
if no_usable_words_in_text:
relevant_words += expected_keywords

relevant_words = [word for word in relevant_words if word.startswith(current_word)]
relevant_words = [
word for word in relevant_words if word.startswith(current_word)
]

autocomplete_matches = sorted(
set(relevant_words), key=(lambda s: (-relevant_words.count(s), len(s), s))
set(relevant_words),
key=(lambda s: (-relevant_words.count(s), len(s), s)),
)

return autocomplete_matches
Expand Down Expand Up @@ -82,7 +87,9 @@ def get_replacements(
)

# Reintroduce duplicates
similar_with_duplicates = [word for word in starter_words if word in similar_words]
similar_with_duplicates = [
word for word in starter_words if word in similar_words
]

ranked_matches = sorted(
set(similar_with_duplicates),
Expand Down

0 comments on commit 8f68e62

Please sign in to comment.