Skip to content

Commit

Permalink
Make standard library detection opt-out (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Jan 25, 2024
1 parent e7f69bc commit 458292f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
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

0 comments on commit 458292f

Please sign in to comment.