|
9 | 9 | import threading
|
10 | 10 | from ast import PyCF_ONLY_AST
|
11 | 11 | from inspect import Parameter
|
12 |
| -from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple |
| 12 | +from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union |
13 | 13 |
|
14 | 14 | import docstring_to_markdown
|
15 | 15 | import jedi.api.errors
|
16 | 16 | import jedi.inference.references
|
17 | 17 | import jedi.settings
|
18 | 18 | 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 | +) |
20 | 27 | from lsprotocol.types import (
|
21 | 28 | CompletionItem,
|
22 | 29 | CompletionItemKind,
|
@@ -298,21 +305,19 @@ def lsp_python_diagnostic(uri: str, source: str) -> Optional[Diagnostic]:
|
298 | 305 | compile(source, uri, "exec", PyCF_ONLY_AST)
|
299 | 306 | return None
|
300 | 307 | 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) |
304 | 310 | _until_column = getattr(err, "end_offset", None)
|
305 | 311 | _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 |
309 | 317 | )
|
310 |
| - until_line = _until_line - 1 if _until_line is not None else line |
311 |
| - |
312 | 318 | if (line, column) >= (until_line, until_column):
|
313 | 319 | until_column, until_line = column, line
|
314 | 320 | column = 0
|
315 |
| - |
316 | 321 | return Diagnostic(
|
317 | 322 | range=Range(
|
318 | 323 | start=Position(line=line, character=column),
|
@@ -419,7 +424,7 @@ def clean_completion_name(name: str, char_before_cursor: str) -> str:
|
419 | 424 | _PARAM_NAME_IGNORE = {"/", "*"}
|
420 | 425 |
|
421 | 426 |
|
422 |
| -def get_snippet_signature(signature: Signature) -> str: |
| 427 | +def get_snippet_signature(signature: Union[Signature, BaseSignature]) -> str: |
423 | 428 | """Return the snippet signature."""
|
424 | 429 | params: List[ParamName] = signature.params
|
425 | 430 | if not params:
|
@@ -527,11 +532,6 @@ def _md_bold(value: str, markup_kind: MarkupKind) -> str:
|
527 | 532 | return f"**{value}**" if markup_kind == MarkupKind.Markdown else value
|
528 | 533 |
|
529 | 534 |
|
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 |
| - |
535 | 535 | def _md_text(value: str, markup_kind: MarkupKind) -> str:
|
536 | 536 | """Surround a markdown string with a Python fence."""
|
537 | 537 | return (
|
|
0 commit comments