Skip to content

Commit 8f6e176

Browse files
committed
Ensure that diagnostic position cannot be less than 0
Resolves pappasam#272
1 parent 2ca1f8b commit 8f6e176

File tree

4 files changed

+101
-154
lines changed

4 files changed

+101
-154
lines changed

jedi_language_server/initialization_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def structure(cls: type) -> Any:
141141
return make_dict_structure_fn(
142142
cls,
143143
initialization_options_converter,
144-
**{
144+
**{ # type: ignore[arg-type]
145145
a.name: override(rename=convert_class_keys(a.name))
146146
for a in fields(cls)
147147
},

jedi_language_server/jedi_utils.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@
1616
import jedi.inference.references
1717
import jedi.settings
1818
from jedi import Project, Script
19-
from jedi.api.classes import BaseName, Completion, Name, ParamName, Signature
19+
from jedi.api.classes import (
20+
BaseName,
21+
BaseSignature,
22+
Completion,
23+
Name,
24+
ParamName,
25+
Signature,
26+
)
2027
from lsprotocol.types import (
2128
CompletionItem,
2229
CompletionItemKind,
@@ -298,21 +305,19 @@ def lsp_python_diagnostic(uri: str, source: str) -> Optional[Diagnostic]:
298305
compile(source, uri, "exec", PyCF_ONLY_AST)
299306
return None
300307
except SyntaxError as err:
301-
column = err.offset - 1 if err.offset is not None else 0
302-
line = err.lineno - 1 if err.lineno is not None else 0
303-
308+
column = max(0, err.offset - 1 if err.offset is not None else 0)
309+
line = max(0, err.lineno - 1 if err.lineno is not None else 0)
304310
_until_column = getattr(err, "end_offset", None)
305311
_until_line = getattr(err, "end_lineno", None)
306-
307-
until_column = (
308-
_until_column - 1 if _until_column is not None else column + 1
312+
until_column = max(
313+
0, _until_column - 1 if _until_column is not None else column + 1
314+
)
315+
until_line = max(
316+
0, _until_line - 1 if _until_line is not None else line
309317
)
310-
until_line = _until_line - 1 if _until_line is not None else line
311-
312318
if (line, column) >= (until_line, until_column):
313319
until_column, until_line = column, line
314320
column = 0
315-
316321
return Diagnostic(
317322
range=Range(
318323
start=Position(line=line, character=column),
@@ -419,7 +424,7 @@ def clean_completion_name(name: str, char_before_cursor: str) -> str:
419424
_PARAM_NAME_IGNORE = {"/", "*"}
420425

421426

422-
def get_snippet_signature(signature: Signature) -> str:
427+
def get_snippet_signature(signature: Signature | BaseSignature) -> str:
423428
"""Return the snippet signature."""
424429
params: List[ParamName] = signature.params
425430
if not params:
@@ -527,11 +532,6 @@ def _md_bold(value: str, markup_kind: MarkupKind) -> str:
527532
return f"**{value}**" if markup_kind == MarkupKind.Markdown else value
528533

529534

530-
def _md_italic(value: str, markup_kind: MarkupKind) -> str:
531-
"""Add italic surrounding when markup_kind is markdown."""
532-
return f"*{value}*" if markup_kind == MarkupKind.Markdown else value
533-
534-
535535
def _md_text(value: str, markup_kind: MarkupKind) -> str:
536536
"""Surround a markdown string with a Python fence."""
537537
return (

0 commit comments

Comments
 (0)