From 9117709fd74bf82c59dea09d31bb3d628929ac03 Mon Sep 17 00:00:00 2001 From: KMohZaid <68484509+KMohZaid@users.noreply.github.com> Date: Sun, 25 Aug 2024 01:28:52 +0530 Subject: [PATCH] notfy: give ack. about ruff linter and formatter (#94) * notfy: give ack. about ruff linter and formatter --- pylsp_ruff/plugin.py | 62 ++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/pylsp_ruff/plugin.py b/pylsp_ruff/plugin.py index 833f16b..7b95212 100644 --- a/pylsp_ruff/plugin.py +++ b/pylsp_ruff/plugin.py @@ -116,6 +116,7 @@ def pylsp_format_document(workspace: Workspace, document: Document) -> Generator Document to apply ruff on. """ + log.debug(f"textDocument/formatting: {document}") outcome = yield result = outcome.get_result() @@ -128,34 +129,37 @@ def pylsp_format_document(workspace: Workspace, document: Document) -> Generator if not settings.format_enabled: return - new_text = run_ruff_format( - settings=settings, document_path=document.path, document_source=source - ) - - if settings.format: - # A second pass through the document with `ruff check` and only the rules - # enabled via the format config property. This allows for things like - # specifying `format = ["I"]` to get import sorting as part of formatting. - new_text = run_ruff( - settings=PluginSettings( - ignore=["ALL"], select=settings.format, executable=settings.executable - ), - document_path=document.path, - document_source=new_text, - fix=True, + with workspace.report_progress("format: ruff"): + new_text = run_ruff_format( + settings=settings, document_path=document.path, document_source=source ) - # Avoid applying empty text edit - if not new_text or new_text == source: - return + if settings.format: + # A second pass through the document with `ruff check` and only the rules + # enabled via the format config property. This allows for things like + # specifying `format = ["I"]` to get import sorting as part of formatting. + new_text = run_ruff( + settings=PluginSettings( + ignore=["ALL"], + select=settings.format, + executable=settings.executable, + ), + document_path=document.path, + document_source=new_text, + fix=True, + ) - range = Range( - start=Position(line=0, character=0), - end=Position(line=len(document.lines), character=0), - ) - text_edit = TextEdit(range=range, new_text=new_text) + # Avoid applying empty text edit + if not new_text or new_text == source: + return + + range = Range( + start=Position(line=0, character=0), + end=Position(line=len(document.lines), character=0), + ) + text_edit = TextEdit(range=range, new_text=new_text) - outcome.force_result(converter.unstructure([text_edit])) + outcome.force_result(converter.unstructure([text_edit])) @hookimpl @@ -174,10 +178,12 @@ def pylsp_lint(workspace: Workspace, document: Document) -> List[Dict]: List of dicts containing the diagnostics. """ - settings = load_settings(workspace, document.path) - checks = run_ruff_check(document=document, settings=settings) - diagnostics = [create_diagnostic(check=c, settings=settings) for c in checks] - return converter.unstructure(diagnostics) + + with workspace.report_progress("lint: ruff"): + settings = load_settings(workspace, document.path) + checks = run_ruff_check(document=document, settings=settings) + diagnostics = [create_diagnostic(check=c, settings=settings) for c in checks] + return converter.unstructure(diagnostics) def create_diagnostic(check: RuffCheck, settings: PluginSettings) -> Diagnostic: