Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer end position for Pylint diagnostics #547

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

Wuestengecko
Copy link
Contributor

@Wuestengecko Wuestengecko commented Apr 5, 2024

Pylint only supplies the start position of markers, but not the end. Always extending the marker until the end of the line leads to undesirable highlighting in editors, for example:

def my_func(unused_arg, used_arg):
    print(used_arg)

Starting an "unused argument" diagnostic at unused_arg and extending It until EOL would also highlight used_arg, even though the diagnostic doesn't apply there.

With this commit, the end position sent to the editor is automatically determined by looking for an identifier at the indicated start position. If there is no valid identifier at that position, the entire line is highlighted as before.


Note that in some cases, Pylint doesn't supply the start position of the token of interest, but instead marks the first non-whitespace character. I noticed this on import statements and except clauses, where the import (or from) and the except keywords then are what gets highlighted, instead of the module or variable in question. However, I think these are only minor issues in comparison to the original issue with the example above.

Pylint only supplies the start position of markers, but not the end.
Always extending the marker until the end of the line leads to
undesirable highlighting in editors, for example:

```python
def my_func(unused_arg, used_arg):
    print(used_arg)
```

Starting an "unused argument" diagnostic at `unused_arg` and extending
It until EOL would also highlight `used_arg`, even though the diagnostic
doesn't apply there.

With this commit, the end position sent to the editor is automatically
determined by looking for an identifier at the indicated start position.
If there is no valid identifier at that position, the entire line is
highlighted as before.
@ccordoba12 ccordoba12 added this to the v1.12.0 milestone Jul 29, 2024
@ccordoba12 ccordoba12 added the enhancement New feature or request label Jul 29, 2024
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks @Wuestengecko!

@ccordoba12 ccordoba12 merged commit 4714d38 into python-lsp:develop Aug 22, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants