Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename deprecated function / types #263

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,23 @@ class VersionModified(NamedTuple):
@LSP_SERVER.feature(TEXT_DOCUMENT_DID_OPEN)
async def did_open(params: DidOpenTextDocumentParams) -> None:
"""LSP handler for textDocument/didOpen request."""
document = LSP_SERVER.workspace.get_document(params.text_document.uri)
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
diagnostics: list[Diagnostic] = await _lint_document_impl(document)
LSP_SERVER.publish_diagnostics(document.uri, diagnostics)


@LSP_SERVER.feature(TEXT_DOCUMENT_DID_CLOSE)
def did_close(params: DidCloseTextDocumentParams) -> None:
"""LSP handler for textDocument/didClose request."""
document = LSP_SERVER.workspace.get_document(params.text_document.uri)
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
# Publishing empty diagnostics to clear the entries for this file.
LSP_SERVER.publish_diagnostics(document.uri, [])


@LSP_SERVER.feature(TEXT_DOCUMENT_DID_SAVE)
async def did_save(params: DidSaveTextDocumentParams) -> None:
"""LSP handler for textDocument/didSave request."""
document = LSP_SERVER.workspace.get_document(params.text_document.uri)
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
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 @@ -208,13 +208,13 @@ async def did_save(params: DidSaveTextDocumentParams) -> None:
@LSP_SERVER.feature(TEXT_DOCUMENT_DID_CHANGE)
async def did_change(params: DidChangeTextDocumentParams) -> None:
"""LSP handler for textDocument/didChange request."""
document = LSP_SERVER.workspace.get_document(params.text_document.uri)
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
if lint_run(_get_settings_by_document(document)) == "onType":
diagnostics: list[Diagnostic] = await _lint_document_impl(document)
LSP_SERVER.publish_diagnostics(document.uri, diagnostics)


async def _lint_document_impl(document: workspace.Document) -> list[Diagnostic]:
async def _lint_document_impl(document: workspace.TextDocument) -> list[Diagnostic]:
result = await _run_check_on_document(document)
if result is None:
return []
Expand Down Expand Up @@ -364,7 +364,7 @@ def _get_severity(code: str) -> DiagnosticSeverity:
@LSP_SERVER.feature(TEXT_DOCUMENT_HOVER)
async def hover(params: HoverParams) -> Hover | None:
"""LSP handler for textDocument/hover request."""
document = LSP_SERVER.workspace.get_document(params.text_document.uri)
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
match = NOQA_REGEX.search(document.lines[params.position.line])
if not match:
return None
Expand Down Expand Up @@ -455,7 +455,7 @@ class LegacyFix(TypedDict):
)
async def code_action(params: CodeActionParams) -> list[CodeAction] | None:
"""LSP handler for textDocument/codeAction request."""
document = LSP_SERVER.workspace.get_document(params.text_document.uri)
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)

settings = _get_settings_by_document(document)

Expand Down Expand Up @@ -670,7 +670,7 @@ async def code_action(params: CodeActionParams) -> list[CodeAction] | None:
@LSP_SERVER.feature(CODE_ACTION_RESOLVE)
async def resolve_code_action(params: CodeAction) -> CodeAction:
"""LSP handler for codeAction/resolve request."""
document = LSP_SERVER.workspace.get_document(cast(str, params.data))
document = LSP_SERVER.workspace.get_text_document(cast(str, params.data))

settings = _get_settings_by_document(document)

