python-lsp/python-lsp-ruff

'E501 Line too long': Not showing in-line

rkshthrmsh opened this issue · 7 comments

I am using the Helix editor with pylsp as the language server and python-lsp-ruff as plugin for ruff. Most diagnostics appear inline in the editor as expected except E501 which is related to line legth. Running ruff directly on the violating file shows the error in the terminal.

ruff test.py
test.py:3:89: E501 Line too long (100 > 88 characters)

The log from pylsp is here:

2023-02-24 12:50:41,955 IST - DEBUG - pylsp.config.config -   pylsp_lint [hook]
      config: <pylsp.config.config.Config object at 0x104791f50>
      workspace: <pylsp.workspace.Workspace object at 0x104830ad0>
      document: file:///Users/rkshthrmsh/ws/sandbox/test.py
      is_saved: True

2023-02-24 12:50:41,956 IST - DEBUG - pylsp.config.config - Got user config from PyCodeStyleConfig: {}
2023-02-24 12:50:41,957 IST - DEBUG - pylsp.config.config - Got project config from PyCodeStyleConfig: {}
2023-02-24 12:50:41,957 IST - DEBUG - pylsp.config.config - With configuration: {'plugins': {'pyflakes': {'enabled': False}, 'pydocstyle': {'enabled': False}, 'rope_rename': {'enabled': False}, 'ruff': {'exclude': None, 'ignore': None, 'select': ['D'], 'lineLength': None, 'perFileIgnores': None, 'executable': 'ruff', 'config': None, 'enabled': True}, 'autopep8': {'enabled': False}, 'flake8': {'enabled': False}, 'preload': {'modules': ['OpenGL', 'PIL', 'array', 'audioop', 'binascii', 'cPickle', 'cStringIO', 'cmath', 'collections', 'datetime', 'errno', 'exceptions', 'gc', 'imageop', 'imp', 'itertools', 'marshal', 'math', 'matplotlib', 'mmap', 'mpmath', 'msvcrt', 'networkx', 'nose', 'nt', 'numpy', 'operator', 'os', 'os.path', 'pandas', 'parser', 'rgbimg', 'scipy', 'signal', 'skimage', 'sklearn', 'statsmodels', 'strop', 'sympy', 'sys', 'thread', 'time', 'wx', 'xxsubtype', 'zipimport', 'zlib']}, 'rope_autoimport': {'enabled': False, 'memory': False}, 'jedi_completion': {'fuzzy': True, 'include_class_objects': True, 'include_function_objects': True}, 'rope_completion': {'enabled': False, 'eager': False}, 'pycodestyle': {'enabled': False}, 'yapf': {'enabled': True}, 'pylint': {'enabled': False, 'args': [], 'executable': None}, 'mccabe': {'enabled': False}}, 'rope': {'extensionModules': ['OpenGL', 'PIL', 'array', 'audioop', 'binascii', 'cPickle', 'cStringIO', 'cmath', 'collections', 'datetime', 'errno', 'exceptions', 'gc', 'imageop', 'imp', 'itertools', 'marshal', 'math', 'matplotlib', 'mmap', 'mpmath', 'msvcrt', 'networkx', 'nose', 'nt', 'numpy', 'operator', 'os', 'os.path', 'pandas', 'parser', 'rgbimg', 'scipy', 'signal', 'skimage', 'sklearn', 'statsmodels', 'strop', 'sympy', 'sys', 'thread', 'time', 'wx', 'xxsubtype', 'zipimport', 'zlib']}}
2023-02-24 12:50:41,958 IST - DEBUG - pylsp_ruff.ruff_lint - Got ruff settings: {'exclude': None, 'ignore': None, 'select': ['D'], 'lineLength': None, 'perFileIgnores': None, 'line_length': 100, 'executable': 'ruff', 'config': None, 'enabled': True}
2023-02-24 12:50:41,958 IST - DEBUG - pylsp_ruff.ruff_lint - Calling ruff with args: ['--quiet', '--format=json', '--no-fix', '--force-exclude', '--stdin-filename', '/Users/rkshthrmsh/ws/sandbox/test.py', '--select=D', '--', '-'] on '/Users/rkshthrmsh/ws/sandbox/test.py'
2023-02-24 12:50:41,971 IST - DEBUG - pylsp.config.config -   finish pylsp_lint --> [[]] [hook]

