summaryrefslogtreecommitdiff
path: root/lib/edoc
diff options
context:
space:
mode:
authorHans Bolinder <hasse@erlang.org>2021-02-01 07:17:32 +0100
committerHans Bolinder <hasse@erlang.org>2021-02-01 07:17:32 +0100
commitee6a69bcef0dfdafe07906b939052d24e25be9c3 (patch)
treea778d0648b2b9fbbb3bc1eba374ce0d25a29a1e3 /lib/edoc
parent2ac9e0744e867f791662a5f279e91f6a7bf67199 (diff)
parent370a2f1c940d305818eb6e415e874741382c22d9 (diff)
downloaderlang-ee6a69bcef0dfdafe07906b939052d24e25be9c3.tar.gz
Merge branch 'richcarl/columns/PR-2664/OTP-16824'
* richcarl/columns/PR-2664/OTP-16824: (56 commits) Update primary bootstrap erl_lint: Give a better column position for format warnings erl_lint: Correct column number for unsized binary not at end Include column numbers in compiler warnings dialyzer: Improve column numbers in warnings stdlib: Improve locations of annotations of abstract code stdlib: Improve error locations in module erl_lint stdlib: Improve error locations in module epp stdlib: Improve error locations in module erl_parse stdlib: Fix handling of annotations in erl_expand_records erl_docgen: Correct handling of annotation of abstract code syntax_tools: Generalize start line to be location syntax_tools: Correct handling of annotations of abstract code edoc: Correct handling of annotations of abstract code tools: Substitute Anno for Line in xref_reader tools: Substitute Anno for Line in cover stdlib: Substitute Anno for Line in epp stdlib: Substitute Anno for Line in erl_eval stdlib: Substitute Anno for Line in erl_pp stdlib: Substitute Anno for Line in eval_bits ...
Diffstat (limited to 'lib/edoc')
-rw-r--r--lib/edoc/src/edoc_extract.erl10
-rw-r--r--lib/edoc/src/edoc_specs.erl21
2 files changed, 22 insertions, 9 deletions
diff --git a/lib/edoc/src/edoc_extract.erl b/lib/edoc/src/edoc_extract.erl
index e878fc1a39..e821c1931d 100644
--- a/lib/edoc/src/edoc_extract.erl
+++ b/lib/edoc/src/edoc_extract.erl
@@ -385,7 +385,7 @@ collect([F | Fs], Cs, Ss, Ts, Rs, As, Header, Mod) ->
comment ->
collect(Fs, [F | Cs], Ss, Ts, Rs, As, Header, Mod);
{function, Name} ->
- L = erl_syntax:get_pos(F),
+ L = get_line(F),
Export = ordsets:is_element(Name, Mod#module.exports),
Args = parameters(erl_syntax:function_clauses(F)),
collect(Fs, [], [], [], [],
@@ -394,7 +394,7 @@ collect([F | Fs], Cs, Ss, Ts, Rs, As, Header, Mod) ->
data = {comment_text(Cs),Ss,Ts,Rs}} | As],
Header, Mod);
{attribute, {module, _}} when Header =:= undefined ->
- L = erl_syntax:get_pos(F),
+ L = get_line(F),
collect(Fs, [], [], [], [], As,
#entry{name = module, line = L,
data = {comment_text(Cs),Ss,Ts,Rs}},
@@ -441,7 +441,7 @@ comment_text(Cs) ->
comment_text(Cs, []).
comment_text([C | Cs], Ss) ->
- L = erl_syntax:get_pos(C),
+ L = get_line(C),
comment_text(Cs, [#comment{line = L,
text = [remove_percent_chars(S)
|| S <- erl_syntax:comment_text(C)]}
@@ -449,6 +449,10 @@ comment_text([C | Cs], Ss) ->
comment_text([], Ss) ->
Ss.
+get_line(Tree) ->
+ Anno = erl_syntax:get_pos(Tree),
+ erl_anno:line(Anno).
+
%% @doc Replaces leading `%' characters by spaces. For example, `"%%%
%% foo" -> "\s\s\s foo"', but `"% % foo" -> "\s % foo"', since the
%% second `%' is preceded by whitespace.
diff --git a/lib/edoc/src/edoc_specs.erl b/lib/edoc/src/edoc_specs.erl
index 9b5050a7c2..8c2fb8ee50 100644
--- a/lib/edoc/src/edoc_specs.erl
+++ b/lib/edoc/src/edoc_specs.erl
@@ -47,8 +47,9 @@ type(Form, TypeDocs) ->
case Data0 of
{R, Fs} ->
record = Name,
- L = erl_syntax:get_pos(Form),
- {{record, R}, {type, L, record, [{atom,L,R} | Fs]}, [], ""};
+ Anno = erl_syntax:get_pos(Form),
+ {{record, R},
+ {type, Anno, record, [{atom,Anno,R} | Fs]}, [], ""};
{N,T,As} ->
type = tag(Name),
Doc0 =
@@ -137,11 +138,11 @@ find_type_docs([F | Fs], Cs, Fun) ->
try get_name_and_last_line(F) of
{Name, LastTypeLine} ->
C0 = erl_syntax:comment(["% @type f(). "]),
- C1 = erl_syntax:set_pos(C0, LastTypeLine),
+ C1 = erl_syntax:set_pos(C0, anno(LastTypeLine)),
%% Postcomments before the dot after the typespec are ignored.
C2 = [C1 | [C ||
C <- erl_syntax:get_postcomments(F),
- erl_syntax:get_pos(C) >= LastTypeLine]],
+ get_tree_line(C) >= LastTypeLine]],
C3 = collect_comments(Fs, LastTypeLine),
#tag{data = Doc0} = Fun(lists:reverse(C2 ++ C3), LastTypeLine),
case strip(Doc0) of % Strip away "f(). \n"
@@ -158,7 +159,7 @@ find_type_docs([F | Fs], Cs, Fun) ->
collect_comments([], _Line) ->
[];
collect_comments([F | Fs], Line) ->
- L1 = erl_syntax:get_pos(F),
+ L1 = get_tree_line(F),
if
L1 =:= Line + 1;
L1 =:= Line -> % a separate postcomment
@@ -175,6 +176,13 @@ collect_comments([F | Fs], Line) ->
%% by a -type attribute and the include statement is followed by a
%% comment (which is not meant to be documentation of the type).
+anno(Location) ->
+ erl_anno:new(Location).
+
+get_tree_line(Tree) ->
+ Anno = erl_syntax:get_pos(Tree),
+ erl_anno:line(Anno).
+
is_comment(F) ->
erl_syntax_lib:analyze_form(F) =:= comment.
@@ -190,7 +198,8 @@ strip([_ | S]) ->
get_name_and_last_line(F) ->
{Name, Data} = analyze_type_attribute(F),
type = edoc_specs:tag(Name),
- Attr = {attribute, erl_syntax:get_pos(F), Name, Data},
+ Anno = erl_syntax:get_pos(F),
+ Attr = {attribute, Anno, Name, Data},
Fun = fun(A) ->
Line = get_line(A),
case get('$max_line') of