Skip to content

Commit

Permalink
Merge pull request #97 from pappasam/resolve-initialize-regression
Browse files Browse the repository at this point in the history
Handle null rootUri
  • Loading branch information
pappasam authored Mar 19, 2021
2 parents 373d115 + 4c5b1ff commit 6a743cd
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 59 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.28.4

### Fixed

- Handle null rootUri's by not creating a Jedi project, fixes <https://github.com/pappasam/jedi-language-server/issues/95>
- Tolerate invalid InitializationOptions by using default values on error

## 0.28.3

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions jedi_language_server/jedi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import random
import string # pylint: disable=deprecated-module
from inspect import Parameter
from typing import Dict, List
from typing import Dict, List, Optional

import docstring_to_markdown
import jedi.api.errors
Expand Down Expand Up @@ -51,7 +51,7 @@ def set_jedi_settings( # pylint: disable=invalid-name
)


def script(project: Project, document: Document) -> Script:
def script(project: Optional[Project], document: Document) -> Script:
"""Simplifies getting jedi Script."""
return Script(code=document.source, path=document.path, project=project)

Expand Down
26 changes: 18 additions & 8 deletions jedi_language_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
Location,
MarkupContent,
MarkupKind,
MessageType,
ParameterInformation,
RenameParams,
SignatureHelp,
Expand Down Expand Up @@ -82,8 +83,11 @@ def bf_initialize(self, params: InitializeParams) -> InitializeResult:
server.initialization_options = InitializationOptions.parse_obj(
params.initialization_options
)
except ValidationError:
pass
except ValidationError as error:
msg = f"Invalid InitializationOptions, using defaults: {error}"
server.show_message(msg, msg_type=MessageType.Error)
server.show_message_log(msg, msg_type=MessageType.Error)
server.initialization_options = InitializationOptions()

initialization_options = server.initialization_options
jedi_utils.set_jedi_settings(initialization_options)
Expand All @@ -110,11 +114,15 @@ def bf_initialize(self, params: InitializeParams) -> InitializeResult:
server.feature(TEXT_DOCUMENT_DID_CHANGE)(did_change)
server.feature(TEXT_DOCUMENT_DID_SAVE)(did_save)
initialize_result: InitializeResult = super().bf_initialize(params)
server.project = Project(
path=server.workspace.root_path,
added_sys_path=initialization_options.workspace.extra_paths,
smart_sys_path=True,
load_unsafe_extensions=False,
server.project = (
Project(
path=server.workspace.root_path,
added_sys_path=initialization_options.workspace.extra_paths,
smart_sys_path=True,
load_unsafe_extensions=False,
)
if server.workspace.root_path
else None
)
return initialize_result

Expand All @@ -128,7 +136,7 @@ class JediLanguageServer(LanguageServer):
`JediLanguageServerProtocol.bf_initialize`.
"""

project: Project
project: Optional[Project]

def __init__(self, *args: Any, **kwargs: Any) -> None:
self.initialization_options = InitializationOptions()
Expand Down Expand Up @@ -388,6 +396,8 @@ def workspace_symbol(
2. Those that are not rooted in the current workspace.
3. Those whose folders contain a directory that is ignored (.venv, etc)
"""
if not server.project:
return None
names = server.project.complete_search(params.query)
workspace_root = server.workspace.root_path
ignore_folders = (
Expand Down
96 changes: 48 additions & 48 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ line_length = 79

[tool.poetry]
name = "jedi-language-server"
version = "0.28.3"
version = "0.28.4"
description = "A language server for Jedi!"
authors = ["Sam Roeca <samuel.roeca@gmail.com>"]
readme = "README.md"
Expand Down

0 comments on commit 6a743cd

Please sign in to comment.