2023-02-24 12:50:41,972 IST - DEBUG - pylsp_jsonrpc.endpoint - Sending notification: textDocument/publishDiagnostics {'uri': 'file:///Users/rkshthrmsh/ws/sandbox/test.py', 'diagnostics': []}
2023-02-24 12:50:43,477 IST - DEBUG - pylsp_jsonrpc.endpoint - Handling notification from client {'jsonrpc': '2.0', 'method': 'textDocument/didSave', 'params': {'text': '"""Implement CCSDS 123.0-B-2 Compression.\n\nCCSDS 123.0-B-2 specifies a standard for Low-Complexity Lossless and Near-Lossless Multispectral and\nHyper\n"""\n', 'textDocument': {'uri': 'file:///Users/rkshthrmsh/ws/sandbox/test.py'}}}
2023-02-24 12:50:43,480 IST - DEBUG - pylsp.config.config -   pylsp_document_did_save [hook]
      config: <pylsp.config.config.Config object at 0x104791f50>
      workspace: <pylsp.workspace.Workspace object at 0x104830ad0>
      document: file:///Users/rkshthrmsh/ws/sandbox/test.py

2023-02-24 12:50:43,480 IST - DEBUG - pylsp.config.config -   finish pylsp_document_did_save --> [] [hook]

2023-02-24 12:50:43,480 IST - DEBUG - pylsp_jsonrpc.endpoint - Handling request from client {'jsonrpc': '2.0', 'method': 'shutdown', 'params': None, 'id': 1}
2023-02-24 12:50:43,480 IST - DEBUG - pylsp_jsonrpc.endpoint - Got result from synchronous request handler: None
2023-02-24 12:50:43,481 IST - DEBUG - pylsp_jsonrpc.endpoint - Handling notification from client {'jsonrpc': '2.0', 'method': 'exit', 'params': None}

Based on the log files it looks like you provide python-lsp-server with 'line_length': 100 in your lsp configuration file for helix(the same place where you specified the "select" argument for ruff). Remove that line to get the default length of 88.

Change made, but still not able to see the in-line warning. Log after change:

