Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow multiple type declarations, use better exception

  • Loading branch information...
commit 461828670f4be8540c9df2e105d7f5a1e6dbf603 1 parent b381187
tturpin tturpin authored
1  ocamlwizard/TODO
View
@@ -2,6 +2,7 @@
- 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: collect all occurrences in a or-pattern
13 ocamlwizard/refactor/findName.ml
View
@@ -266,9 +266,13 @@ let locate_renamed_id s loc =
-> Modtype, id
| `structure_item {str_desc = Tstr_type types}
| `signature_item {sig_desc = Tsig_type types}
- -> (match types with
- | [id, _] -> Type, id
- | _ -> failwith "multiple type definitions are not yet supported")
+ ->
+ let id, _ =
+ List.find
+ (function id, d -> contains d.typ_loc loc)
+ types
+ in
+ Type, id
| `type_declaration d ->
(match d.typ_type.type_kind, d.typ_kind with
| Type_variant cs, Ttype_variant tcs ->
@@ -277,7 +281,8 @@ let locate_renamed_id s loc =
| Type_record (fs, _), Ttype_record tfs ->
Label,
locate_field loc
- (function id, _, _ -> id) (function _, _, _, loc -> loc) fs tfs
+ (function id, _, _ -> id) (function _, _, _, loc -> loc)
+ fs tfs
| Type_abstract, Ttype_abstract -> raise Not_found
| _ -> assert false)
| `structure_item {str_desc = Tstr_exception (id, _)}
10 ocamlwizard/refactor/rename.ml
View
@@ -198,7 +198,7 @@ let read_typedtree _ file =
match data.(0) with
| Saved_implementation str -> `structure str
| Saved_signature sg -> `signature sg
- | _ -> failwith "error reading cmt(i) file"
+ | _ -> fail_owz "error reading cmt(i) file"
in
try
match data.(1), data.(2), data.(3) with
@@ -208,7 +208,7 @@ let read_typedtree _ file =
tree, loc, lloc, env
| _ -> raise Not_found
with
- _ -> failwith
+ _ -> fail_owz
"ident location or path environment table not found in cmt(i)"
let sort_replaces =
@@ -285,13 +285,13 @@ let rename loc name' file =
(* Check that everything is up-to-date *)
if Common_config.has_auto_save file then
- failwith "buffer must be saved before renaming";
+ fail_owz "buffer must be saved before renaming";
let source_kind = classify_source file in
let typedtree_file = typedtree_file source_kind file in
if not (Sys.file_exists typedtree_file) then
- failwith ("no cmt(i) file for " ^ file);
+ fail_owz "no cmt(i) file for %s" file;
if Unix.((stat file).st_mtime > (stat typedtree_file).st_mtime) then
- failwith "cmt(i) file is older than source file";
+ fail_owz "cmt(i) file is older than source file";
(* Read the typedtree *)
let s, idents, lidents, paths = read_typedtree source_kind typedtree_file in
2  ocamlwizard/test/Makefile
View
@@ -8,7 +8,7 @@ R_CASES=renameSimple.ml renameSigNewCaptured.ml renameSigOldCaptured.ml \
renameOpenNewCaptured.ml renameOpenOldCaptured.ml \
renameMultiple.ml renameProp.ml renamePropFunctor.ml \
renamePropFunctorNoApp.ml renameFor.ml renameVal.ml \
- renameType.ml renameTypeInSig.ml \
+ renameType.ml renameTypeInSig.ml renameTypes.ml\
renameModtype.ml renameModtypeInSig.ml \
renameModule.ml renameModuleInSig.ml renameModuleInFunctor.ml \
renameModuleInFunctorType.ml \
5 ocamlwizard/test/expected/renameTypes_rres.ml
View
@@ -0,0 +1,5 @@
+type a = y
+and y = [`foo]
+and z
+Renamed 1 definition(s) and 1 reference(s)
+
7 ocamlwizard/test/renameException_rres.ml
View
@@ -1,7 +0,0 @@
-exception Y
-
-let _ = match Y with Y -> ()
-
-let _ = try () with Y -> ()
-Renamed 1 definition(s) and 3 reference(s)
-
3  ocamlwizard/test/renameTypes.ml
View
@@ -0,0 +1,3 @@
+type a = x
+and $x€ = [`foo]
+and z
Please sign in to comment.
Something went wrong with that request. Please try again.