Skip to content
This repository was archived by the owner on Sep 21, 2019. It is now read-only.

Conversation

@ches
Copy link
Contributor

@ches ches commented Jul 31, 2016

This branch is based on my logger and unit testing branches, #323 and #327. It will be a lot easier to review if those get merged. In the meantime here is the diff as if they were already merged:

ches/ensime-vim@integration...ches:editor-object

This is a first pass at factoring all editor functionality out of the EnsimeClient class and into a separate one, as described in #321. I would still like to make further improvements to the API of the Editor object, but since this is already a lot of changes, I've tried to mostly make this phase a "direct port" of existing functions for the benefit of easier review. The follow-up changes might evoke more design discussion, hopefully this two-phase approach helps to defer most of that to when it easier to focus on.

The config.commands dictionary is completely eliminated 🎉

The vim object is eliminated from EnsimeClient with a couple of exceptions that I'll note inline.

New API on the Editor object is covered by unit tests mocking the vim object. I haven't written tests for the old API yet because I want to change a lot of it in the next stage. By the way, make coverage is a thing now.

I would appreciate it if brave souls can try running this branch for their work for a few days (cc @ChrisCoffey @ktonga). This is a lot of changes on top of two already significant branches, so I would really like to start landing some of it—I think altogether they are big steps in making ensime-vim easier for contributors to dive into.

self.ensime_cache = osp.join(config_dirname, ".ensime_cache")
self.log_dir = self.ensime_cache
if not osp.isdir(self.ensime_cache):
def __init__(self, editor, vim, launcher): # noqa: C901
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't quite jettison the vim attribute yet, the remaining usage is for disable_plugin which is too complicated to deal with in the course of these changes, I've dived into it a bit for #294 and will continue later.

# Use current_file command because we cannot access self.vim
current_file_cmd = commands["current_file"]
current_file = self.vim.eval(current_file_cmd)
current_file = self.vim.current.buffer.name
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't understand the comment here because it still uses self.vim anyway 😩 This change seems to work fine, but let me know if anyone sees an issue.

The cases I believe we know of where using the vim object can be problematic:

  • Off of the main thread. The Python Vim API isn't threadsafe so that's why the only code that tries to invoke it from the polling worker thread, which is disable_plugin, jumps through the threadsafe_vim hoop (which is just YOLO for standard Vim…).
  • In Ensime.__init__. We observed that using self.vim there didn't work and my hunch was that's because the class is first being defined when an autocommand like VimEnter fires triggering it to be loaded, and we're also defining the code that Vim is trying to invoke for our autocommand handler within the Ensime class, so there's a reentrancy thing going on there.

Neither of these apply here. It may have been that at one time, further back than I have spelunked in git blame, that current_client was being called from __init__?

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be delegated on a method in editor considering we ain't gonna reference vim directly from the client anymore.

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 is a method of the Ensime class, not EnsimeClient—we can discuss this more in the context of design discussion in the second part of these changes, but my reasoning so far is that using vim here is reasonable because the Ensime class basically represents the Vim plugin itself on the Python side, i.e. it's the base class for NeovimEnsime for instance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, my bad for looking at the decontextualized diff. I agree with you on the scope of the vim object.

@ktonga
Copy link
Contributor

ktonga commented Aug 3, 2016

Hey @ches :EnSuggestImport isn't working. Didn't do any further research tho. Sorry.
From the logs I can tell you that the request reaches the server but nothing happens afterwards. No errors are shown in the logs.

@ches
Copy link
Contributor Author

ches commented Aug 3, 2016

Hmm that's weird, it works for me. Let me know if you have a chance to figure out more specific reproduction conditions.

@ktonga
Copy link
Contributor

ktonga commented Aug 3, 2016

Never mind, it seemed to be an unrelated problem which I solved just restarting the server. After commenting here I started noticing problems with other commands, such as :EnType, so I decided to restart and that fixed all the problems. Maybe it's related somehow but I would not be able to reproduce it easily. I will let you know if it happens again. Sorry for the noise.

