format code with ruff

This commit is contained in:
dece 2024-08-21 07:57:24 +02:00
parent e5e097f4a2
commit 254bb68c95
3 changed files with 53 additions and 28 deletions

View file

@ -11,8 +11,13 @@ DEFAULT_LOG_FILE = "/tmp/italianswirls.log"
def main():
argparser = argparse.ArgumentParser(description=DESCRIPTION)
argparser.add_argument("-d", "--debug", nargs="?", const=DEFAULT_LOG_FILE,
help=f"debug log (default: {DEFAULT_LOG_FILE})")
argparser.add_argument(
"-d",
"--debug",
nargs="?",
const=DEFAULT_LOG_FILE,
help=f"debug log (default: {DEFAULT_LOG_FILE})",
)
args = argparser.parse_args()
if debug_log_file := args.debug:

View file

@ -6,10 +6,18 @@ from typing import Generator, Optional, Union
from jedi.api.classes import Name
from jedi.api.refactoring import Refactoring
from lsprotocol.types import (CompletionItemKind, Location, Position, Range,
RenameFile, RenameFileOptions,
ResourceOperationKind, TextDocumentEdit,
TextEdit, VersionedTextDocumentIdentifier)
from lsprotocol.types import (
CompletionItemKind,
Location,
Position,
Range,
RenameFile,
RenameFileOptions,
ResourceOperationKind,
TextDocumentEdit,
TextEdit,
VersionedTextDocumentIdentifier,
)
from pygls.workspace import Workspace
JEDI_COMPLETION_TYPE_MAP = {
@ -67,10 +75,7 @@ def get_lsp_locations(names: list[Name]) -> list[Location]:
def get_lsp_completion_kind(jedi_compl_type: str) -> CompletionItemKind:
"""Return an LSP completion item kind from this Jedi completion type."""
return JEDI_COMPLETION_TYPE_MAP.get(
jedi_compl_type,
CompletionItemKind.Text
)
return JEDI_COMPLETION_TYPE_MAP.get(jedi_compl_type, CompletionItemKind.Text)
def _build_line_offsets(text: str) -> list[int]:
@ -119,8 +124,8 @@ def _gen_document_text_edits(
new_code = changed_file.get_new_code()
line_offsets = _build_line_offsets(old_code)
edit_operations = (
opcode for opcode in
difflib.SequenceMatcher(a=old_code, b=new_code).get_opcodes()
opcode
for opcode in difflib.SequenceMatcher(a=old_code, b=new_code).get_opcodes()
if opcode[0] != "equal"
)
text_edits: list[TextEdit] = []
@ -153,5 +158,5 @@ def _gen_document_renames(
kind=ResourceOperationKind.Rename,
old_uri=old_name.as_uri(),
new_uri=new_name.as_uri(),
options=RenameFileOptions(ignore_if_exists=True, overwrite=True)
options=RenameFileOptions(ignore_if_exists=True, overwrite=True),
)

View file

@ -3,23 +3,39 @@ from typing import Optional
from jedi import Script
from jedi.api.refactoring import RefactoringError
from lsprotocol.types import (CompletionItem, CompletionList, CompletionOptions,
CompletionParams, DefinitionParams, Hover,
HoverParams, InsertTextFormat, Location,
ReferenceParams, RenameParams,
TextDocumentPositionParams, TypeDefinitionParams,
WorkspaceEdit,
TEXT_DOCUMENT_COMPLETION, TEXT_DOCUMENT_DEFINITION,
TEXT_DOCUMENT_HOVER, TEXT_DOCUMENT_REFERENCES,
TEXT_DOCUMENT_RENAME,
TEXT_DOCUMENT_TYPE_DEFINITION)
from lsprotocol.types import (
CompletionItem,
CompletionList,
CompletionOptions,
CompletionParams,
DefinitionParams,
Hover,
HoverParams,
InsertTextFormat,
Location,
ReferenceParams,
RenameParams,
TextDocumentPositionParams,
TypeDefinitionParams,
WorkspaceEdit,
TEXT_DOCUMENT_COMPLETION,
TEXT_DOCUMENT_DEFINITION,
TEXT_DOCUMENT_HOVER,
TEXT_DOCUMENT_REFERENCES,
TEXT_DOCUMENT_RENAME,
TEXT_DOCUMENT_TYPE_DEFINITION,
)
from pygls.server import LanguageServer
from pygls.workspace import Document
from italianswirls.glue import (gen_document_edits, get_jedi_position,
get_lsp_completion_kind, get_lsp_locations)
from italianswirls.glue import (
gen_document_edits,
get_jedi_position,
get_lsp_completion_kind,
get_lsp_locations,
)
LS = LanguageServer('italianswirls', 'v0.0.1')
LS = LanguageServer("italianswirls", "v0.0.1")
def get_jedi_script(document: Document) -> Script:
@ -28,8 +44,7 @@ def get_jedi_script(document: Document) -> Script:
def get_jedi_script_from_params(
params: TextDocumentPositionParams,
server: LanguageServer
params: TextDocumentPositionParams, server: LanguageServer
) -> Script:
"""Get Jedi Script using text document params provided by the client."""
document_uri = params.text_document.uri