Elixir - 模块没有用docs编译 [英] Elixir -- Module was not compiled with docs

查看:110
本文介绍了Elixir - 模块没有用docs编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习药剂。我有一个文件User.exs。它看起来像这样:

  defmodule用户do 
@moduledoc
定义用户结构和

#功能和东西去这里...

end

当我运行 iex 时,当我尝试查看文档时会发生什么:

  iex(1)> cuser.exs
[用户]
iex(2)> h用户
用户没有使用文档

任何想法?

解决方案

c(user.exs)编译内存中的文件,字节码(.beam文件)到磁盘,而 h / 1 目前需要(详细说明)光盘文件存在于磁盘上。您可以使 c 将生成的字节码存储在当前目录中,这将使 h / 1 使用 c(user.exs,。)

  $ ls 
user.exs
$ cat user.exs
defmodule User do
@moduledoc
定义用户结构和函数来处理用户

end
$ iex
Erlang / OTP 19 [erts-8.2] [source] [64位] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

交互式Elixir(1.4.2) - 按Ctrl + C退出(输入h()ENTER进行帮助)
iex(1)> ; c(user.exs,。)
[用户]
iex(2)> h用户

用户

定义用户结构和功能来处理用户。

iex(3)>
BREAK:(a)bort(c)ontinue(p)roc info(i)nfo(l)oaded
(v)ersion(k)ill(D)b-tables(d)istribution
^ C
$ ls
Elixir.User.beam user.exs



< hr>

h / 1 依赖于 Code.get_docs / 2 在模块上提取调用:code.get_object_code / 1 的文档。 :code.get_object_code / 1 根据其文档,搜索模块模块的目标代码的代码路径返回 {Module,Binary,Filename} 如果成功,否则错误


I just started learning elixir yesterday. I have a file User.exs. It looks like this:

defmodule User do
    @moduledoc """ 
    Defines the user struct and functions to handle users.
    """
    # functions and stuff go here...

end

When I run iex, this is what happens when I try to see the docs:

iex(1)> c "user.exs"
[User]
iex(2)> h User
User was not compiled with docs

Any ideas?

解决方案

c("user.exs") compiles the file in memory and does not write the bytecode (.beam file) to disk while h/1 currently requires (details below) the beam file to be present on disk to work. You can make c store the generated bytecode in the current directory which will make h/1 work with c("user.exs", "."):

$ ls
user.exs
$ cat user.exs
defmodule User do
  @moduledoc """
  Defines the user struct and functions to handle users.
  """
end
$ iex
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.4.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> c("user.exs", ".")
[User]
iex(2)> h User

                                      User

Defines the user struct and functions to handle users.

iex(3)>
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution
^C
$ ls
Elixir.User.beam user.exs


h/1 relies on Code.get_docs/2 to fetch the documentation which calls :code.get_object_code/1 on the module. :code.get_object_code/1 according to its docs, "Searches the code path for the object code of module Module. Returns {Module, Binary, Filename} if successful, otherwise error."

这篇关于Elixir - 模块没有用docs编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