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
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










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.