Skip to content

Commit

Permalink
Use .extend instead of += (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
Moosems authored Jul 20, 2024
1 parent fc06d82 commit 507b82f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion salve/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion salve/server_functions/autocompletions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion salve/server_functions/highlight/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions salve/server_functions/highlight/links_and_hidden_chars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions salve/server_functions/highlight/tree_sitter_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions salve/server_functions/replacements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 507b82f

Please sign in to comment.