ソースを参照

fix for completion of modules types in current package

Nicolas Cannasse 13 年 前
コミット
7625ec3a64
2 ファイル変更22 行追加11 行削除
  1. 13 2
      main.ml
  2. 9 9
      parser.ml

+ 13 - 2
main.ml

@@ -1048,10 +1048,21 @@ with
 				error ctx ("No classes found in " ^ String.concat "." p) Ast.null_pos
 			else
 				complete_fields (List.map (fun f -> f,"","") (packs @ classes))
-		| Some c ->
+		| Some (c,cur_package) ->
 			try
 				let ctx = Typer.create com in
-				let m = Typeload.load_module ctx (p,c) Ast.null_pos in
+				let rec lookup p = 
+					try
+						Typeload.load_module ctx (p,c) Ast.null_pos
+					with e ->
+						if cur_package then 
+							match List.rev p with
+							| [] -> raise e
+							| _ :: p -> lookup (List.rev p)
+						else
+							raise e
+				in
+				let m = lookup p in
 				complete_fields (List.map (fun t -> snd (t_path t),"","") (List.filter (fun t -> not (t_infos t).mt_private) m.m_types))
 			with Completion c ->
 				raise (Completion c)

+ 9 - 9
parser.ml

@@ -28,7 +28,7 @@ type error_msg =
 	| Custom of string
 
 exception Error of error_msg * pos
-exception TypePath of string list * string option
+exception TypePath of string list * (string * bool) option
 exception Display of expr
 
 let error_msg = function
@@ -170,22 +170,22 @@ let semicolon s =
 let rec	parse_file s =
 	doc := None;
 	match s with parser
-	| [< '(Kwd Package,_); p = parse_package; _ = semicolon; l = parse_type_decls []; '(Eof,_) >] -> p , l
-	| [< l = parse_type_decls []; '(Eof,_) >] -> [] , l
+	| [< '(Kwd Package,_); p = parse_package; _ = semicolon; l = parse_type_decls p []; '(Eof,_) >] -> p , l
+	| [< l = parse_type_decls [] []; '(Eof,_) >] -> [] , l
 
-and parse_type_decls acc s =
+and parse_type_decls pack acc s =
 	try
 		match s with parser
-		| [< v = parse_type_decl; l = parse_type_decls (v :: acc) >] -> l
+		| [< v = parse_type_decl; l = parse_type_decls pack (v :: acc) >] -> l
 		| [< >] -> List.rev acc
-	with (TypePath ([],Some name)) as e ->
+	with TypePath ([],Some (name,false)) ->
 		(* resolve imports *)
 		List.iter (fun d ->
 			match fst d with
-			| EImport t when (t.tsub = None && t.tname = name) -> raise (TypePath (t.tpackage,Some t.tname))
+			| EImport t when (t.tsub = None && t.tname = name) -> raise (TypePath (t.tpackage,Some (name,false)))
 			| _ -> ()
 		) acc;
-		raise e
+		raise (TypePath (pack,Some(name,true)))
 
 and parse_type_decl s =
 	match s with parser
@@ -366,7 +366,7 @@ and parse_type_path1 pack = parser
 		let sub = (match s with parser
 			| [< '(Dot,p); s >] ->
 				(if is_resuming p then
-					raise (TypePath (List.rev pack,Some name))
+					raise (TypePath (List.rev pack,Some (name,false)))
 				else match s with parser
 					| [< '(Const (Type name),_) >] -> Some name
 					| [< >] -> serror())