Skip to content

Commit

Permalink
Misc. follow-ups to lint-specific settings (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Oct 2, 2023
1 parent 10acf3f commit f9eba0c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 13 additions & 7 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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"),
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions ruff_lsp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit f9eba0c

Please sign in to comment.