From 507b82f0289472c1f66b6ee4f94b8f34fbd9c32a Mon Sep 17 00:00:00 2001 From: Moosems <95927277+Moosems@users.noreply.github.com> Date: Fri, 19 Jul 2024 20:17:22 -0600 Subject: [PATCH] Use .extend instead of += (#72) --- salve/server.py | 2 +- salve/server_functions/autocompletions.py | 4 +++- salve/server_functions/highlight/highlight.py | 2 +- .../server_functions/highlight/links_and_hidden_chars.py | 4 ++-- salve/server_functions/highlight/tree_sitter_funcs.py | 8 +++++--- salve/server_functions/replacements.py | 4 ++-- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/salve/server.py b/salve/server.py index 28155f6..8adf3ad 100644 --- a/salve/server.py +++ b/salve/server.py @@ -150,7 +150,7 @@ def handle_request(self, request: Request) -> None: language=request["language"], # type: ignore text_range=request["text_range"], # type: ignore ) - result += [token for token in pre_refined_result] # type: ignore + result.extend([token for token in pre_refined_result]) case "editorconfig": self.logger.info("Getting editorconfig info for request") result = get_config(request["file_path"]) # type: ignore diff --git a/salve/server_functions/autocompletions.py b/salve/server_functions/autocompletions.py index 9df366c..4e618fd 100644 --- a/salve/server_functions/autocompletions.py +++ b/salve/server_functions/autocompletions.py @@ -20,7 +20,9 @@ def find_autocompletions( no_usable_words_in_text: bool = not relevant_words if no_usable_words_in_text: - relevant_words += expected_keywords + relevant_words.extend( + expected_keywords * 3 + ) # We add a multiplier of three to boost the score of keywords relevant_words = [ word for word in relevant_words if word.startswith(current_word) diff --git a/salve/server_functions/highlight/highlight.py b/salve/server_functions/highlight/highlight.py index 12fdc05..1a92762 100644 --- a/salve/server_functions/highlight/highlight.py +++ b/salve/server_functions/highlight/highlight.py @@ -63,6 +63,6 @@ def get_highlights( new_tokens, proper_docstring_tokens(lexer, full_text) ) - new_tokens += get_special_tokens(full_text, split_text, text_range[0]) + new_tokens.extend(get_special_tokens(full_text, split_text, text_range[0])) new_tokens = only_tokens_in_text_range(new_tokens, text_range) return new_tokens diff --git a/salve/server_functions/highlight/links_and_hidden_chars.py b/salve/server_functions/highlight/links_and_hidden_chars.py index 2cfdf80..6d9ae47 100644 --- a/salve/server_functions/highlight/links_and_hidden_chars.py +++ b/salve/server_functions/highlight/links_and_hidden_chars.py @@ -112,8 +112,8 @@ def get_special_tokens( whole_text: str, split_text: list[str], start_offset: int ) -> list[Token]: return_tokens: list[Token] = [] - return_tokens += get_urls(split_text, start_offset) + return_tokens.extend(get_urls(split_text, start_offset)) if [char for char in hidden_chars if char in whole_text]: # If there are no hidden chars we don't want to needlessly compute this - return_tokens += find_hidden_chars(split_text, start_offset) + return_tokens.extend(find_hidden_chars(split_text, start_offset)) return return_tokens diff --git a/salve/server_functions/highlight/tree_sitter_funcs.py b/salve/server_functions/highlight/tree_sitter_funcs.py index fb0c772..8f841b2 100644 --- a/salve/server_functions/highlight/tree_sitter_funcs.py +++ b/salve/server_functions/highlight/tree_sitter_funcs.py @@ -54,8 +54,8 @@ def tree_sitter_highlight( tree = language_parser.parse(bytes(new_code, "utf8")) trees_and_parsers[language_str] = (tree, language_parser, new_code) return_tokens = node_to_tokens(tree.root_node, mapping, logger) - return_tokens += get_special_tokens( - new_code, split_text, text_range[0] + return_tokens.extend( + get_special_tokens(new_code, split_text, text_range[0]) ) return_tokens = only_tokens_in_text_range(return_tokens, text_range) return return_tokens @@ -65,7 +65,9 @@ def tree_sitter_highlight( trees_and_parsers[language_str] = (new_tree, parser, new_code) return_tokens = node_to_tokens(new_tree, mapping, logger) - return_tokens += get_special_tokens(new_code, split_text, text_range[0]) + return_tokens.extend( + get_special_tokens(new_code, split_text, text_range[0]) + ) return_tokens = only_tokens_in_text_range(return_tokens, text_range) return return_tokens diff --git a/salve/server_functions/replacements.py b/salve/server_functions/replacements.py index 9d09055..be6fa81 100644 --- a/salve/server_functions/replacements.py +++ b/salve/server_functions/replacements.py @@ -8,8 +8,8 @@ def get_replacements( ) -> list[str]: """Returns a list of possible and plausible replacements for a given word""" # Get all words in file - starter_words = find_words(full_text) - starter_words += ( + starter_words: list[str] = find_words(full_text) + starter_words.extend( expected_keywords * 3 ) # We add a multiplier of three to boost the score of keywords while replaceable_word in starter_words: