Skip to content

Commit

Permalink
Merge pull request #276 from dimbleby/fixes-and-updates
Browse files Browse the repository at this point in the history
Fixes and updates
  • Loading branch information
pappasam authored Jul 31, 2023
2 parents 6b064bc + 38aa42e commit a7affc3
Show file tree
Hide file tree
Showing 11 changed files with 745 additions and 630 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
19 changes: 3 additions & 16 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
[MASTER]
# Profiled execution.
profile=no

# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=CVS, .svn, .git, venv
Expand All @@ -18,7 +15,7 @@ extension-pkg-whitelist=pydantic

[MESSAGES CONTROL]
# can opt to enable instead if you want
disable=logging-format-interpolation, bad-continuation
disable=logging-format-interpolation

[REPORTS]

Expand All @@ -27,11 +24,6 @@ disable=logging-format-interpolation, bad-continuation
# mypackage.mymodule.MyReporterClass.
output-format=colorized

# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name "pylint_global.[txt|html]".
files-output=no

# Tells whether to display a full report or only the messages
reports=no

Expand All @@ -42,11 +34,6 @@ reports=no
# (RP0004).
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)

# Add a comment according to your evaluation note. This is used by the global
# evaluation report (RP0004).
comment=no


[MISCELLANEOUS]

# List of note tags to take in consideration, separated by a comma.
Expand Down Expand Up @@ -184,7 +171,7 @@ max-locals=15
max-returns=6

# Maximum number of branch for function / method body
max-branchs=12
max-branches=12

# Maximum number of statements in function / method body
max-statements=50
Expand Down Expand Up @@ -224,4 +211,4 @@ int-import-graph=

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception
overgeneral-exceptions=builtins.Exception
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

