chipsenkbeil / org-roam.nvim

Port of org-roam to neovim using orgmode
MIT License
107 stars 9 forks source link

Support indexing of existing org files outside the org-roam directory #42

Closed seflue closed 3 months ago

seflue commented 4 months ago

Hi. First of all, many thanks to you, @chipsenkbeil, for this great plugin!

I wanted to ask, if it is possible to add another config option, where the user can declare file locations to get indexed, but which are explicitly not the directory where new files are created.

My usecase is, that I already have a large amount of org-files, which are organized in a hierarchical tree. But because I don't really think in hierarchies, org-roam's workflow is much more feasible for me. But I want to integrate my old files into the knowledge graph of org-roam without moving them, because they already have interconnecting links.

I don't know, if the architecture of org-roam allows that. If so, another command to easily create a knew ID at the top would also be nice. But that's not so urgent, I can do that also with copy/paste and uuidgen. But have the possibility to define scanning targets (similar to the agenda files in orgmode) would be really useful.

If you don't have time to implement it by yourself, you can also provide me an entry-point in your code and I would be happy to try it myself and create an PR.

seflue commented 4 months ago

Ok, I couldn't withstand my curiosity, so I had a look into the code.

Here you assume a string or an array of strings: https://github.com/chipsenkbeil/org-roam.nvim/blob/295fa650e157f52586473a763510f860323adeb9/lua/org-roam/database/loader.lua#L24

Which you here even treat like a tree (btw., my LSP shows tbl_flatten as deprecated - is it because of nvim 0.10?): https://github.com/chipsenkbeil/org-roam.nvim/blob/295fa650e157f52586473a763510f860323adeb9/lua/org-roam/database/loader.lua#L32

I gues, any handling of globbing must happen before this code: Reading the comment above helps - globbing seems already handled. So it actually boils down to expose this properly via config options and constructor arguments of loader.lua and database.lua https://github.com/chipsenkbeil/org-roam.nvim/blob/295fa650e157f52586473a763510f860323adeb9/lua/org-roam/database/loader.lua#L35-L44

Did I miss something? By the way, I very much appreciate, how clean your code is written. It is so easy and pleasant to read!

chipsenkbeil commented 4 months ago

Hey there! Thanks for the interest in the plugin :) Very kind words you've provided, and I'm more than happy to review a PR if you'd like to contribute.

You've already done digging, and yes the config directory is transformed into a glob to work with the nvim-orgmode plugin.

Config Updates

The way I'd consider approaching from a high level is to introduce an additional configuration option to provide extra paths that should be scanned for roam nodes.

https://github.com/chipsenkbeil/org-roam.nvim/blob/295fa650e157f52586473a763510f860323adeb9/lua/org-roam/config.lua#L13-L17

Maybe something like

---Paths to extra directories containing org files for use with org-roam. 
---@type string[]
extra_paths = {},

Database & Loader

From there, you'd need to update the database and loader to accept extra paths. I believe the loader can already accept multiple paths as you discovered. The database needs to be updated to support multiple paths.

Other References

Lastly, we'd need to double-check where the config.directory is used today. For example, this autocmd would need to be updated to support a list of directories instead of just one.

https://github.com/chipsenkbeil/org-roam.nvim/blob/295fa650e157f52586473a763510f860323adeb9/lua/org-roam/setup/autocmds.lua#L42-L46

And this example of a command creates a new database instance, which would also need to update the extra paths if we add them.

https://github.com/chipsenkbeil/org-roam.nvim/blob/295fa650e157f52586473a763510f860323adeb9/lua/org-roam/setup/commands.lua#L60-L69

And this sets up the database.

https://github.com/chipsenkbeil/org-roam.nvim/blob/295fa650e157f52586473a763510f860323adeb9/lua/org-roam/setup/database.lua#L11-L18

seflue commented 4 months ago

I already started to hack together something with a second config option taking a list of strings and smashing it together with directory before forwarding it to the loader. But because the extra folders weren't processed by the loader and I was too impatient and lazy to debug it right away, I deferred the work. I also don't want to annoy you with inconsistent code formattings, that's why I first would continue with the stylua issue #43.

chipsenkbeil commented 4 months ago

@seflue should be go to proceed now that you've gotten the stylua PR merged, right? I also sent you an invite to be a collaborator on this plugin. I'm a fan of fast collaboration in my repos, so figured I'd send you an invite since you were interested in contributing.

seflue commented 4 months ago

Thanks for the invitation. Yes, I will have a look into this and open a PR as soon as I have something. And of course, I will be happy to contribute.

seflue commented 3 months ago

@chipsenkbeil I finally got back to this issue and finished to implement it. A stupid bug hold me back and the setup code is not the easiest to debug. :sweat_smile:

seflue commented 3 months ago

Resolved by #55.