1212import sys
1313from subprocess import PIPE , Popen
1414
15- from pylsp import hookimpl , lsp
15+ from lsprotocol .types import DiagnosticSeverity , DiagnosticTag
16+
17+ from pylsp import hookimpl
1618
1719try :
1820 import ujson as json
@@ -74,7 +76,7 @@ def lint(cls, document, is_saved, flags=""):
7476 },
7577 }
7678 'message': msg,
77- 'severity': lsp. DiagnosticSeverity.*,
79+ 'severity': DiagnosticSeverity.*,
7880 }
7981 """
8082 if not is_saved :
@@ -160,17 +162,20 @@ def lint(cls, document, is_saved, flags=""):
160162 }
161163
162164 if diag ["type" ] == "convention" :
163- severity = lsp . DiagnosticSeverity .Information
165+ severity = DiagnosticSeverity .Information
164166 elif diag ["type" ] == "information" :
165- severity = lsp . DiagnosticSeverity .Information
167+ severity = DiagnosticSeverity .Information
166168 elif diag ["type" ] == "error" :
167- severity = lsp . DiagnosticSeverity .Error
169+ severity = DiagnosticSeverity .Error
168170 elif diag ["type" ] == "fatal" :
169- severity = lsp . DiagnosticSeverity .Error
171+ severity = DiagnosticSeverity .Error
170172 elif diag ["type" ] == "refactor" :
171- severity = lsp . DiagnosticSeverity .Hint
173+ severity = DiagnosticSeverity .Hint
172174 elif diag ["type" ] == "warning" :
173- severity = lsp .DiagnosticSeverity .Warning
175+ severity = DiagnosticSeverity .Warning
176+ else :
177+ log .warning ("Unknown pylint diagnostic type '%s'" , diag ["type" ])
178+ severity = DiagnosticSeverity .Error
174179
175180 code = diag ["message-id" ]
176181
@@ -183,9 +188,9 @@ def lint(cls, document, is_saved, flags=""):
183188 }
184189
185190 if code in UNNECESSITY_CODES :
186- diagnostic ["tags" ] = [lsp . DiagnosticTag .Unnecessary ]
191+ diagnostic ["tags" ] = [DiagnosticTag .Unnecessary ]
187192 if code in DEPRECATION_CODES :
188- diagnostic ["tags" ] = [lsp . DiagnosticTag .Deprecated ]
193+ diagnostic ["tags" ] = [DiagnosticTag .Deprecated ]
189194
190195 diagnostics .append (diagnostic )
191196 cls .last_diags [document .path ] = diagnostics
@@ -327,12 +332,12 @@ def _parse_pylint_stdio_result(document, stdout):
327332 line = int (line ) - 1
328333 character = int (character )
329334 severity_map = {
330- "C" : lsp . DiagnosticSeverity .Information ,
331- "E" : lsp . DiagnosticSeverity .Error ,
332- "F" : lsp . DiagnosticSeverity .Error ,
333- "I" : lsp . DiagnosticSeverity .Information ,
334- "R" : lsp . DiagnosticSeverity .Hint ,
335- "W" : lsp . DiagnosticSeverity .Warning ,
335+ "C" : DiagnosticSeverity .Information ,
336+ "E" : DiagnosticSeverity .Error ,
337+ "F" : DiagnosticSeverity .Error ,
338+ "I" : DiagnosticSeverity .Information ,
339+ "R" : DiagnosticSeverity .Hint ,
340+ "W" : DiagnosticSeverity .Warning ,
336341 }
337342 severity = severity_map [code [0 ]]
338343 diagnostic = {
@@ -351,9 +356,9 @@ def _parse_pylint_stdio_result(document, stdout):
351356 "severity" : severity ,
352357 }
353358 if code in UNNECESSITY_CODES :
354- diagnostic ["tags" ] = [lsp . DiagnosticTag .Unnecessary ]
359+ diagnostic ["tags" ] = [DiagnosticTag .Unnecessary ]
355360 if code in DEPRECATION_CODES :
356- diagnostic ["tags" ] = [lsp . DiagnosticTag .Deprecated ]
361+ diagnostic ["tags" ] = [DiagnosticTag .Deprecated ]
357362 diagnostics .append (diagnostic )
358363
359364 return diagnostics
0 commit comments