Skip to content

Creation of LSPReporter#1314

Merged
david-yz-liu merged 7 commits intopyta-uoft:masterfrom
PraneethS42:lspreporter
Mar 11, 2026
Merged

Creation of LSPReporter#1314
david-yz-liu merged 7 commits intopyta-uoft:masterfrom
PraneethS42:lspreporter

Conversation

@PraneethS42
Copy link
Copy Markdown
Contributor

@PraneethS42 PraneethS42 commented Mar 4, 2026

Proposed Changes

Works on #1307. Adds a new reporter called LSPReporter that outputs JSON in the format of the LSP 3.17 specification. Uses the lsprotocol types of Diagnostic, Range and Position to structure output. Also added lsprotocol to dependencies within packages/python-ta/pyproject.toml. Other changes:

  • Added reporter to list in reporters/__init__.py
  • Added the new path to the _get_reporter_class_path function in src/python_ta/check/helpers.py
  • Created tests in test_lsp_reporter.py, passing in input from lsp_reporter_input.py
Screenshots of your changes (if applicable)

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality) x
🐛 Bug fix (non-breaking change that fixes an issue)
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📚 Documentation update (change that only updates documentation)
📦 Dependency update (change that updates a dependency) x
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • I have updated the project Changelog (this is required for all changes).
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have verified that the pre-commit.ci checks have passed.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

(Include any questions or comments you have regarding your changes.)

@PraneethS42
Copy link
Copy Markdown
Contributor Author

I'm creating a draft PR to check if I am on the right path with this. I looked to json_reporter.py for inspiration and used the LSP documentation, but I'm not sure if I have the right logic/format. I will add Changelog and documentation updates once I convert this to a proper PR.

@PraneethS42 PraneethS42 requested a review from david-yz-liu March 4, 2026 04:33
@PraneethS42 PraneethS42 changed the title Lspreporter Creation of LSPReporter Mar 4, 2026
Copy link
Copy Markdown
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

Hi @PraneethS42, I definitely think you are on the right track. 👍

I left a few high-level comments about the direction you're taking.

@@ -0,0 +1,60 @@
import json

import attrs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't currently require this module in our dependency list and I don't think it's necessary to achieve the functionality here. Try using just lsprotocol's type converters, e.g. here.

messages: dict[str, list[NewMessage]]

def display_messages(self, layout: BaseLayout) -> None:
json_output = {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So overall this is good but I think we can go even further with the types to match the LSP. I think the main class we want to target is PublishDiagnosticsParams, which sits one level about the individual Diagnostics`.

For this class you can use a URI that's just based on the file path (i.e., file://...).

Because the reporter needs to handle multiple files, for now you can output JSON which is a list of PublishDiagnosticsParams objects.

@PraneethS42 PraneethS42 marked this pull request as ready for review March 7, 2026 19:45
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Mar 7, 2026

Pull Request Test Coverage Report for Build 22936925775

Details

  • 31 of 33 (93.94%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 89.987%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/python-ta/src/python_ta/reporters/lsp_reporter.py 29 31 93.55%
Totals Coverage Status
Change from base Build 22746237351: 0.03%
Covered Lines: 3478
Relevant Lines: 3865

💛 - Coveralls

@PraneethS42 PraneethS42 requested a review from david-yz-liu March 8, 2026 17:47
Copy link
Copy Markdown
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

@PraneethS42 nice work, in addition to the comments I left, please also add mention of the new reporter in the output-format config option docs in the default .pylintrc file, and in the documentation (under "configuration")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The reporter should be added here as well


from .core import NewMessage, PythonTaReporter

category_to_lsp = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

name this constant with ALL_CAPS style



def _lsp_severity(category: str) -> types.DiagnosticSeverity:
"""Convert the PyLint category to DiagnosticSeverity type, return default of warning"""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"PyLint" -> "Pylint"



class LSPReporter(PythonTaReporter):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a docstring for this class



@pytest.fixture()
def lsp_output(prevent_webbrowser_and_httpserver):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the prevent_webbrowser_and_httpserver isn't necessary here, as the HTMLReporter isn't being used

return json.loads(buf.read())


def test_output_is_list(lsp_output):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall these tests aren't very precise. I would generate an explicit expected object and compare (using ==) the actual JSON that's output by the reporter.

@PraneethS42
Copy link
Copy Markdown
Contributor Author

I have added the syntax fixes, documentation changes and changed the test structure to just be a comparison of output in one test.

Copy link
Copy Markdown
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

Nice work, @PraneethS42!

@david-yz-liu david-yz-liu merged commit 2174e6a into pyta-uoft:master Mar 11, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants