Skip to content

Commit

Permalink
Collegamento V1.2.0 (#89)
Browse files Browse the repository at this point in the history
* Update to match rc0

* Update for coming token_tools

* Update examples

* Fix small issues

* Is windows being normal??

* Format

* Bump version
  • Loading branch information
Moosems authored Sep 8, 2024
1 parent db662e3 commit 7904a27
Show file tree
Hide file tree
Showing 22 changed files with 87 additions and 215 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 align="center">Salve v1.1.1</h1>
<h1 align="center">Salve v1.2.0</h1>

# Installation

Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
project = "Salve"
copyright = "2024, Moosems"
author = "Moosems"
release = "v1.1.1"
release = "v1.2.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion docs/source/example-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Now that you have ``Salve`` installed, let's try running a simple example that p
sleep(1)
# If there is no response we give None instead of raising an Exception
output: Response | None = context.get_response(HIGHLIGHT)
output: Response | None = context.get_response(HIGHLIGHT) # type: ignore
print(output)
# Finally, if you are done with the IPC before the rest of the program, you can
Expand Down
43 changes: 0 additions & 43 deletions docs/source/examples/highlight_logging_example.rst

This file was deleted.

2 changes: 1 addition & 1 deletion examples/example_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main():

# Check output
# context.cancel_request("autocomplete") # Uncommenting this line will cause the request to always be cancelled
output: Response | None = context.get_response(AUTOCOMPLETE)
output: Response | None = context.get_response(AUTOCOMPLETE) # type: ignore
if not output:
continue

Expand Down
2 changes: 1 addition & 1 deletion examples/gui_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def create_request(_) -> None:
label.pack()

def loop() -> None:
output: Response | None = context.get_response(AUTOCOMPLETE)
output: Response | None = context.get_response(AUTOCOMPLETE) # type: ignore
data: list[str] = [""]
if output is not None:
data: list[str] = output["result"] # type: ignore
Expand Down
35 changes: 0 additions & 35 deletions examples/highlight_logging_example.py

This file was deleted.

2 changes: 1 addition & 1 deletion examples/simple_autocomplete_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def main():

sleep(1)

output: Response | None = context.get_response(AUTOCOMPLETE)
output: Response | None = context.get_response(AUTOCOMPLETE) # type: ignore
print(output)
context.kill_IPC()

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_definitions_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def main():
)

sleep(1)
output: Response | None = context.get_response(DEFINITION)
output: Response | None = context.get_response(DEFINITION) # type: ignore
print(output)
context.kill_IPC()

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_editorconfig_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def main():
context.request(EDITORCONFIG, file_path=__file__)

sleep(1)
output: Response | None = context.get_response(EDITORCONFIG)
output: Response | None = context.get_response(EDITORCONFIG) # type: ignore
print(output)
context.kill_IPC()

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_highlight_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def main():
)

sleep(1)
output: Response | None = context.get_response(HIGHLIGHT)
output: Response | None = context.get_response(HIGHLIGHT) # type: ignore
print(output)
context.kill_IPC()

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_links_and_hidden_chars_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main():
context.request(LINKS_AND_CHARS, file="test", text_range=(1, 30))

sleep(1)
output: Response | None = context.get_response(LINKS_AND_CHARS)
output: Response | None = context.get_response(LINKS_AND_CHARS) # type: ignore
print(output)
context.kill_IPC()

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_replacements_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def main():
)

sleep(1)
output: Response | None = context.get_response(REPLACEMENTS)
output: Response | None = context.get_response(REPLACEMENTS) # type: ignore
print(output)
context.kill_IPC()

Expand Down
12 changes: 4 additions & 8 deletions salve/ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,14 @@ def request( # type: ignore
definition_starters: list[tuple[str, str]] = [("", "before")],
) -> None:
"""Sends the main_server a request of type command with given kwargs - external API"""
self.logger.debug("Beginning request")
if command not in COMMANDS:
self.logger.exception(
f"Command {command} not in builtin commands. Those are {COMMANDS}!"
)
raise Exception(
f"Command {command} not in builtin commands. Those are {COMMANDS}!"
)

if file not in self.files and command != EDITORCONFIG:
self.logger.exception(f"File {file} does not exist in system!")
raise Exception(f"File {file} does not exist in system!")

