Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle null rootUri #97

Merged
merged 4 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my intention had been that this was handled by creating default options at

self.initialization_options = InitializationOptions()
, not sure if this was broken?

logging the error is clearly a good idea!

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, this is redundant, I'll fix now


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