Creation of LSPReporter#1314
Conversation
|
I'm creating a draft PR to check if I am on the right path with this. I looked to |
david-yz-liu
left a comment
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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 = {} |
There was a problem hiding this comment.
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.
Pull Request Test Coverage Report for Build 22936925775Details
💛 - Coveralls |
david-yz-liu
left a comment
There was a problem hiding this comment.
@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")
There was a problem hiding this comment.
The reporter should be added here as well
|
|
||
| from .core import NewMessage, PythonTaReporter | ||
|
|
||
| category_to_lsp = { |
There was a problem hiding this comment.
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""" |
|
|
||
|
|
||
| class LSPReporter(PythonTaReporter): | ||
|
|
There was a problem hiding this comment.
Add a docstring for this class
|
|
||
|
|
||
| @pytest.fixture() | ||
| def lsp_output(prevent_webbrowser_and_httpserver): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
|
I have added the syntax fixes, documentation changes and changed the test structure to just be a comparison of output in one test. |
david-yz-liu
left a comment
There was a problem hiding this comment.
Nice work, @PraneethS42!
Proposed Changes
Works on #1307. Adds a new reporter called
LSPReporterthat 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 withinpackages/python-ta/pyproject.toml. Other changes:reporters/__init__.py_get_reporter_class_pathfunction insrc/python_ta/check/helpers.pytest_lsp_reporter.py, passing in input fromlsp_reporter_input.pyScreenshots of your changes (if applicable)
Type of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)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:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)