Skip to content
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

Elixir umbrellas - any ideas if its possible to get it working? #154

Open
dkuku opened this issue Jan 2, 2021 · 3 comments
Open

Elixir umbrellas - any ideas if its possible to get it working? #154

dkuku opened this issue Jan 2, 2021 · 3 comments

Comments

@dkuku
Copy link

dkuku commented Jan 2, 2021

I had a setup like that and it was perfect,

  "lib/**/controllers/*_controller.ex": {
    "type": "controller",
    "alternate": "test/{dirname}/controllers/{basename}_controller_test.exs",
    "template": [
      "defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}Controller do",
      "  use {dirname|camelcase|capitalize}, :controller",
      "end"
    ]
  }

but stopped working in umbrella app which adds another two nested directories
apps/app_name/lib/**/controllers/
difference is

.
├── config
├── lib
│   ├── myapp
│   │      └── accounts
│   └── myapp_web
│       ├── controllers
│       ├── templates
│       └── views
└── test
    ├── myapp
    │   └── accounts
    ├── myapp_web
    │   ├── channels
    │   ├── controllers
    │   ├── features
    │   └── views
    └── support

and default umbrella is nested 2 levels deeper

└── apps
    ├── myapp
    │   ├── lib
    │   │    └── myapp
    │   └── test
    │         └── myapp
    │              └── accounts
    └── myapp_web
        ├── lib
        │   └── myapp_web
        │       ├── controllers
        │       ├── templates
        │       └── views
        └── test
            ├── myapp_web
            │   ├── controllers
            │   └── views
            └── support

2 options come to my mind - have a way to split the dirname and drop the first two elements from the list or have a possibility to run a regex on the dirname

@frm
Copy link

frm commented Nov 29, 2022

Not an ideal solution, but I worked around it by detecting if I'm in an umbrella root on startup and calculating the projections for each app.

In my case:

function! AddUmbrellaProjections()
  let l:apps = split(globpath('apps', '*'), '\n')

  if filereadable("mix.exs") && isdirectory("apps")
    let l:projections = {}

    for l:app in l:apps
      let l:projections[l:app . '/lib/*.ex'] = {
            \ "skeleton": "mod",
            \ "alternate": l:app . "/test/{}_test.exs"
            \ }
    endfor

    call projectionist#append(getcwd(), l:projections)
  endif
endfunction

autocmd User ProjectionistDetect
\ call AddUmbrellaProjections()

@tpope
Copy link
Owner

tpope commented Dec 3, 2022

The right way to do this is to start with g:projectionist_file and check parent directories looking for a match. I have several plugins that do this you can use as inspiration: salve.vim, rake.vim, bundler.vim, rails.vim, rbenv.vim, scriptease.vim, fugitive.vim. Search for projectionist_file. Unfortunately, all of these have extra complexity of some sort or another; none is suitable for direct copy and paste.

@Mahammadnajaf
Copy link

"apps//lib//controllers/*_controller.ex": {
"type": "controller",
"alternate": "test/{dirname}/controllers/{basename}_controller_test.exs",
"template": [
"defmodule {dirname|split('/'):sublist(2)|join('/')|camelcase|capitalize}.{basename|camelcase|capitalize}Controller do",
" use {dirname|split('/'):sublist(2)|join('/')|camelcase|capitalize}, :controller",
"end"
]
}

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

No branches or pull requests

4 participants