self.logger.debug("Sending info to create_message()")
request: dict = {
"command": command,
"expected_keywords": expected_keywords,
Expand All @@ -80,6 +74,8 @@ def request( # type: ignore
"file_path": file_path,
"definition_starters": definition_starters,
}

if file:
request.update({"file": file})
super().request(request)
request["file"] = file

super().request(**request)
4 changes: 3 additions & 1 deletion salve/server_functions/highlight/docstring_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def proper_docstring_tokens(lexer: RegexLexer, full_text: str) -> list[Token]:
continue

start_pos: tuple[int, int] = (1, 0)
simple_token_type: str = get_new_token_type(str(token_type))
simple_token_type: str | None = get_new_token_type(str(token_type))
if not simple_token_type:
continue

while match:
span: tuple[int, int] = match.span()
Expand Down
4 changes: 2 additions & 2 deletions salve/server_functions/highlight/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def get_highlights(
for line in split_text:
og_tokens: _LexReturnTokens = list(lex(line, lexer))
for token in og_tokens:
new_type: str = get_new_token_type(str(token[0]))
new_type: str | None = get_new_token_type(str(token[0]))
token_str: str = token[1]
token_len: int = len(token_str)

if token_str == "\n":
# Lexer adds the newline back as its own token
continue

if not token_str.strip() or new_type == "Text":
if not token_str.strip() or not new_type:
# If the token is empty or is plain Text we simply skip it because that's ultimately useless info
start_index = (start_index[0], start_index[1] + token_len)
continue
Expand Down
41 changes: 20 additions & 21 deletions salve/server_functions/highlight/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

from token_tools import GENERIC_TOKENS

default_tokens: list[str] = [
"Token.Text.Whitespace",
"Token.Text",
"Token.Error",
"Token.Keyword",
"Token.Name",
"Token.Literal.String",
"Token.Literal.Number",
"Token.Literal",
"Token.Operator",
"Token.Punctuation",
"Token.Comment",
"Token.Generic",
]
default_tokens: dict[str, str | None] = {
"Token.Text.Whitespace": None,
"Token.Text": None,
"Token.Error": GENERIC_TOKENS[1],
"Token.Keyword": GENERIC_TOKENS[2],
"Token.Name": GENERIC_TOKENS[0],
"Token.Literal.String": GENERIC_TOKENS[4],
"Token.Literal.Number": GENERIC_TOKENS[5],
"Token.Literal": GENERIC_TOKENS[6],
"Token.Operator": GENERIC_TOKENS[7],
"Token.Punctuation": GENERIC_TOKENS[8],
"Token.Comment": GENERIC_TOKENS[9],
"Token.Generic": None,
}


def normal_text_range(
Expand All @@ -34,11 +34,10 @@ def normal_text_range(


@cache
def get_new_token_type(old_token: str) -> str:
def get_new_token_type(token: str) -> str | None:
"""Turns pygments token types into a generic predefined Token"""
new_type: str = GENERIC_TOKENS[0]
for index, token in enumerate(default_tokens):
if old_token.startswith(token):
new_type = GENERIC_TOKENS[index]
break
return new_type
for old_token, new_token in default_tokens.items():
if token.startswith(old_token):
return new_token

return None
1 change: 1 addition & 0 deletions salve/server_functions/links_and_hidden_chars.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def get_urls(whole_text: str, text_range: tuple[int, int]) -> list[Token]:
while True:
if start_pos[0] > text_range[1]:
break

line: str = lines[start_pos[0] - text_range[0]][start_pos[1] :]
match_start: Match[str] | None = url_regex.search(line)
if match_start is None:
Expand Down
4 changes: 1 addition & 3 deletions salve/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,5 @@ def get_special_tokens_request_wrapper(
) -> list[Token]:
return get_special_tokens(
request["file"], # type: ignore
normal_text_range(request["file"], request["text_range"])[ # type: ignore
1
],
normal_text_range(request["file"], request["text_range"])[1], # type: ignore
)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="salve",
version="1.1.1",
version="1.2.0",
description="Salve is an IPC library that can be used by code editors to easily get autocompletions, replacements, editorconfig suggestions, definitions, and syntax highlighting.",
author="Moosems",
author_email="[email protected]",
Expand Down
Loading

0 comments on commit 7904a27

Please sign in to comment.