8000 check pyproject for ruff entry, add (.)ruff.toml · kstrauser/python-lsp-ruff@d6755af · GitHub
[go: up one dir, main page]

Skip to content

Commit d6755af

Browse files
committed
check pyproject for ruff entry, add (.)ruff.toml
1 parent d11a03f commit d6755af

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

pylsp_ruff/plugin.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
from subprocess import PIPE, Popen
77
from typing import Dict, Generator, List, Optional
88

9+
if sys.version_info >= (3, 11):
10+
import tomllib
11+
else:
12+
import tomli as tomllib
13+
914
from lsprotocol.types import (
1015
CodeAction,
1116
CodeActionContext,
@@ -527,12 +532,23 @@ def load_settings(workspace: Workspace, document_path: str) -> PluginSettings:
527532
workspace.root_path, document_path, ["pyproject.toml"]
528533
)
529534

530-
# Check if pyproject is present, ignore user settings if toml exists
535+
config_in_pyproject = False
531536
if pyproject_file:
532-
log.debug(
533-
f"Found pyproject file: {str(pyproject_file[0])}, "
534-
+ "skipping pylsp config."
535-
)
537+
try:
538+
with open(pyproject_file[0], "rb") as f:
539+
toml_dict = tomllib.load(f)
540+
except tomllib.TOMLDecodeError:
541+
log.warn("Error while parsing toml file, ignoring config.")
542+
if "tool.ruff" in toml_dict:
543+
config_in_pyproject = True
544+
545+
ruff_toml = find_parents(
546+
workspace.root_path, document_path, ["ruff.toml", ".ruff.toml"]
547+
)
548+
549+
# Check if pyproject is present, ignore user settings if toml exists
550+
if config_in_pyproject or ruff_toml:
551+
log.debug("Found existing configuration for ruff, skipping pylsp config.")
536552
# Leave config to pyproject.toml
537553
return PluginSettings(
538554
enabled=plugin_settings.executable,

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies = [
1616
"ruff>=0.0.260",
1717
"python-lsp-server",
1818
"lsprotocol>=2022.0.0a1",
19+
"tomli>=1.1.0; python_version < '3.11'",
1920
]
2021

2122
[project.optional-dependencies]

0 commit comments

Comments
 (0)
0