Skip to content

Commit feb9b1e

Browse files
committed
Print scope
1 parent 6aa9d71 commit feb9b1e

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

analysis/src/CmtViewer.ml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
let loc_to_string (loc : Warnings.loc) : string =
2-
Format.sprintf "(%02d,%02d--%02d,%02d)" loc.loc_start.pos_lnum
3-
(loc.loc_start.pos_cnum - loc.loc_start.pos_bol)
4-
loc.loc_end.pos_lnum
5-
(loc.loc_end.pos_cnum - loc.loc_end.pos_bol)
6-
71
let filter_by_cursor cursor (loc : Warnings.loc) : bool =
82
match cursor with
93
| None -> true
@@ -70,16 +64,16 @@ let dump ?filter rescript_json cmt_path =
7064
match kind with
7165
| KType t ->
7266
Printf.printf "%d ktype %s\n" stamp
73-
(loc_to_string t.extentLoc)
67+
(Warnings.loc_to_string t.extentLoc)
7468
| KValue t ->
7569
Printf.printf "%d kvalue %s\n" stamp
76-
(loc_to_string t.extentLoc)
70+
(Warnings.loc_to_string t.extentLoc)
7771
| KModule t ->
7872
Printf.printf "%d kmodule %s\n" stamp
79-
(loc_to_string t.extentLoc)
73+
(Warnings.loc_to_string t.extentLoc)
8074
| KConstructor t ->
8175
Printf.printf "%d kconstructor %s\n" stamp
82-
(loc_to_string t.extentLoc));
76+
(Warnings.loc_to_string t.extentLoc));
8377

8478
(* dump the structure *)
8579
let rec dump_structure indent (structure : Module.structure) =
@@ -91,11 +85,13 @@ let dump ?filter rescript_json cmt_path =
9185
let open Module in
9286
match item.kind with
9387
| Value _typedExpr ->
94-
Printf.printf "Value %s %s\n" item.name (loc_to_string item.loc)
88+
Printf.printf "Value %s %s\n" item.name
89+
(Warnings.loc_to_string item.loc)
9590
| Type _ ->
96-
Printf.printf "Type %s %s\n" item.name (loc_to_string item.loc)
91+
Printf.printf "Type %s %s\n" item.name (Warnings.loc_to_string item.loc)
9792
| Module {type_ = m} ->
98-
Printf.printf "Module %s %s\n" item.name (loc_to_string item.loc);
93+
Printf.printf "Module %s %s\n" item.name
94+
(Warnings.loc_to_string item.loc);
9995
dump_module indent m
10096
and dump_module indent (module_ : Module.t) =
10197
match module_ with
@@ -127,6 +123,6 @@ let dump ?filter rescript_json cmt_path =
127123
| 0 -> compare aLoc.pos_cnum bLoc.pos_cnum
128124
| c -> c)
129125
|> List.iter (fun {loc; locType} ->
130-
let locStr = loc_to_string loc in
126+
let locStr = Warnings.loc_to_string loc in
131127
let kindStr = SharedTypes.locTypeToString locType in
132128
Printf.printf "%s %s\n" locStr kindStr)

analysis/src/Completions.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ let getCompletions ~debug ~path ~pos ~currentFile ~forHover =
99
with
1010
| None -> None
1111
| Some (completable, scope) -> (
12+
if debug then (
13+
Printf.printf "\nScope from frontend:\n";
14+
List.iter
15+
(fun item ->
16+
Printf.printf "%s\n" (SharedTypes.ScopeTypes.item_to_string item))
17+
scope;
18+
print_newline ());
1219
(* Only perform expensive ast operations if there are completables *)
1320
match Cmt.loadFullCmtFromPath ~path with
1421
| None -> None

analysis/src/SharedTypes.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,18 @@ module ScopeTypes = struct
801801
| Type of string * Location.t
802802
| Value of string * Location.t * Completable.contextPath option * item list
803803
| Include of string * Location.t
804+
805+
let item_to_string = function
806+
| Constructor (name, loc) ->
807+
"Constructor " ^ name ^ " " ^ Warnings.loc_to_string loc
808+
| Field (name, loc) -> "Field " ^ name ^ " " ^ Warnings.loc_to_string loc
809+
| Module (name, loc) -> "Module " ^ name ^ " " ^ Warnings.loc_to_string loc
810+
| Open path -> "Open " ^ (path |> String.concat ".")
811+
| Type (name, loc) -> "Type " ^ name ^ " " ^ Warnings.loc_to_string loc
812+
| Value (name, loc, _, _) ->
813+
"Value " ^ name ^ " " ^ Warnings.loc_to_string loc
814+
| Include (name, loc) ->
815+
"Include " ^ name ^ " " ^ Warnings.loc_to_string loc
804816
end
805817

806818
module Completion = struct

compiler/ext/warnings.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,3 +676,9 @@ let help_warnings () =
676676
(String.concat ", " (List.map string_of_int l))
677677
done;
678678
exit 0
679+
680+
let loc_to_string (loc : loc) : string =
681+
Format.sprintf "(%02d,%02d--%02d,%02d)" loc.loc_start.pos_lnum
682+
(loc.loc_start.pos_cnum - loc.loc_start.pos_bol)
683+
loc.loc_end.pos_lnum
684+
(loc.loc_end.pos_cnum - loc.loc_end.pos_bol)

compiler/ext/warnings.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,8 @@ val message : t -> string
126126
val number : t -> int
127127

128128
val reset : unit -> unit
129+
130+
val loc_to_string : loc -> string
131+
(**
132+
Turn the location into a string with (line,column--line,column) format.
133+
*)

0 commit comments

Comments
 (0)