Browse Source

[display] added `this` and `super` to the toplevel completion (fixes #6051) (#6842)

Alexander Kuzmenko 7 years ago
parent
commit
f8c9169db4
2 changed files with 24 additions and 0 deletions
  1. 4 0
      src/context/displayToplevel.ml
  2. 20 0
      tests/display/src/cases/Toplevel.hx

+ 4 - 0
src/context/displayToplevel.ml

@@ -122,6 +122,10 @@ let collect ctx only_types =
 		add (ITLiteral "null");
 		add (ITLiteral "true");
 		add (ITLiteral "false");
+		add (ITLiteral "this");
+		match ctx.curclass.cl_super with
+			| Some _ -> add (ITLiteral "super")
+			| None -> ()
 	end;
 
 	let module_types = ref [] in

+ 20 - 0
tests/display/src/cases/Toplevel.hx

@@ -199,6 +199,26 @@ class Toplevel extends DisplayTestCase {
 		eq(false, hasToplevel(toplevel(pos(1)), "static", "test"));
 	}
 
+	/**
+	class Parent {
+		function parent() {
+			{-1-}
+		}
+	}
+	class Child extends Parent {
+		function child() {
+			{-2-}
+		}
+	}
+	**/
+	function testThisSuper() {
+		eq(true, hasToplevel(toplevel(pos(1)), "literal", "this"));
+		eq(false, hasToplevel(toplevel(pos(1)), "literal", "super"));
+
+		eq(true, hasToplevel(toplevel(pos(2)), "literal", "this"));
+		eq(true, hasToplevel(toplevel(pos(2)), "literal", "super"));
+	}
+
 	public static function hasToplevel(a:Array<ToplevelElement>, kind:String, name:String):Bool {
 		return a.exists(function(t) return t.kind == kind && t.name == name);
 	}