Skip to content

Default to a specific file using multiple keys #196

Description

@sodapopcan

Apologies for the subject/description, I had a really tough time coming up with a one sentence summary.

With this directory structure:

lib/
  ops.ex
  ops/
    accounts/
      filters.ex
    suppliers.ex
test/
  ops/
    suppliers_test.exs

I would like the command :Edomain without arguments to edit lib/ops.ex and otherwise edit files within lib/ops/*.ex.

I can accomplish this with the following:

let g:projectionist_heuristics['mix.exs'] = {
      \   'lib/ops.ex': {
      \     'type': 'domain',
      \   },
      \   'lib/ops/*.ex': {
      \     'type': 'domain'
      \   }
      \ }

However, as soon as I introduce an alternate file to either command, things get a little funky.

let g:projectionist_heuristics['mix.exs'] = {
      \   'lib/ops.ex': {
      \     'type': 'domain',
      \   },
      \   'lib/ops/*.ex': {
      \     'type': 'domain',
      \     'alternate': 'test/ops/{}_test.exs' " <----- Add this
      \   }
      \ }

Now calling :Edomain (no args) on a file within lib/ops/ that doesn't have a test will take me to the depth-first file under that dir--In my case that's opts/accounts/filters.ex. Calling it on a file with a test, in my case lib/ops/suppliers.ex, will be a no-op (leaving me on the current file). Otherwise, calling it from outside lib/ops will take me to lib/ops.ex.

I've tried some hacks like adding: 'related': ['lib/ops.ex'] under both keys to no avail.

I know it's documented that alternate will be used as the default for related but I don't think that matches up with what I'm seeing here.

Is this a bug or to be expected?

I created a small sample app here.

I've actually found this behaviour to be somewhat random (race condition, perhaps?). For example, sometimes calling :Edo on the suppliers.ex will take me to the filters.ex file, but other times it will be a no-op.

Thanks!

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions