Skip to content

feat: exclude_dir for excluding directories within vaults#822

Open
neuroconvergent wants to merge 11 commits into
obsidian-nvim:mainfrom
neuroconvergent:exclude-directories
Open

feat: exclude_dir for excluding directories within vaults#822
neuroconvergent wants to merge 11 commits into
obsidian-nvim:mainfrom
neuroconvergent:exclude-directories

Conversation

@neuroconvergent
Copy link
Copy Markdown
Contributor

Excluding directories from workspaces (#816 )

This PR adds a config option exclude_dir, which accepts a table of path strings to exclude certain directories from the plug-in entirely. This follows a similar logic to the current implementation of .gitignore i.e. uses glob matching for path (removes all exclusions with ! from current gitignore implementation).

The config option has been tested to work as both a global option and as a workspace override.

PR Checklist

  • The PR contains a description of the changes
  • I read the [CONTRIBUTING.md] file
  • The CHANGELOG.md is updated
  • The changes are documented in the README.md file
  • The code complies with make chores (for style, lint, types, and tests)

Copy link
Copy Markdown
Member

@neo451 neo451 left a comment

Choose a reason for hiding this comment

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

see the code comments, plus:

  1. there's an obsidian app counterpart that is internally called "userIgnoreFilters", so might be good to call the option "ignore_filters"
  2. I am not too sure about why add a new option, instead of just use gitignore's patterns, make note attaching and ripgrep also ignore them, seems cleaner, I get the appeal to declare a readable list in config, but for now I prefer less option the better
  3. need some tests, also fine if you prefer to not go down that rabbit hole, since we don't have proper test coverage in the search module, so just some simpler tests can do

Comment thread lua/obsidian/exclusions.lua Outdated
Comment thread lua/obsidian/search/opts.lua Outdated

if Obsidian.opts.exclude_dir and #Obsidian.opts.exclude_dir > 0 then
for _, dir in ipairs(Obsidian.opts.exclude_dir) do
add_exclude(search_opts, dir)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if the option supposed to be a list of globs or just subdir names? if former, the add_exclude will not work in many cases?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did some testing and glob patterns do seem to work. Only exception seems to be a global path but that is the expected ripgrep behaviour.

Can you maybe give me an example where this would fail?

Comment thread lua/obsidian/note.lua Outdated
@neo451
Copy link
Copy Markdown
Member

neo451 commented Apr 26, 2026

thank you for the idea and work btw :)

@neuroconvergent
Copy link
Copy Markdown
Contributor Author

My original idea was just to exclude entire sub-directories, but it might be better to rename the option to allow individual files. As you have already pointed out, it would fail with some glob patterns when looking so that needs to be robust.

The problem with just using gitignore is that there might be files which are to be committed to git but need to be ignored from the plug-in. For example, I use a program called presenterm for creating review slides but these markdown files don't work properly with some YAML headers used by Obsidian. So I want to exclude these files from Obsidian frontmatter or LSP while keeping them in my git tree.

I can certainly add some tests, I hope a few simple tests with different kinds of options such as relative path, absolute path and glob patterns should suffice. I can't personally think of any edge cases that specifically need to be tested but do let me know if you have any in mind and I can add them.

@neo451
Copy link
Copy Markdown
Member

neo451 commented May 24, 2026

great work, sorry for the late response, some notes before I merge this:

  1. address the style thing
  2. I think this can be moved into a new file config module, like file.ignore_filters, and there can be a file.trash with feat: implement lsp will delete and vault trash folder #804
  3. for consistency, rename all the exclude exclusion in code to ignore, the module name and the function names
  4. document in a new docs/File.md and in inline comments, that users should use simple gitignore style globs without modifiers, and rg compatibility is not guaranteed
  5. in autocmds.lua, move the ignore check after find_workspace call, otherwise it is called for any markdown file, which is not efficient and outside the duty of this plugin.

@neuroconvergent
Copy link
Copy Markdown
Contributor Author

These suggestions seem fair to me so I have made the changes you suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants