Permalink
Browse files

Completed ident retrieving and documentation.

  • Loading branch information...
1 parent 4e32034 commit bbc3bd0d1bea7e1456e874f1820fc15d24bc80b5 Tiphaine Turpin committed Jul 11, 2011
View
@@ -48,7 +48,8 @@ containing <file.ml>, or its parent directories, back to the root.
This file must contain exactly one directory name per line, and
compiled interface will be searched in this directories. Relative
directory names are interpreted with respect to the directory
-containing the project file .ocamlwizard.
+containing the project file .ocamlwizard. See ../.ocamlwizard for an
+example.
@@ -109,20 +110,38 @@ the test cases for a detailed overview of the current behavior.
Refactoring:
............
-- Renaming (C-c C-o r): rename a value identifier through a single .ml
- file (other sorts of idents are not yet implemented). The cursor
- must be placed on the *definition* of the value (typically, a let
- binding or a pattern). Renaming takes care of necessary propagation
- (e.g., when distinct values with the same name need to be renamed
- consistently because this name appears in a common interface), and
- capture is detected. Backups are made in case anything goes wrong.
+- Renaming (C-c C-o r): rename an identifier through a single .ml or
+ .mli file. The cursor must be placed on the *definition* of the
+ value (for example, a let binding or a pattern). Renaming takes care
+ of necessary propagation (e.g., when distinct values with the same
+ name need to be renamed consistently because this name appears in a
+ common interface), and capture is detected. Undoing works in emacs.
+ Backups are made in case anything goes wrong.
+ Renaming is implemented for: values, types, modules (non-recursive),
+ module types, fields, constructors, and exceptions. Objects are not
+ supported. Type variables, argument labels, and polymorphic variants
+ are not supported either.
+
+ The replacement is intended to be complete in the current file, up
+ to the following known limitations:
+ - labels, e.g. let x = .. in f ~x
+ - fields, e.g. let x = .. in {x} or match .. with {x} -> ..
+ - or-patterns, e.g. match .. with [], x | x, [] -> ..
- Command line interface
~~~~~~~~~~~~~~~~~~~~~~~~
-Needs to be redefined.
+The following conventions are common to all queries:
+- stdin is ignored,
+- stderr is used for debug purpose and should be discarded by editors.
+- possible exit codes are:
+ - 0: normal completion, with result is written on stdout
+ - 1: "controlled" failure, with an explanation message on stdout
+ - 2: unexpected error, with an exception backtrace printed on stdout.
+
+Command line arguments needs to be redesigned.
- Internal working overview
View
@@ -3,9 +3,8 @@
- Grep: should be easy to implement using rename
- Rename: return a list of files that emacs should revert
- Rename: check that we always lookup in the right environment
-- Rename: check that all Ident.t s in typedtree are processed
- Rename: rename type variables, argument labels, polymorphic variants, methods
-- Rename: propagate more constraints (constrs, fields, exceptions)
+- Rename: test propagation for constrs, fields, exceptions...
- Rename: collect all occurrences in a or-pattern
- Rename: retrieve a definition from an occurrence
- Rename: warn about potential future captures
@@ -245,34 +245,60 @@ let locate_field loc pid ploc fs tfs =
in
pid f
-(* Should be almost complete for expressions, but this is not a safety
- requirement anyway. *)
-let locate_renamed_id s loc =
+let locate_id loc pid ploc decls =
+ pid
+ (List.find
+ (function d -> contains (ploc d) loc)
+ decls)
+
+let find_id_def table id =
+ StringTbl.find table (Ident.name id)
+
+(* Missing: Tstr_class_type, class_infos, Tmeth_val, cstr_meths,
+ Tcf_inher, Tcf_val, Tcf_let *)
+let locate_renamed_id table loc =
let open Env in
locate_map `innermost
(function n ->
try Some (match n with
+
+ (* Values *)
| `pattern {pat_desc = Tpat_var id}
+ | `pattern {pat_desc = Tpat_alias (_, TPat_alias id)}
| `expression {exp_desc = Texp_for (id, _, _, _, _)}
- | `signature_item {sig_desc = Tsig_value (id, _)}
- -> Value, id
+ | `structure_item {str_desc = Tstr_primitive (id, _)}
+ | `signature_item {sig_desc = Tsig_value (id, _)} -> Value, id
+
+ | `class_expr {cl_desc =
+ Tcl_fun (_, _, bs, _, _) | Tcl_let (_, _, bs, _)} ->
+ Value, locate_id loc fst (function id, _ -> find_id_def table id) bs
+
+ (* Modules *)
| `structure_item {str_desc = Tstr_module (id, _)}
| `signature_item {sig_desc = Tsig_module (id, _)}
| `module_expr {mod_desc = Tmod_functor (id, _, _)}
| `module_type {mty_desc = Tmty_functor (id, _, _)}
- -> Module, id
+ | `expression {exp_desc = Texp_letmodule (id, _, _)} -> Module, id
+
+ | `structure_item {str_desc = Tstr_recmodule mods} ->
+ Module,
+ locate_id loc (function id, _, _ -> id)
+ (function id, _, _ -> find_id_def table id) mods
+
+ | `signature_item {sig_desc = Tsig_recmodule mods} ->
+ Module,
+ locate_id loc fst (function id, _ -> find_id_def table id) mods
+
+ (* Module types *)
| `structure_item {str_desc = Tstr_modtype (id, _)}
- | `signature_item {sig_desc = Tsig_modtype (id, _)}
- -> Modtype, id
+ | `signature_item {sig_desc = Tsig_modtype (id, _)} -> Modtype, id
+
+ (* Types *)
| `structure_item {str_desc = Tstr_type types}
- | `signature_item {sig_desc = Tsig_type types}
- ->
- let id, _ =
- List.find
- (function id, d -> contains d.typ_loc loc)
- types
- in
- Type, id
+ | `signature_item {sig_desc = Tsig_type types} ->
+ Type, locate_id loc fst (function _, d -> d.typ_loc) types
+
+ (* Constructors, fields, and exceptions *)
| `type_declaration d ->
(match d.typ_type.type_kind, d.typ_kind with
| Type_variant cs, Ttype_variant tcs ->
@@ -285,12 +311,11 @@ let locate_renamed_id s loc =
fs tfs
| Type_abstract, Ttype_abstract -> raise Not_found
| _ -> assert false)
+
| `structure_item {str_desc = Tstr_exception (id, _)}
- | `signature_item {sig_desc = Tsig_exception (id, _)} ->
- Constructor, id
+ | `structure_item {str_desc = Tstr_exn_rebind (id, _)}
+ | `signature_item {sig_desc = Tsig_exception (id, _)} -> Constructor, id
+
| _ -> raise Not_found)
with Not_found -> None)
- loc s
-
-let find_id_def table id =
- StringTbl.find table (Ident.name id)
+ loc
@@ -32,8 +32,8 @@ val get_lids :
(Location.t * Longident.t * (Env.t * Env.path_sort)) list
val locate_renamed_id :
+ Location.string_table -> int * int ->
[ `signature of Typedtree.signature | `structure of Typedtree.structure ] ->
- int * int ->
Env.path_sort * Ident.t
val find_id_def :
@@ -297,7 +297,10 @@ let rename loc name' file =
let s, idents, lidents, paths = read_typedtree source_kind typedtree_file in
(* Get the "initial" id to rename and its sort *)
- let renamed_kind, id = locate_renamed_id s loc in
+ let renamed_kind, id =
+ try locate_renamed_id idents loc s
+ with Not_found -> fail_owz "Cannot rename anything here"
+ in
let name = Ident.name id in
let name' = fix_case renamed_kind name' in
@@ -12,7 +12,7 @@ let r = {a = () ; b = ()}
let () = match [] with$
=>
-let () = match [] withError: File "completion/completion.ml", line 150, characters 19-25: Assertion failed
+let () = match [] withError: File "completion/completion.ml", line 128, characters 19-25: Assertion failed
Called from file "main/ocamlwizard.ml", line 90, characters 14-32
Called from file "main/ocamlwizard.ml", line 61, characters 6-10
EOF
@@ -54,7 +54,7 @@ let () = match () with $fo€o -> ()
=>
let () = match () with Error: Not_found
Raised at file "common/typedtreeOps.ml", line 181, characters 10-19
-Called from file "completion/completion.ml", line 120, characters 3-85
+Called from file "completion/completion.ml", line 98, characters 3-85
Called from file "main/ocamlwizard.ml", line 90, characters 14-32
Called from file "main/ocamlwizard.ml", line 61, characters 6-10
EOF
@@ -64,7 +64,7 @@ let () = match None with Some $_€ -> ()
let () = match None with Some Error: var
Raised at file "pervasives.ml", line 22, characters 22-33
Called from file "completion/extraction/proposal_extraction.ml", line 281, characters 11-25
-Called from file "completion/completion.ml", line 161, characters 14-56
+Called from file "completion/completion.ml", line 139, characters 14-56
Called from file "main/ocamlwizard.ml", line 90, characters 14-32
Called from file "main/ocamlwizard.ml", line 61, characters 6-10
EOF
@@ -122,7 +122,7 @@ let () = match `a with `b -> ()$
let () = match `a with `b -> ()Error: Error while typing
Raised at file "pervasives.ml", line 22, characters 22-33
Called from file "completion/completion.ml", line 62, characters 6-35
-Called from file "completion/completion.ml", line 100, characters 26-48
+Called from file "completion/completion.ml", line 82, characters 26-48
Called from file "main/ocamlwizard.ml", line 90, characters 14-32
Called from file "main/ocamlwizard.ml", line 61, characters 6-10
EOF
@@ -140,14 +140,14 @@ let () = match {a = () ; b = ()} with
let (_ : unit -> 'a) = function $
=>
-let (_ : unit -> 'a) = function Error: File "completion/completion.ml", line 150, characters 19-25: Assertion failed
+let (_ : unit -> 'a) = function Error: File "completion/completion.ml", line 128, characters 19-25: Assertion failed
Called from file "main/ocamlwizard.ml", line 90, characters 14-32
Called from file "main/ocamlwizard.ml", line 61, characters 6-10
EOF
let () = match () with | $
=>
-let () = match () with | Error: File "completion/completion.ml", line 150, characters 19-25: Assertion failed
+let () = match () with | Error: File "completion/completion.ml", line 128, characters 19-25: Assertion failed
Called from file "main/ocamlwizard.ml", line 90, characters 14-32
Called from file "main/ocamlwizard.ml", line 61, characters 6-10
EOF
@@ -156,14 +156,14 @@ let () = match true with true -> $
=>
let () = match true with true -> Error: Not_found
Raised at file "common/typedtreeOps.ml", line 181, characters 10-19
-Called from file "completion/completion.ml", line 120, characters 3-85
+Called from file "completion/completion.ml", line 98, characters 3-85
Called from file "main/ocamlwizard.ml", line 90, characters 14-32
Called from file "main/ocamlwizard.ml", line 61, characters 6-10
EOF
let () = match true with true -> () | $
=>
-let () = match true with true -> () | Error: File "completion/completion.ml", line 150, characters 19-25: Assertion failed
+let () = match true with true -> () | Error: File "completion/completion.ml", line 128, characters 19-25: Assertion failed
Called from file "main/ocamlwizard.ml", line 90, characters 14-32
Called from file "main/ocamlwizard.ml", line 61, characters 6-10
EOF
@@ -183,7 +183,7 @@ let () = match `a with `b -> ()$ (* because it doesn't type... *)
let () = match `a with `b -> ()Error: Error while typing
Raised at file "pervasives.ml", line 22, characters 22-33
Called from file "completion/completion.ml", line 62, characters 6-35
-Called from file "completion/completion.ml", line 100, characters 26-48
+Called from file "completion/completion.ml", line 82, characters 26-48
Called from file "main/ocamlwizard.ml", line 90, characters 14-32
Called from file "main/ocamlwizard.ml", line 61, characters 6-10
EOF
@@ -112,7 +112,7 @@ let () = so $ (* this does not work, purposely *)
let () = so Error: Error while typing
Raised at file "pervasives.ml", line 22, characters 22-33
Called from file "completion/completion.ml", line 62, characters 6-35
-Called from file "completion/completion.ml", line 100, characters 26-48
+Called from file "completion/completion.ml", line 82, characters 26-48
Called from file "main/ocamlwizard.ml", line 90, characters 14-32
Called from file "main/ocamlwizard.ml", line 61, characters 6-10
EOF
@@ -143,21 +143,21 @@ EOF
let _ = {a = () $
=>
-let _ = {a = () Error: File "completion/completion.ml", line 149, characters 17-23: Assertion failed
+let _ = {a = () Error: File "completion/completion.ml", line 127, characters 17-23: Assertion failed
Called from file "main/ocamlwizard.ml", line 90, characters 14-32
Called from file "main/ocamlwizard.ml", line 61, characters 6-10
EOF
let _ = {a = () ; M$
=>
-let _ = {a = () ; MError: File "completion/completion.ml", line 150, characters 19-25: Assertion failed
+let _ = {a = () ; MError: File "completion/completion.ml", line 128, characters 19-25: Assertion failed
Called from file "main/ocamlwizard.ml", line 90, characters 14-32
Called from file "main/ocamlwizard.ml", line 61, characters 6-10
EOF
let _ = {r $
=>
-let _ = {r Error: File "completion/completion.ml", line 149, characters 17-23: Assertion failed
+let _ = {r Error: File "completion/completion.ml", line 127, characters 17-23: Assertion failed
Called from file "main/ocamlwizard.ml", line 90, characters 14-32
Called from file "main/ocamlwizard.ml", line 61, characters 6-10
EOF
@@ -0,0 +1,5 @@
+let _ =
+ let module Y = struct let x = () end in
+ Y.x
+Renamed 1 definition(s) and 1 reference(s)
+
@@ -0,0 +1,5 @@
+let _ =
+ let module Y = struct let x = () end in
+ Y.x
+Renamed 1 definition(s) and 1 reference(s)
+
@@ -0,0 +1,14 @@
+module rec M : sig val x : unit end = struct let x = () end
+and N : sig end = struct let y = M.x end
+Error: different environments
+Raised at file "pervasives.ml", line 22, characters 22-33
+Called from file "refactor/findName.ml", line 196, characters 24-57
+Called from file "refactor/findName.ml", line 217, characters 21-33
+Called from file "hashtbl.ml", line 157, characters 23-35
+Called from file "hashtbl.ml", line 161, characters 12-33
+Called from file "refactor/findName.ml", line 238, characters 27-62
+Called from file "refactor/rename.ml", line 307, characters 6-79
+Called from file "main/ocamlwizard.ml", line 96, characters 31-59
+Called from file "main/ocamlwizard.ml", line 61, characters 6-10
+
+

0 comments on commit bbc3bd0

Please sign in to comment.