ash/documentation/topics/development/development-utilities.md

71 lines
1.9 KiB
Markdown
Raw Normal View History

2022-07-06 06:19:06 +12:00
# Development Utilities
## ElixirSense Plugin
Ash uses [Spark](https://hexdocs.pm/spark) to build all of our DSLs (like `Ash.Resource` and `Ash.Domain`) and to validate options lists to functions. `Spark` ships with an extension that is automatically picked up by ElixirLS to provide autocomplete for all of our DSLs, and options list. You don't need to do anything to enable this, but it only works with ElixirLS (not other language server tools).
2022-07-06 06:19:06 +12:00
## Formatter plugin
2022-07-06 06:19:06 +12:00
`Spark` also ships with a formatter plugin that can help you keep your resources formatted consistently. This plugin can sort the sections of your DSL to make your resources more consistent, and it can ensure that the DSL builders don't have parenthesis around them. (i.e `attribute :foo, :bar` vs `attribute(:foo, :bar)`).
2022-07-06 06:19:06 +12:00
### Adding the plugin
2022-07-06 06:19:06 +12:00
Add the following to your `.formatter.exs`
```elixir
[
plugins: [Spark.Formatter], # <- add the plugin here
2022-07-06 06:19:06 +12:00
inputs: ...
]
```
### Configuration
#### Minimal config for your Ash Resources
```elixir
config :spark, :formatter,
remove_parens?: true,
"Ash.Domain": [],
"Ash.Resource": [
section_order: [
# any section not in this list is left where it is
# but these sections will always appear in this order in a resource
:actions,
:attributes,
:relationships,
:identities
]
]
```
#### If you `use` a different module than Ash.Resource
2022-07-06 06:19:06 +12:00
```elixir
config :spark, :formatter,
[
"Ash.Resource": [
section_order: [
:resource,
:identities,
:attributes,
:relationships,
...
]
],
# If you use a different module than Ash.Resource
"MyApp.Resource": [
type: Ash.Resource,
# What extensions might be added by your base module
extensions: [...],
section_order: [
:resource,
:identities,
:attributes,
:relationships,
...
]
]
2022-07-06 06:19:06 +12:00
]
```