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

dmod: Make more robust when used outside default folders #13

Merged
merged 1 commit into from
Mar 25, 2021

Conversation

sascha-wolf
Copy link
Contributor

@sascha-wolf sascha-wolf commented Mar 24, 2021

The snippet expansion is now split into two distinct parts: the namespace and the module name.

The namespace expansion looks for a lib|test|spec folder and uses any folder below that as the namespace, joined by dots. If no lib|test|spec folder can be found, no namespace will be generated.

The module name is generated through the TM_FILENAME_BASE, and is basically the same as it was before. But this allows us to generate a defmodule Config module in config/config.exs.

Before

Expanding dmod in lib/foo/bar/baz.exs would result in:

defmodule Foo.Bar.Baz do
  
end

But expanding dmod in config/foo/bar/baz.exs would result in:

defmodule <path to project>/config/foo/bar/baz.exs do
  
end

Which is certainly unexpected.

After

Expanding dmod in lib/foo/bar/baz.exs would result in:

defmodule Foo.Bar.Baz do
  
end

And expanding dmod in config/foo/bar/baz.exs would result in:

defmodule Baz do
  
end

Which is not as nice as the lib version above but at least a usable module name. 🙂

The snippet expansion is now split into two distinct parts: the namespace and the module name.

The namespace expansion looks for a `lib|test|spec` folder and uses any folder below that as the namespace, joined by dots. If no `lib|test|spec` folder can be found, no namespace will be generated.

The module name is generated through the `TM_FILENAME_BASE`, and is basically the same as it was before. But this allows us to generate a `defmodule Config` module in `config/config.exs`.
@florinpatrascu
Copy link
Owner

W⦿‿⦿t!

@florinpatrascu florinpatrascu merged commit fb03b67 into florinpatrascu:master Mar 25, 2021
florinpatrascu added a commit that referenced this pull request Mar 26, 2021
…path and line number. Label string can easily be discarded

  inspired bby this [tip](https://elixirstream.dev/tips/7bca7ae3-1431-4bb1-bf2c-1ee3c5390a40) I added my own take on it. Hopefully you can enjoy this newer version as much as I do :)
- dmod: Make more robust when used outside default folders #13
- ^^^ Thank you @sascha-wolf <3
@florinpatrascu
Copy link
Owner

published!
Thank you @sascha-wolf ❤️

also added a new one iins ;)

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.

3 participants