diff --git a/ruff_lsp/server.py b/ruff_lsp/server.py index 82d14bc..ebce915 100755 --- a/ruff_lsp/server.py +++ b/ruff_lsp/server.py @@ -184,7 +184,7 @@ def did_close(params: DidCloseTextDocumentParams) -> None: async def did_save(params: DidSaveTextDocumentParams) -> None: """LSP handler for textDocument/didSave request.""" document = LSP_SERVER.workspace.get_document(params.text_document.uri) - if lint_run(_get_settings_by_document(document), "onSave") == "onSave": + if lint_run(_get_settings_by_document(document)) in ("onType", "onSave"): diagnostics: list[Diagnostic] = await _lint_document_impl(document) LSP_SERVER.publish_diagnostics(document.uri, diagnostics) @@ -193,7 +193,7 @@ async def did_save(params: DidSaveTextDocumentParams) -> None: async def did_change(params: DidChangeTextDocumentParams) -> None: """LSP handler for textDocument/didChange request.""" document = LSP_SERVER.workspace.get_document(params.text_document.uri) - if lint_run(_get_settings_by_document(document), "onType") == "onType": + if lint_run(_get_settings_by_document(document)) == "onType": diagnostics: list[Diagnostic] = await _lint_document_impl(document) LSP_SERVER.publish_diagnostics(document.uri, diagnostics) @@ -942,7 +942,7 @@ def _supports_code_action_resolve(capabilities: ClientCapabilities) -> bool: def _get_global_defaults() -> UserSettings: - return { + settings: UserSettings = { "codeAction": GLOBAL_SETTINGS.get("codeAction", {}), "fixAll": GLOBAL_SETTINGS.get("fixAll", True), "importStrategy": GLOBAL_SETTINGS.get("importStrategy", "fromEnvironment"), @@ -951,12 +951,18 @@ def _get_global_defaults() -> UserSettings: "logLevel": GLOBAL_SETTINGS.get("logLevel", "error"), "organizeImports": GLOBAL_SETTINGS.get("organizeImports", True), "path": GLOBAL_SETTINGS.get("path", []), - # Deprecated: use `lint.args` instead. - "args": GLOBAL_SETTINGS.get("args", []), - # Deprecated: use `lint.run` instead. - "run": GLOBAL_SETTINGS.get("run", "onType"), } + # Deprecated: use `lint.args` instead. + if "args" in GLOBAL_SETTINGS: + settings["args"] = GLOBAL_SETTINGS["args"] + + # Deprecated: use `lint.run` instead. + if "run" in GLOBAL_SETTINGS: + settings["run"] = GLOBAL_SETTINGS["run"] + + return settings + def _update_workspace_settings(settings: list[WorkspaceSettings]) -> None: if not settings: diff --git a/ruff_lsp/settings.py b/ruff_lsp/settings.py index e11953a..c5c3983 100644 --- a/ruff_lsp/settings.py +++ b/ruff_lsp/settings.py @@ -83,11 +83,11 @@ def lint_args(settings: UserSettings) -> list[str]: return [] -def lint_run(settings: UserSettings, default: Run) -> Run: +def lint_run(settings: UserSettings) -> Run: """Get the `lint.run` setting from the user settings.""" if "lint" in settings and "run" in settings["lint"]: return settings["lint"]["run"] elif "run" in settings: return settings["run"] else: - return default + return "onType"