Expand All @@ -696,7 +696,7 @@ async def resolve_code_action(params: CodeAction) -> CodeAction:
@LSP_SERVER.command("ruff.applyAutofix")
async def apply_autofix(arguments: tuple[TextDocument]):
uri = arguments[0]["uri"]
text_document = LSP_SERVER.workspace.get_document(uri)
text_document = LSP_SERVER.workspace.get_text_document(uri)
results = await _fix_document_impl(text_document)
LSP_SERVER.apply_edit(
_create_workspace_edits(text_document, results),
Expand All @@ -707,7 +707,7 @@ async def apply_autofix(arguments: tuple[TextDocument]):
@LSP_SERVER.command("ruff.applyOrganizeImports")
async def apply_organize_imports(arguments: tuple[TextDocument]):
uri = arguments[0]["uri"]
text_document = LSP_SERVER.workspace.get_document(uri)
text_document = LSP_SERVER.workspace.get_text_document(uri)
results = await _fix_document_impl(text_document, only="I001")
LSP_SERVER.apply_edit(
_create_workspace_edits(text_document, results),
Expand All @@ -720,7 +720,7 @@ async def apply_organize_imports(arguments: tuple[TextDocument]):
@LSP_SERVER.command("ruff.applyFormat")
async def apply_format(arguments: tuple[TextDocument]):
uri = arguments[0]["uri"]
text_document = LSP_SERVER.workspace.get_document(uri)
text_document = LSP_SERVER.workspace.get_text_document(uri)
results = await _format_document_impl(text_document)
LSP_SERVER.apply_edit(
_create_workspace_edits(text_document, results),
Expand All @@ -733,19 +733,19 @@ async def format_document(
params: DocumentFormattingParams,
) -> list[TextEdit] | None:
uri = params.text_document.uri
document = ls.workspace.get_document(uri)
document = ls.workspace.get_text_document(uri)
return await _format_document_impl(document)


async def _format_document_impl(
document: workspace.Document,
document: workspace.TextDocument,
) -> list[TextEdit]:
result = await _run_format_on_document(document)
return _result_to_edits(document, result)


async def _fix_document_impl(
document: workspace.Document,
document: workspace.TextDocument,
*,
only: str | None = None,
) -> list[TextEdit]:
Expand All @@ -754,7 +754,7 @@ async def _fix_document_impl(


def _result_to_edits(
document: workspace.Document,
document: workspace.TextDocument,
result: RunResult | None,
) -> list[TextEdit]:
if result is None:
Expand Down Expand Up @@ -787,7 +787,7 @@ def _result_to_edits(


def _create_workspace_edits(
document: workspace.Document,
document: workspace.TextDocument,
edits: Sequence[TextEdit | AnnotatedTextEdit],
) -> WorkspaceEdit:
return WorkspaceEdit(
Expand All @@ -803,7 +803,7 @@ def _create_workspace_edits(
)


def _create_workspace_edit(document: workspace.Document, fix: Fix) -> WorkspaceEdit:
def _create_workspace_edit(document: workspace.TextDocument, fix: Fix) -> WorkspaceEdit:
return WorkspaceEdit(
document_changes=[
TextDocumentEdit(
Expand Down Expand Up @@ -845,7 +845,7 @@ def _get_line_endings(text: str) -> str | None:
return None # No line ending found


def _match_line_endings(document: workspace.Document, text: str) -> str:
def _match_line_endings(document: workspace.TextDocument, text: str) -> str:
"""Ensures that the edited text line endings matches the document line endings."""
expected = _get_line_endings(document.source)
actual = _get_line_endings(text)
Expand Down Expand Up @@ -1013,7 +1013,7 @@ def _update_workspace_settings(settings: list[WorkspaceSettings]) -> None:
}


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

Expand All @@ -1025,7 +1025,7 @@ def _get_document_key(document: workspace.Document) -> str | None:


def _get_settings_by_document(
document: workspace.Document | None,
document: workspace.TextDocument | None,
) -> WorkspaceSettings:
if document is None or document.path is None:
return list(WORKSPACE_SETTINGS.values())[0]
Expand Down Expand Up @@ -1147,7 +1147,7 @@ def _executable_version(executable: str) -> Version:


async def _run_check_on_document(
document: workspace.Document,
document: workspace.TextDocument,
*,
extra_args: Sequence[str] = [],
only: str | None = None,
Expand Down Expand Up @@ -1192,7 +1192,7 @@ async def _run_check_on_document(
)


async def _run_format_on_document(document: workspace.Document) -> RunResult | None:
async def _run_format_on_document(document: workspace.TextDocument) -> RunResult | None:
"""Runs the Ruff `format` subcommand on the given document."""
if str(document.uri).startswith("vscode-notebook-cell"):
# Skip notebook cells
Expand Down Expand Up @@ -1227,7 +1227,7 @@ async def _run_format_on_document(document: workspace.Document) -> RunResult | N


async def _run_subcommand_on_document(
document: workspace.Document,
document: workspace.TextDocument,
version_requirement: SpecifierSet,
*,
args: Sequence[str],
Expand Down