def set_filetype(self, filetype):
"""Set filetype for the current buffer.

Unfortunately setting the filetype with ``set_buffer_options`` (or
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an implementation detail, no need to be leaked in the editor API. Maybe it could be specially handled in set_buffer_options instead of being a separate method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's probably true, I guess I thought this might be independently useful, but it could also be automatically handled as a special case in set_buffer_options. There's no other singular form of that anywhere just because it wasn't needed yet.

@ktonga
Copy link
Contributor

ktonga commented Aug 5, 2016

This change is looking so sexy. I've been using it for a week or so and seems to be working well.

LGTM

You should rebase on master to integrate the new debug commands and you can just merge it.
Excellent work!

@ches
Copy link
Contributor Author

ches commented Aug 5, 2016

Thanks for the review and trying it out!

I'll incorporate a change of the set_filetype consolidation thing, and I'd also maybe like to make an interim improvement on #330 before rebasing this. Maybe not the bigger changes discussed there, but at least breaking the source formatting part into a sensible separate function should be easy and now I understand what it's doing in order to get rid of that last self.vim usage. Been preoccupied with other stuff for the last few days so haven't gotten around to that yet, should be able to in the next day or two.

@ktonga
Copy link
Contributor

ktonga commented Aug 5, 2016

Ok. Sounds great. I'll keep using it for a few more days so, just to be sure. But be aware that I only use a small subset of the plugin functionality.

ches added 5 commits August 16, 2016 21:51
Syntastic automatically scans the runtimepath for syntax_checkers
directories to accommodate plugins:

https://github.com/scrooloose/syntastic/wiki/Syntax-Checker-Guide#external

The non-standard location was specifically requested in #184, but I
don’t agree with the reasoning or the extra code that is required to
work around it. I’m not sure Jorge understood that Syntastic has a
supported convention.

This reverts this commit, but it was squashed away before merge so the
object isn’t actually reachable from most clones:

ensime/ensime-vim@ed0e941
Get rid of the `commands` dictionary of Vim commands/expressions, giving
them a real function API instead of a stringly-typed one.

This is also a push toward unit-testability, reducing complex
dependencies of objects so they can feasibly be injected with mocks.

This is a first pass only, the Editor object API can definitely be
improved but most functions are ported intact at this time to make
review easier and defer design discussions. Also, a few uses of the
`vim` object remain on EnsimeClient -- these are limited to the
disable_plugin functionality and will be addressed in #294, it is too
complicated to include in the scope of this change.

Closes #321.
The original format is supported by lgtm, I like real names personally:

https://lgtm.co/docs/maintainers/

This reverts commit d456a13.
@ches
Copy link
Contributor Author

ches commented Aug 16, 2016

Okay, I've rebased this and incorporated changes we've discussed.

@ches ches merged commit 07822b2 into ensime:master Aug 16, 2016
@ches ches removed the In progress label Aug 16, 2016
@ches ches deleted the editor-object branch August 16, 2016 19:07
ches referenced this pull request in ches/ensime-vim Aug 26, 2016
We’ve had some recent discussion about what the responsibily of this
class should be, and based on that it has some methods that don’t fit
or at least should not be public. This is a first pass at cleaning up.

Some consideration of the class’s role was hashed out on #328. These
changes have eventual relevance to #243, #294, #325.
ches referenced this pull request in ches/ensime-vim Aug 26, 2016
We’ve had some recent discussion about what the responsibily of this
class should be, and based on that it has some methods that don’t fit
or at least should not be public. This is a first pass at cleaning up.

Some consideration of the class’s role was hashed out on #328. These
changes have eventual relevance to #243, #294, #325.
ches referenced this pull request in ches/ensime-vim Sep 26, 2016
Regression from #328 where Vim's string result to the Syntastic feature
detection wasn't properly cast to Boolean, and escaping was doubled
after changing match pattern to a Python raw string.

Closes #339.
ktonga pushed a commit that referenced this pull request Sep 27, 2016
Regression from #328 where Vim's string result to the Syntastic feature
detection wasn't properly cast to Boolean, and escaping was doubled
after changing match pattern to a Python raw string.

Closes #339.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants