Skip to content
This repository was archived by the owner on Sep 21, 2019. It is now read-only.
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
10 changes: 6 additions & 4 deletions ensime_shared/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ def lazy_initialize_ensime():
self.log.debug(str(inspect.stack()))
self.log.debug('setup(quiet=%s, bootstrap_server=%s) called by %s()',
quiet, bootstrap_server, called_by)
no_classpath = not os.path.exists(self.launcher.classpath_file)
if not bootstrap_server and no_classpath:

installed = self.launcher.strategy.isinstalled()
if not installed and not bootstrap_server:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This little strategy.isinstalled() Law of Demeter violation felt dirty for a moment, but I feel the right solution is probably not a delegating method on the launcher itself, but getting this logic entirely out of EnsimeClient as per #325. And likely extending to some of the work toward server lifecycle management.

if not quiet:
scala = self.launcher.config.get('scala-version')
msg = feedback["prompt_server_install"].format(scala_version=scala)
Expand Down Expand Up @@ -261,6 +262,7 @@ def reconnect(e):
def connect_ensime_server(self):
"""Start initial connection with the server."""
self.log.debug('connect_ensime_server: in')
server_v2 = isinstance(self, EnsimeClientV2)

def disable_completely(e):
if e:
Expand All @@ -272,12 +274,12 @@ def disable_completely(e):
self.number_try_connection -= 1
if not self.ensime_server:
port = self.ensime.http_port()
uri = "websocket" if self.launcher.server_v2 else "jerky"
uri = "websocket" if server_v2 else "jerky"
self.ensime_server = gconfig["ensime_server"].format(port, uri)
with catch(Exception, disable_completely):
from websocket import create_connection
# Use the default timeout (no timeout).
options = {"subprotocols": ["jerky"]} if self.launcher.server_v2 else {}
options = {"subprotocols": ["jerky"]} if server_v2 else {}
self.log.debug("About to connect to %s with options %s",
self.ensime_server, options)
self.ws = create_connection(self.ensime_server, **options)
Expand Down
2 changes: 1 addition & 1 deletion ensime_shared/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ensime_shared.util import Util

BOOTSTRAPS_ROOT = os.path.join(os.environ['HOME'], '.config/ensime-vim/')
BOOTSTRAPS_ROOT = os.path.join(os.environ['HOME'], '.config', 'ensime-vim')
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated, but the config folder location could be improved by using XDG for Linux and AppData for Windows.

"""Default directory where ENSIME server bootstrap projects will be created."""

LOG_FORMAT = '%(levelname)-8s <%(asctime)s> (%(filename)s:%(lineno)d) - %(message)s'
Expand Down
10 changes: 6 additions & 4 deletions ensime_shared/ensime.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ def __init__(self, vim):
self._vim = vim
self.clients = {}

@property
def using_server_v2(self):
"""Whether user has configured the plugin to use ENSIME v2 protocol."""
"""bool: Whether user has configured the plugin to use ENSIME v2 protocol."""
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused, keeping this setting just to choose the client version can't lead to a client and server version mismatch?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nvm, it's an undocumented setting so only people knowing what they do should be using it.

Copy link
Contributor

@ktonga ktonga Dec 9, 2016

Choose a reason for hiding this comment

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

Sorry about the noise, I think we should get rid of this setting and ask the launcher which version we should use for the client.

return bool(self.get_setting('server_v2', 0))

def get_setting(self, key, default):
Expand Down Expand Up @@ -109,10 +110,11 @@ def create_client(self, config_path):

This will launch the ENSIME server for the project as a side effect.
"""
server_v2 = self.using_server_v2()
config = ProjectConfig(config_path)
editor = Editor(self._vim)
launcher = EnsimeLauncher(self._vim, config_path, server_v2)
if server_v2:
launcher = EnsimeLauncher(self._vim, config)

if self.using_server_v2:
return EnsimeClientV2(editor, self._vim, launcher)
else:
return EnsimeClientV1(editor, self._vim, launcher)
Expand Down
4 changes: 4 additions & 0 deletions ensime_shared/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def __init__(self, errno, msg, filename, *args):
super(InvalidJavaPathError, self).__init__(errno, msg, filename, *args)


class LaunchError(RuntimeError):
"""Raised when ensime-vim cannot launch the ENSIME server."""


class Error(object):
"""Represents an error in source code reported by ENSIME."""

Expand Down
Loading