8000 Add support for ruff `extension` option to enable `jupyterlab-lsp` (#59) · python-lsp/python-lsp-ruff@42095ef · GitHub
[go: up one dir, main page]

Skip to content

Commit 42095ef

Browse files
authored
Add support for ruff extension option to enable jupyterlab-lsp (#59)
1 parent 9ff905c commit 42095ef

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

pylsp_ruff/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ def build_check_arguments(
553553
args.append("--exit-zero")
554554
# Use the json formatting for easier evaluation
555555
args.append("--output-format=json")
556+
args.append("--extension=ipynb:python")
556557
if fix:
557558
args.append("--fix")
558559
else:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ readme = "README.md"
1313
requires-python = ">=3.7"
1414
license = {text = "MIT"}
1515
dependencies = [
16-
"ruff>=0.1.0, <0.2.0",
16+
"ruff>=0.1.5, <0.2.0",
1717
"python-lsp-server",
1818
"cattrs!=23.2.1",
1919
"lsprotocol>=2022.0.0a1",

tests/test_ruff_lint.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def f():
182182
"--quiet",
183183
"--exit-zero",
184184
"--output-format=json",
185+
"--extension=ipynb:python",
185186
"--no-fix",
186187
"--force-exclude",
187188
f"--stdin-filename={os.path.join(workspace.root_path, '__init__.py')}",
@@ -243,3 +244,23 @@ def f():
243244
assert diag["code"] != "F401"
244245

245246
os.unlink(os.path.join(workspace.root_path, "pyproject.toml"))
247+
248+
249+
def test_notebook_input(workspace):
250+
doc_str = r"""
251+
print('hi')
252+
import os
253+
def f():
254+
a = 2
255+
"""
256+
# attribute the python code to a notebook file name per jupyterlab-lsp
257+
doc_uri = uris.from_fs_path(os.path.join(workspace.root_path, "Untitled.ipynb"))
258+
workspace.put_document(doc_uri, doc_str)
259+
doc = workspace.get_document(doc_uri)
260+
261+
diags = ruff_lint.pylsp_lint(workspace, doc)
262+
diag_codes = [diag["code"] for diag in diags]
263+
assert "E999" not in diag_codes
264+
assert "E402" in diag_codes
265+
assert "F401" in diag_codes
266+
assert "F841" in diag_codes

0 commit comments

Comments
 (0)
0