-
Notifications
You must be signed in to change notification settings - Fork 256
Single NeoTree command to interface with different sources #61
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
Conversation
Thanks @levouh , I'll take a look. As for the question about having multiple window open, I do see a use case for that. Some people, even myself, may want to have trees open on both the left and the right. Say, a file tree on the left and a symbol tree on the right. The more sources we have the more likely this feature will be used. Also, we definitely do need some kind of interface, base class, or similar concept for sources. I'm new to lua and don't quite grok the class system yet. I'll take a look at nvim-cmp top see what they have done. |
I have a couple of top level comments:
There have been a lot of changes merged since this branch. At least one of them was a fix for toggle commands. I also added a log module copied from plenary and modified slightly. Along with that log, I added two new (undocumented) commands:
These were really added for myself to use. Log levels below info only go to the file, which you have to enable in your config: require("neo-tree").setup({
log_level = "debug",
log_to_file = true,
}) |
@levouh I don't know if you've made any attempt to create a base class for sources, but I just put a little time into it. If you were going down that path too I think we should sync up. It's a fair amount of work and I'm not sure if I am going to continue it as part of the feature I am working on now. Something definitely needs to happen because the common functionality between the sources is really growing. Now that I am adding events and file watchers I need to add a dispose method to clean this stuff up and that's the last straw. Here is what I have done so far on that: 8aa4526 It doesn't actually work yet. |
Awesome! I have not done any work in that regard yet (wanted to get your general feedback on this PR first), but I'm honestly glad that you took a stab first as I am much less familiar with the code base and what it might need to look like. Happy to provide feedback as well if you'd like.
Either way I think this would be a good idea, however I imagine most of the classes will manifest themselves into a common set of actions rather naturally. As long as that is mostly the case (some common-ish contract that classes must follow), then the commands are super easy. Pending how aggressive you want to be on your side, it will likely be a good idea to wait to do this PR on top of your work. |
Agreed that the commands should come after the common contract. I am starting to lean toward just using the "base source" as a module that the other sources deep copy and merge themselves onto as the means of inheritance rather than go all the way to classes. This is what i have done with components. The reason for this is that I don't actually want to encapsulate state, I just want to reuse and selectively override static methods. One advantage here is that it would not require any changes in the exported interface of sources. If you have any thoughts on this I would love to hear them. |
@levouh Can you let me know if you plan on continuing this work or not? Whether you'be just been busy or have lost interest, it's OK either way. I just want to know if I should continue it on my own. Thanks! |
I completely forgot this was in my court. Feel free to work on/finish it if you'd like, otherwise I can get back to it next week-ish @cseickel. |
I'm very happy to leave it with you if you are still interested @levouh, I'm sure you will do a good job with it! let me know if anything changes. When you do get back to it, I had a thought about the command syntax. All of the arguments have unique values that don't conflict, so we can probably support space separated options in any order without issue, but leave the
|
I'm going to close this PR because it seems dead. I've started a new branch for this and I will implement this feature. Thanks so much for the discussion and the portion you did complete @levouh! Even though I started fresh, I keep referring to the work here as a guide and it's been very helpful. The new branch is at https://github.com/nvim-neo-tree/neo-tree.nvim/tree/feat/single-command-wth-args |
No worries, absolutely understandable @cseickel ❤️ |
Still super work-in-progress, but I wanted to get feedback early before spending a bunch of time doing something that ultimately needs to be changed. The current status:
NeoTree
command works for all previous commands (I think, I have not used most of them much nor do they have tests so it was all done manually)make test
can be used to run tests usingplenary
sbusted
module.md
files for now, will need to be converted into the.txt
docs for Vim:h
support, or we can look at using md2vim so you only have to maintain a single one).A brief description of the changes here:
utils/command
module that handles all interfacing with the commands, including parsing, validating, and running the appropriately associated methodCommandParser
object, which I do not think is super necessary as we are able tounpack({<f-args>})
in the command. This function basically just ends up callingvim.split
on each of the value in the table, so it comes across as quite overkill, however it does make testing the parsing of commands easier to have it separated this way.Action
object, which mostly handles taking the parsed arguments for the command and determining what action needs to be called, and with what arguments. The abstraction layer here isn't really necessary pending some of the middle layers that exist (discussed below). Being able to keep a (again abstracted/separate for easier testing) mapping here for a function and extra arguments that need to be passed to it makes it easier to use the same underlying functions inneo-tree.lua
but pass them different arguments. Separate functions in that same module (neo-tree.lua
) with some hard-coded arguments to call other functions, so like:does the same thing and might end up being a bit easier. Either way, having some "layer" like this seems necessary for all of the variations of the commands.
Again, I am posting this now for some early feedback and it is not complete yet, however I think it is still a bit jank the way that the command interfaces with the different methods in the main
neo-tree.lua
file. In a perfect world we might be able to pull sources into their own objects that all obey a contract, then this way the functions being called on them are "guaranteed" to work.I'd like to mess with it a bit more (as well as talk here) to see what that layer might look like, both in the short term (say with no refactoring) and in the longer term (perhaps some refactoring). A good example for "user-implemented sources" would be how
nvim-cmp
does it in my opinion.Some questions too:
all
might also be useful, but I'm not sure what the use case for having multiple trees open is. Thoughts?