[![image-version](https://img.shields.io/pypi/v/jedi-language-server.svg)](https://python.org/pypi/jedi-language-server)
[![image-license](https://img.shields.io/pypi/l/jedi-language-server.svg)](https://python.org/pypi/jedi-language-server)
[![image-python-versions](https://img.shields.io/badge/python->=3.7-blue)](https://python.org/pypi/jedi-language-server)
[![image-python-versions](https://img.shields.io/badge/python->=3.8-blue)](https://python.org/pypi/jedi-language-server)
[![image-pypi-downloads](https://pepy.tech/badge/jedi-language-server)](https://pepy.tech/project/jedi-language-server)
[![github-action-testing](https://github.com/pappasam/jedi-language-server/actions/workflows/testing.yaml/badge.svg)](https://github.com/pappasam/jedi-language-server/actions/workflows/testing.yaml)

A [Language Server](https://microsoft.github.io/language-server-protocol/) for the latest version(s) of [Jedi](https://jedi.readthedocs.io/en/latest/). If using Neovim/Vim, we recommend using with [coc-jedi](https://github.com/pappasam/coc-jedi). Supports Python versions 3.7 and newer.
A [Language Server](https://microsoft.github.io/language-server-protocol/) for the latest version(s) of [Jedi](https://jedi.readthedocs.io/en/latest/). If using Neovim/Vim, we recommend using with [coc-jedi](https://github.com/pappasam/coc-jedi). Supports Python versions 3.8 and newer.

**Note:** this tool is actively used by its primary author. He's happy to review pull requests / respond to issues you may discover.

Expand Down
10 changes: 4 additions & 6 deletions jedi_language_server/initialization_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import List, Optional, Pattern, Set

from lsprotocol.types import MarkupKind
from pydantic import BaseModel, Field
from pydantic import BaseModel, ConfigDict, Field

# pylint: disable=missing-class-docstring
# pylint: disable=too-few-public-methods
Expand All @@ -22,8 +22,7 @@ def snake_to_camel(string: str) -> str:


class Model(BaseModel):
class Config:
alias_generator = snake_to_camel
model_config = ConfigDict(alias_generator=snake_to_camel)


class CodeAction(Model):
Expand All @@ -34,8 +33,7 @@ class CodeAction(Model):
class Completion(Model):
disable_snippets: bool = False
resolve_eagerly: bool = False
# <https://github.com/pydantic/pydantic/issues/2636>
ignore_patterns: List[Pattern] = [] # type: ignore[type-arg]
ignore_patterns: List[Pattern[str]] = []


class Diagnostics(Model):
Expand Down Expand Up @@ -116,5 +114,5 @@ class InitializationOptions(Model):
diagnostics: Diagnostics = Diagnostics()
hover: Hover = Hover()
jedi_settings: JediSettings = JediSettings()
markup_kind_preferred: Optional[MarkupKind]
markup_kind_preferred: Optional[MarkupKind] = None
workspace: Workspace = Workspace()
38 changes: 19 additions & 19 deletions jedi_language_server/jedi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def lsp_python_diagnostic(uri: str, source: str) -> Optional[Diagnostic]:
until_column = (
_until_column - 1 if _until_column is not None else column + 1
)
until_line = _until_line - 1 if _until_line is not None else line + 1
until_line = _until_line - 1 if _until_line is not None else line

if (line, column) >= (until_line, until_column):
until_column, until_line = column, line
Expand All @@ -328,8 +328,8 @@ def lsp_python_diagnostic(uri: str, source: str) -> Optional[Diagnostic]:
def line_column(position: Position) -> Tuple[int, int]:
"""Translate pygls Position to Jedi's line/column.
Returns a dictionary because this return result should be unpacked as a
function argument to Jedi's functions.
Returns a tuple because this return result should be unpacked as a function
argument to Jedi's functions.
Jedi is 1-indexed for lines and 0-indexed for columns. LSP is 0-indexed for
lines and 0-indexed for columns. Therefore, add 1 to LSP's request for the
Expand All @@ -352,19 +352,19 @@ def line_column(position: Position) -> Tuple[int, int]:
def line_column_range(pygls_range: Range) -> Dict[str, int]:
"""Translate pygls range to Jedi's line/column/until_line/until_column.
Returns a dictionary because this return result should be unpacked as a
function argument to Jedi's functions.
Returns a dictionary because this return result should be unpacked
as a function argument to Jedi's functions.
Jedi is 1-indexed for lines and 0-indexed for columns. LSP is 0-indexed for
lines and 0-indexed for columns. Therefore, add 1 to LSP's request for the
line.
Jedi is 1-indexed for lines and 0-indexed for columns. LSP is
0-indexed for lines and 0-indexed for columns. Therefore, add 1 to
LSP's request for the line.
"""
return dict(
line=pygls_range.start.line + 1,
column=pygls_range.start.character,
until_line=pygls_range.end.line + 1,
until_column=pygls_range.end.character,
)
return {
"line": pygls_range.start.line + 1,
"column": pygls_range.start.character,
"until_line": pygls_range.end.line + 1,
"until_column": pygls_range.end.character,
}


def compare_names(name1: Name, name2: Name) -> bool:
Expand All @@ -381,12 +381,12 @@ def compare_names(name1: Name, name2: Name) -> bool:
def complete_sort_name(name: Completion, append_text: str) -> str:
"""Return sort name for a jedi completion.
Should be passed to the sortText field in CompletionItem. Strings sort a-z,
a comes first and z comes last.
Should be passed to the sortText field in CompletionItem. Strings
sort a-z, a comes first and z comes last.
Additionally, we'd like to keep the sort order to what Jedi has provided.
For this reason, we make sure the sort-text is just a letter and not the
name itself.
Additionally, we'd like to keep the sort order to what Jedi has
provided. For this reason, we make sure the sort-text is just a
letter and not the name itself.
"""
name_str = name.name
if name_str is None:
Expand Down
9 changes: 1 addition & 8 deletions jedi_language_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,21 +371,14 @@ def hover(
jedi_script = jedi_utils.script(server.project, document)
jedi_lines = jedi_utils.line_column(params.position)
markup_kind = _choose_markup(server)
# jedi's help function is buggy when the column is 0. For this reason, as a
# rote fix, we simply set the column to 1 if params.position returns column
# 0.
hover_text = jedi_utils.hover_text(
jedi_script.help(
line=jedi_lines[0],
column=1 if jedi_lines[1] == 0 else jedi_lines[1],
),
jedi_script.help(*jedi_lines),
markup_kind,
server.initialization_options,
)
if not hover_text:
return None
contents = MarkupContent(kind=markup_kind, value=hover_text)
document = server.workspace.get_document(params.text_document.uri)
_range = pygls_utils.current_word_range(document, params.position)
return Hover(contents=contents, range=_range)

Expand Down
3 changes: 2 additions & 1 deletion jedi_language_server/text_edit_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def lsp_text_edits(
Handles inserts, replaces, and deletions within a text file.
Additionally, makes sure returned code is syntactically valid Python.
Additionally, makes sure returned code is syntactically valid
Python.
"""
new_code = changed_file.get_new_code()
if not is_valid_python(new_code):
Expand Down
Loading

0 comments on commit a7affc3

Please sign in to comment.