|
6 | 6 | from subprocess import PIPE, Popen |
7 | 7 | from typing import Dict, Generator, List, Optional |
8 | 8 |
|
| 9 | +if sys.version_info >= (3, 11): |
| 10 | + import tomllib |
| 11 | +else: |
| 12 | + import tomli as tomllib |
| 13 | + |
9 | 14 | from lsprotocol.types import ( |
10 | 15 | CodeAction, |
11 | 16 | CodeActionContext, |
@@ -527,12 +532,23 @@ def load_settings(workspace: Workspace, document_path: str) -> PluginSettings: |
527 | 532 | workspace.root_path, document_path, ["pyproject.toml"] |
528 | 533 | ) |
529 | 534 |
|
530 | | - # Check if pyproject is present, ignore user settings if toml exists |
| 535 | + config_in_pyproject = False |
531 | 536 | 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.") |
536 | 552 | # Leave config to pyproject.toml |
537 | 553 | return PluginSettings( |
538 | 554 | enabled=plugin_settings.executable, |
|
0 commit comments