tangui
Hi all,
I’ve been playing with Specify lately and I’m trying to get the @type module attribute like the @doc one, so as to link to that type in my documentation.
Configuration looks like this:
Specify.defconfig do
@doc "there are no floors for me to sweep"
@type floors_to_sweep :: non_neg_integer()
field :floors_to_sweep, default: 0
end
Trying to get the @type module attribute always results in a nil value:
field_documentation = Module.delete_attribute(__MODULE__, :doc)
IO.inspect(Module.delete_attribute(__MODULE__, :type))
The :doc is retrieved, but not the :type module attribute.
I suspect the @type is processed in a particular way. Is there any way to retrieve it?
Cheers
Trending in Questions
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Other Trending Topics
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #performance










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
josevalim
Yeah, you can’t get @type, @spec, @callback and friends because they have special semantics. Usually, what is stored in a module attribute is evaluated, if you do
@foo 1 + 1, the value of@foois the result of1 + 1. For typespecs, we actually receive an AST that we process, and returning that would leak some implementation details.Qqwy
Interesting use case!
Currently, when you add
@type-annotations inside thedefconfig, they will end up being shown in the documentation just as if they were written outside of thedefconfig.So
t YourModule.floors_to_sweepwould work in IEx, and in the compiled HTML documentation, the type would also be listed.If you want to fully link to a type, what about writing a parser function and adding a
@specto that one? The field documentation will link to its parser function’s documentation, and in that way you can keep the semantics together. (The other advantage is that you can re-use the same type/parser for multiple fields).tangui
Thanks for your answers.
@Qqwy: not sure to understand and if it’s the same use case
. Mine is mainly about documenting hundreds (if not more) configuration options including many callbacks with most of the time different signatures, and linking between them (config option ↔ type), and also to help dialyzer with detecting type errors. Nice lib by the way!
Qqwy
I think this part is already covered by the existing functionality. Every module that uses
defconfigwill have, for every field in the documentation, the following part in their docs:Example here.
This is indeed not something that Specify currently helps you with. It definitely would be interesting to automate the generation of a ‘config typespec’ in some way. Maybe the field types can be inferred from the parser function’s spec, and we can then define a type for the config struct as a whole.
…
Thanks!
tangui
I’ve tried it and it’s somehow difficult to generate some specs because of the special syntaxes of @type and @spec (
::, etc.). See also: Dynamically generate typespecs from module attribute listQqwy
I’m fairly certain this is what Code.Typespec is meant to be used for.
We could (as long as the parser function is readable as an invocation of a certain MFA) call
Code.Typespec.fetch_specs(module), find the appropriate function’s spec in the response, and then useCode.Typespec.spec_to_quotedto turn it back into Elixir AST, which, assuming that it has the formatsome_fun(maybe, some, arguments) :: {:ok, result_type} | {:error, problem}means that we should be able to extract theresult_typefrom here.The one thing I haven’t figured out yet is how to disambugate remote types from local and built-in ones.
tangui
I’m now trying to get the
@moduledocmodule attribute in a__using__macro but in:Module.delete_attribute/2always returnsnil(although the@moduledocis set) andModule.put_attribute/3doesn’t set it (nothing in generated doc).Is there an exception with
@moduledoc? I suspect it is not set yet when callingModule.delete_attribute/2. AlsoModule.put_attribute/3is later erased by the plain@moduledoc(I’ve tested it - no@moduledocin the target module results inadditional_docbeing displayed).jackalcooper
Is this still true today? Or there are ways to get the type specs for functions now.
josevalim
Afaik there is still no public API for doing so.