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

Make standard library detection opt-out #363

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,13 +885,15 @@ def document_from_kind(uri: str, kind: str) -> Document:
return Document.from_cell_or_text_uri(uri)

document_path = _uri_to_fs_path(params.text_document.uri)
if utils.is_stdlib_file(document_path):
settings = _get_settings_by_document(document_path)

if settings.get("ignoreStandardLibrary", True) and utils.is_stdlib_file(
document_path
):
# Don't format standard library files.
# Publishing empty list clears the entry.
return None

settings = _get_settings_by_document(document_path)

if settings["organizeImports"]:
# Generate the "Ruff: Organize Imports" edit
for kind in (
Expand Down Expand Up @@ -1758,7 +1760,7 @@ async def _run_check_on_document(
only: Sequence[str] | None = None,
) -> ExecutableResult | None:
"""Runs the Ruff `check` subcommand on the given document source."""
if document.is_stdlib_file():
if settings.get("ignoreStandardLibrary", True) and document.is_stdlib_file():
log_warning(f"Skipping standard library file: {document.path}")
return None

Expand Down Expand Up @@ -1820,11 +1822,12 @@ async def _run_check_on_document(

async def _run_format_on_document(document: Document) -> ExecutableResult | None:
"""Runs the Ruff `format` subcommand on the given document source."""
if document.is_stdlib_file():
settings = _get_settings_by_document(document.path)

if settings.get("ignoreStandardLibrary", True) and document.is_stdlib_file():
log_warning(f"Skipping standard library file: {document.path}")
return None

settings = _get_settings_by_document(document.path)
executable = _find_ruff_binary(settings, VERSION_REQUIREMENT_FORMATTER)
argv: list[str] = [
"format",
Expand Down
3 changes: 3 additions & 0 deletions ruff_lsp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class UserSettings(TypedDict, total=False):
format: Format
"""Settings specific to format capabilities."""

ignoreStandardLibrary: bool
"""Whether to ignore files in the standard library when running Ruff."""

# Deprecated: use `lint.args` instead.
args: list[str]
"""Additional command-line arguments to pass to `ruff check`."""
Expand Down
Loading