2023-02-24 14:28:05,761 IST - DEBUG - pylsp.config.config - Got user config from PyCodeStyleConfig: {}
2023-02-24 14:28:05,762 IST - DEBUG - pylsp.config.config - Got project config from PyCodeStyleConfig: {}
2023-02-24 14:28:05,762 IST - DEBUG - pylsp.config.config - With configuration: {'rope': {'extensionModules': ['OpenGL', 'PIL', 'array', 'audioop', 'binascii', 'cPickle', 'cStringIO', 'cmath', 'collections', 'datetime', 'errno', 'exceptions', 'gc', 'imageop', 'imp', 'itertools', 'marshal', 'math', 'matplotlib', 'mmap', 'mpmath', 'msvcrt', 'networkx', 'nose', 'nt', 'numpy', 'operator', 'os', 'os.path', 'pandas', 'parser', 'rgbimg', 'scipy', 'signal', 'skimage', 'sklearn', 'statsmodels', 'strop', 'sympy', 'sys', 'thread', 'time', 'wx', 'xxsubtype', 'zipimport', 'zlib']}, 'plugins': {'pycodestyle': {'enabled': False}, 'mccabe': {'enabled': False}, 'pydocstyle': {'enabled': False}, 'jedi_completion': {'fuzzy': True, 'include_class_objects': True, 'include_function_objects': True}, 'rope_rename': {'enabled': False}, 'ruff': {'exclude': None, 'ignore': None, 'enabled': True, 'lineLength': None, 'executable': 'ruff', 'select': ['D'], 'config': None, 'perFileIgnores': None}, 'rope_completion': {'enabled': True, 'eager': True}, 'autopep8': {'enabled': False}, 'preload': {'modules': ['OpenGL', 'PIL', 'array', 'audioop', 'binascii', 'cPickle', 'cStringIO', 'cmath', 'collections', 'datetime', 'errno', 'exceptions', 'gc', 'imageop', 'imp', 'itertools', 'marshal', 'math', 'matplotlib', 'mmap', 'mpmath', 'msvcrt', 'networkx', 'nose', 'nt', 'numpy', 'operator', 'os', 'os.path', 'pandas', 'parser', 'rgbimg', 'scipy', 'signal', 'skimage', 'sklearn', 'statsmodels', 'strop', 'sympy', 'sys', 'thread', 'time', 'wx', 'xxsubtype', 'zipimport', 'zlib']}, 'pylint': {'enabled': False, 'args': [], 'executable': None}, 'flake8': {'enabled': False}, 'pyflakes': {'enabled': False}, 'rope_autoimport': {'enabled': True, 'memory': True}, 'yapf': {'enabled': True}}}
2023-02-24 14:28:05,763 IST - DEBUG - pylsp_ruff.ruff_lint - Got ruff settings: {'exclude': None, 'ignore': None, 'enabled': True, 'lineLength': None, 'executable': 'ruff', 'select': ['D'], 'config': None, 'perFileIgnores': None}
2023-02-24 14:28:05,763 IST - DEBUG - pylsp_ruff.ruff_lint - Calling ruff with args: ['--quiet', '--format=json', '--no-fix', '--force-exclude', '--stdin-filename', '/Users/rkshthrmsh/ws/sandbox/python_study_group/test.py', '--select=D', '--', '-'] on '/Users/rkshthrmsh/ws/sandbox/python_study_group/test.py'
2023-02-24 14:28:05,776 IST - DEBUG - pylsp.config.config -   finish pylsp_lint --> [[]] [hook]

2023-02-24 14:28:05,776 IST - DEBUG - pylsp_jsonrpc.endpoint - Sending notification: textDocument/publishDiagnostics {'uri': 'file:///Users/rkshthrmsh/ws/sandbox/python_study_group/test.py', 'diagnostics': []}
2023-02-24 14:28:07,565 IST - DEBUG - pylsp_jsonrpc.endpoint - Handling notification from client {'jsonrpc': '2.0', 'method': 'textDocument/didSave', 'params': {'text': '"""Implement CCSDS 123.0-B-2 Compression.\n\nCCSDS 123.0-B-2 specifies a standard for Low-Complexity Lossless and Near-Lossless Multispectral and\nHyper\n"""\n', 'textDocument': {'uri': 'file:///Users/rkshthrmsh/ws/sandbox/python_study_group/test.py'}}}
2023-02-24 14:28:07,567 IST - DEBUG - pylsp.config.config -   pylsp_document_did_save [hook]
      config: <pylsp.config.config.Config object at 0x104a75a10>
      workspace: <pylsp.workspace.Workspace object at 0x105540f90>
      document: file:///Users/rkshthrmsh/ws/sandbox/python_study_group/test.py

Hmm, there is nothing wrong with the call to ruff, so it has to be some config of ruff on your side that sets line-length to 100. Can you check for local project pyproject.toml files where the ruff line-length was specified? I think there is also a global ruff configuration in ~/.config/ruff/

There are no config files. Currently ruff is using all defaults. As you can see in the log, line length is set to none by the Helix config. I am wondering if the way in which line length diagnostics are handled is different compared to the rest.

Ah, I see the issue: fixing select reduces the errors to check for to only those specified. What you need is extend-select, but this is currently not available as a config option to python-lsp-ruff. I will create a PR for this, in the meantime you can add the needed error letters to the select option (so E, F, ...)

That was it. Thanks!

Reopening to track issue in the PR