Skip to content

Commit

Permalink
Rename deprecated function / types (#263)
Browse files Browse the repository at this point in the history
This PR renames the deprecated symbols for `pygls` in `v1.1.0`.
  • Loading branch information
dhruvmanila committed Oct 6, 2023
1 parent 7705228 commit e114eea
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,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_text_document(params.text_document.uri)
if lint_run(_get_settings_by_document(document)) in ("onType", "onSave"):
if lint_run(_get_settings_by_document(document.path)) in ("onType", "onSave"):
diagnostics: list[Diagnostic] = await _lint_document_impl(document)
LSP_SERVER.publish_diagnostics(document.uri, diagnostics)

Expand All @@ -209,7 +209,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_text_document(params.text_document.uri)
if lint_run(_get_settings_by_document(document)) == "onType":
if lint_run(_get_settings_by_document(document.path)) == "onType":
diagnostics: list[Diagnostic] = await _lint_document_impl(document)
LSP_SERVER.publish_diagnostics(document.uri, diagnostics)

Expand Down Expand Up @@ -457,7 +457,7 @@ async def code_action(params: CodeActionParams) -> list[CodeAction] | None:
"""LSP handler for textDocument/codeAction request."""
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)

settings = _get_settings_by_document(document)
settings = _get_settings_by_document(document.path)

if utils.is_stdlib_file(document.path):
# Don't format standard library files.
Expand Down Expand Up @@ -672,7 +672,7 @@ async def resolve_code_action(params: CodeAction) -> CodeAction:
"""LSP handler for codeAction/resolve request."""
document = LSP_SERVER.workspace.get_text_document(cast(str, params.data))

settings = _get_settings_by_document(document)
settings = _get_settings_by_document(document.path)

if settings["organizeImports"] and params.kind in (
CodeActionKind.SourceOrganizeImports,
Expand Down Expand Up @@ -1013,8 +1013,8 @@ def _update_workspace_settings(settings: list[WorkspaceSettings]) -> None:
}


def _get_document_key(document: workspace.TextDocument) -> str | None:
document_workspace = Path(document.path)
def _get_document_key(document_path: str) -> str | None:
document_workspace = Path(document_path)
workspaces = {s["workspacePath"] for s in WORKSPACE_SETTINGS.values()}

while document_workspace != document_workspace.parent:
Expand All @@ -1024,16 +1024,11 @@ def _get_document_key(document: workspace.TextDocument) -> str | None:
return None


def _get_settings_by_document(
document: workspace.TextDocument | None,
) -> WorkspaceSettings:
if document is None or document.path is None:
return list(WORKSPACE_SETTINGS.values())[0]

key = _get_document_key(document)
def _get_settings_by_document(document_path: str) -> WorkspaceSettings:
key = _get_document_key(document_path)
if key is None:
# This is either a non-workspace file or there is no workspace.
workspace_path = os.fspath(Path(document.path).parent)
workspace_path = os.fspath(Path(document_path).parent)
return {
**_get_global_defaults(), # type: ignore[misc]
"cwd": None,
Expand Down Expand Up @@ -1161,7 +1156,7 @@ async def _run_check_on_document(
log_warning(f"Skipping standard library file: {document.path}")
return None

settings = _get_settings_by_document(document)
settings = _get_settings_by_document(document.path)

executable = _find_ruff_binary(settings, VERSION_REQUIREMENT_LINTER)
argv: list[str] = CHECK_ARGS + list(extra_args)
Expand Down Expand Up @@ -1202,7 +1197,7 @@ async def _run_format_on_document(document: workspace.TextDocument) -> RunResult
log_warning(f"Skipping standard library file: {document.path}")
return None

settings = _get_settings_by_document(document)
settings = _get_settings_by_document(document.path)
executable = _find_ruff_binary(settings, VERSION_REQUIREMENT_FORMATTER)
argv: list[str] = [
"format",
Expand Down Expand Up @@ -1233,7 +1228,7 @@ async def _run_subcommand_on_document(
args: Sequence[str],
) -> RunResult:
"""Runs the tool subcommand on the given document."""
settings = _get_settings_by_document(document)
settings = _get_settings_by_document(document.path)

executable = _find_ruff_binary(settings, version_requirement)
argv: list[str] = list(args)
Expand Down

0 comments on commit e114eea

Please sign in to comment.