Browse Source

allow position/usage completion on enum fields (closes #1968)

Simon Krajewski 11 years ago
parent
commit
e9852dc250
2 changed files with 15 additions and 17 deletions
  1. 7 8
      codegen.ml
  2. 8 9
      typer.ml

+ 7 - 8
codegen.ml

@@ -914,14 +914,13 @@ let detect_usage com =
 	List.iter (fun t -> match t with
 		| TClassDecl c ->
 			let rec expr e = match e.eexpr with
-				| TField(_,fa) ->
-					begin match extract_field fa with
-						| Some cf when Meta.has Meta.Usage cf.cf_meta ->
-							let p = {e.epos with pmin = e.epos.pmax - (String.length cf.cf_name)} in
-							usage := p :: !usage;
-						| _ ->
-							()
-					end;
+				| TField(_,FEnum(_,ef)) when Meta.has Meta.Usage ef.ef_meta ->
+					let p = {e.epos with pmin = e.epos.pmax - (String.length ef.ef_name)} in
+					usage := p :: !usage;
+					Type.iter expr e
+				| TField(_,(FAnon cf | FInstance (_,cf) | FStatic (_,cf) | FClosure (_,cf))) when Meta.has Meta.Usage cf.cf_meta ->
+					let p = {e.epos with pmin = e.epos.pmax - (String.length cf.cf_name)} in
+					usage := p :: !usage;
 					Type.iter expr e
 				| TLocal v when Meta.has Meta.Usage v.v_meta ->
 					usage := e.epos :: !usage

+ 8 - 9
typer.ml

@@ -3351,15 +3351,14 @@ and handle_display ctx e iscall p =
 	| DMUsage | DMPosition ->
 		(* print_endline (s_expr (s_type (print_context())) e); *)
 		begin match e.eexpr with
-		| TField(_,fa) ->
-			begin match extract_field fa with
-				| None ->
-					()
-				| Some cf ->
-					if ctx.com.display = DMPosition then
-						raise (DisplayPosition [cf.cf_pos]);
-					cf.cf_meta <- (Meta.Usage,[],p) :: cf.cf_meta;
-			end
+		| TField(_,FEnum(_,ef)) ->
+			if ctx.com.display = DMPosition then
+				raise (DisplayPosition [ef.ef_pos]);
+			ef.ef_meta <- (Meta.Usage,[],p) :: ef.ef_meta;
+		| TField(_,(FAnon cf | FInstance (_,cf) | FStatic (_,cf) | FClosure (_,cf))) ->
+			if ctx.com.display = DMPosition then
+				raise (DisplayPosition [cf.cf_pos]);
+			cf.cf_meta <- (Meta.Usage,[],p) :: cf.cf_meta;
 		| TLocal v ->
 			v.v_meta <- (Meta.Usage,[],p) :: v.v_meta;
 		| TTypeExpr mt ->