Forráskód Böngészése

Reference viewer mostly functionnal

Clement Espeute 2 éve
szülő
commit
a73fe8894e
8 módosított fájl, 216 hozzáadás és 98 törlés
  1. 7 0
      bin/cdb.css
  2. 11 0
      bin/cdb.less
  3. 1 0
      hide/Ide.hx
  4. 83 79
      hide/comp/cdb/Editor.hx
  5. 5 1
      hide/comp/cdb/Table.hx
  6. 91 6
      hide/view/CdbTable.hx
  7. 15 12
      hide/view/RefViewer.hx
  8. 3 0
      libs/monaco/ScriptEditor.hx

+ 7 - 0
bin/cdb.css

@@ -4,6 +4,13 @@
 .cdb-view .cdb {
   margin-bottom: 350px;
 }
+.refviewer a {
+  text-decoration: underline;
+  cursor: pointer;
+}
+.refviewer a:hover {
+  color: #4772b3;
+}
 .cdb-view.cdb-diff .cdb-sheet th,
 .cdb-view.cdb-diff th.start {
   background-color: #d60;

+ 11 - 0
bin/cdb.less

@@ -8,6 +8,17 @@
 	margin-bottom: 350px;
 }
 
+.refviewer {
+	a {
+		text-decoration: underline;
+		cursor: pointer;
+
+		&:hover {
+			color: @color-highlight;
+		}
+	}
+}
+
 .cdb-view.cdb-diff {
 	.cdb-sheet th, th.start {
 		background-color: #d60;

+ 1 - 0
hide/Ide.hx

@@ -1369,6 +1369,7 @@ class Ide {
 			if( Type.getClassName(Type.getClass(v)) == ext.component && v.state.path == path ) {
 				if( v.container.tab != null )
 					v.container.parent.parent.setActiveContentItem(v.container.parent);
+				onCreate(v);
 				return;
 			}
 		open(ext.component, { path : path }, onCreate);

+ 83 - 79
hide/comp/cdb/Editor.hx

@@ -3,6 +3,14 @@ package hide.comp.cdb;
 import hxd.Key in K;
 using hide.tools.Extensions;
 
+enum PathPart {
+	Id(idCol:String, name:String, ?targetCol: String);
+	Prop(name: String);
+	Line(lineNo:Int, ?targetCol: String);
+	Script(lineNo:Int);
+}
+
+typedef Path = Array<PathPart>;
 
 enum Direction {
 	Left;
@@ -140,7 +148,7 @@ class Editor extends Component {
 				cursor.update();
 			}
 		});
-		keys.register("cdb.gotoReference", () -> gotoReference(cursor.getCell()));
+		keys.register("cdb.", () -> gotoReference(cursor.getCell()));
 		keys.register("cdb.globalSeek", () -> new GlobalSeek(cdbTable.element, cdbTable));
 
 		base = sheet.base;
@@ -890,73 +898,54 @@ class Editor extends Component {
 		}
 		return id;
 	}
-	public function getReferences(id: String, withCodePaths = true, sheet: cdb.Sheet) {
+	public function getReferences(id: String, withCodePaths = true, sheet: cdb.Sheet) : Array<{str:String, ?goto:Void->Void}> {
 		if( id == null )
 			return [];
 
-		var results = sheet.getReferencesFromId(id);
-		var message = [];
-		if( results != null ) {
-			for( rs in results ) {
-				var path = [];
-				var coords = [];
-				for( i in 0...rs.s.length ) {
-					var s = rs.s[i];
-					var oid = Reflect.field(rs.o.path[i], s.id);
-					var idx = rs.o.indexes[i];
-					if( oid == null || oid == "" )
-						path.push(s.s.name.split("@").pop() + (idx < 0 ? "" : "[" + idx +"]"));
-					else
-						path.push(oid);
-				}
-
-				// Build a path of coordinates in the tables and subtable of the editor for the goto-reference functionality
-				var isSheet = true;
-				var curIdx = 0;
-				while(curIdx < rs.o.indexes.length) {
-					var colNo = 0;
-					var lineNo = 0;
-
-					function findColumnId(sheet: cdb.Sheet, name: String) {
-						var retid = null;
-						for (id => c in sheet.columns) {
-							if (c.name == name) {
-								retid = id;
-								break;
-							}
-						}
-						if (retid == null)
-							throw "wtf";
-
-						return retid;
-					}
-
-					if (isSheet) {
-						// sheets will reference an id, and optionally a column
+		function splitPath(rs: {s:Array<{s:cdb.Sheet, c:String, id:Null<String>}>, o:{path:Array<Dynamic>, indexes:Array<Int>}}) {
+			var path = [];
+			var coords = [];
+			for( i in 0...rs.s.length ) {
+				var s = rs.s[i];
+				var oid = Reflect.field(rs.o.path[i], s.id);
+				var idx = rs.o.indexes[i];
+				if( oid == null || oid == "" )
+					path.push(s.s.name.split("@").pop() + (idx < 0 ? "" : "[" + idx +"]"));
+				else
+					path.push(oid);
+			}
 
-						lineNo = rs.o.indexes[curIdx];
-						var sheet = rs.s[curIdx].s;
-						var columns = sheet.columns;
-						if (curIdx < rs.o.indexes.length) {
-							colNo = findColumnId(sheet, rs.s[curIdx].c);
-							isSheet = rs.s[curIdx].s.columns[colNo].type != TProperties;
-						}
+			var coords = [];
+			var curIdx = 0;
+			while(curIdx < rs.o.indexes.length) {
+				var sheet = rs.s[curIdx];
+				var isSheet = !sheet.s.props.isProps;
+				if (isSheet) {
+					var oid = Reflect.field(rs.o.path[curIdx], sheet.id);
+					var next = sheet.c;
+					if (oid != null) {
+						coords.push(Id(sheet.id, oid, next));
 					}
 					else {
-						// properties will only reference a column, which is then treated as a line in the editor
-						lineNo = findColumnId(rs.s[curIdx].s, rs.s[curIdx].c);
-						isSheet = rs.s[curIdx].s.columns[lineNo].type != TProperties;
+						coords.push(Line(rs.o.indexes[curIdx], next));
 					}
+				}
+				else {
+					coords.push(Prop(rs.s[curIdx].c));
+				}
 
-					curIdx += 1;
+				curIdx += 1;
+			}
 
-					coords.push({line: lineNo, column: colNo});
-				}
+			return {pathNames: path, pathParts: coords};
+		}
 
-				openReference2(rs.s[0].s, coords);
-				return [];
-				//path.push(rs.s[rs.s.length-1].c);
-				//message.push(rs.s[0].s.name+"  "+path.join("."));
+		var results = sheet.getReferencesFromId(id);
+		var message = [];
+		if( results != null ) {
+			for( rs in results ) {
+				var path = splitPath(rs);
+				message.push({str: rs.s[0].s.name+"."+path.pathNames.join("."), goto: () -> openReference2(rs.s[0].s, path.pathParts)});
 			}
 		}
 		if (withCodePaths) {
@@ -984,8 +973,17 @@ class Editor extends Component {
 										if( regall.match(str2) ) trace("Skip "+str);
 										continue;
 									}
-									var rel = ide.makeRelative(fpath);
-									message.push(rel+":"+(line+1));
+									var path = ide.makeRelative(fpath);
+									var fn = function () {
+										ide.openFile(path, function (v) {
+											var scr : hide.view.Script = cast v;
+											haxe.Timer.delay(function() {
+												@:privateAccess scr.script.editor.setPosition({column:0, lineNumber: line+1});
+												haxe.Timer.delay(() ->@:privateAccess scr.script.editor.revealLineInCenter(line+1), 1);
+											}, 1);
+										});
+									}
+									message.push({str: path+":"+(line+1), goto: fn});
 								}
 							}
 						}
@@ -1013,8 +1011,19 @@ class Editor extends Component {
 							var content = sys.io.File.getContent(fpath);
 							if( !scriptStr.match(content) ) continue;
 							for( line => str in content.split("\n") ) {
-								if( scriptStr.match(str) )
-									message.push(ide.makeRelative(fpath)+":"+(line+1));
+								if( scriptStr.match(str) ) {
+									var path = ide.makeRelative(fpath);
+									var fn = function () {
+										ide.openFile(path, function (v) {
+											var scr : hide.view.Script = cast v;
+											haxe.Timer.delay(function() {
+												@:privateAccess scr.script.editor.setPosition({column:0, lineNumber: line+1});
+												haxe.Timer.delay(() ->@:privateAccess scr.script.editor.revealLineInCenter(line+1), 1);
+											}, 1);
+										});
+									}
+									message.push({str: path+":"+(line+1), goto: fn});
+								}
 							}
 						}
 					}
@@ -1050,9 +1059,6 @@ class Editor extends Component {
 								var objs = s.getObjects();
 								var i = 0;
 								for( sheetline => o in objs ) {
-									if (i == 18) {
-										trace("break");
-									}
 									i += 1;
 									var obj = o.path[o.path.length - 1];
 									var content = Reflect.field(obj, c.name);
@@ -1060,12 +1066,9 @@ class Editor extends Component {
 									for( line => str in content.split("\n") ) {
 										if( scriptStr.match(str) )
 										{
-											var idname = sheets[sheets.length-1].id;
-											var refname = Std.string(sheetline);
-											if (idname != null) {
-												refname = Reflect.field(obj, idname);
-											}
-											message.push([for(s in sheets) s.s.name].join("/")+"." + refname + "." + c.name + ":"+(line+1));
+											var res = splitPath({s: sheets, o: o});
+											res.pathParts.push(Script(line));
+											message.push({str: sheets[0].s.name+"."+res.pathNames.join(".") + "." + c.name + ":" + Std.string(line + 1), goto: () -> openReference2(sheets[0].s, res.pathParts)});
 										}
 									}
 								}
@@ -1112,16 +1115,17 @@ class Editor extends Component {
 				default:
 			}
 		}
-		var message = [];
+		var refs = [];
 		if( id != null )
-			message = getReferences(id, sheet);
-		if( message.length == 0 ) {
+			refs = getReferences(id, sheet);
+		if( refs.length == 0 ) {
 			ide.message("No reference found");
 			return;
 		}
-		//ide.open("hide.view.RefViewer", {refs: [], editor: this});
-
-		ide.message(message.join("\n"));
+		ide.open("hide.view.RefViewer", null, function(view) {
+			var refViewer : hide.view.RefViewer = cast view;
+			refViewer.showRefs(refs);
+		});
 	}
 
 	function gotoReference( c : Cell ) {
@@ -1138,8 +1142,8 @@ class Editor extends Component {
 		}
 	}
 
-	function openReference2(rootSheet : cdb.Sheet, coords: Array<{line: Int, column: Int}>, ?scriptLine: Int) {
-		ide.open("hide.view.CdbTable", {}, function(view) Std.downcast(view,hide.view.CdbTable).goto2(rootSheet,coords,scriptLine));
+	function openReference2(rootSheet : cdb.Sheet, path: Path) {
+		ide.open("hide.view.CdbTable", {}, function(view) Std.downcast(view,hide.view.CdbTable).goto2(rootSheet,path));
 	}
 
 	function openReference( s : cdb.Sheet, line : Int, column : Int, ?scriptLine: Int ) {

+ 5 - 1
hide/comp/cdb/Table.hx

@@ -593,6 +593,10 @@ class Table extends Component {
 		return ids.join(":");
 	}
 
+	public function shouldDisplayProp(props: Dynamic, c:cdb.Data.Column) {
+		return !( c.opt && props != null && !Reflect.hasField(props,c.name) && displayMode != AllProperties );
+	}
+
 	function refreshProperties() {
 		lines = [];
 
@@ -603,7 +607,7 @@ class Table extends Component {
 
 			if( c.type.match(TList | TProperties) ) isLarge = true;
 
-			if( c.opt && props != null && !Reflect.hasField(props,c.name) && displayMode != AllProperties ) {
+			if(!shouldDisplayProp(props, c)) {
 				available.push(c);
 				continue;
 			}

+ 91 - 6
hide/view/CdbTable.hx

@@ -24,28 +24,113 @@ class CdbTable extends hide.ui.View<{}> {
 		view = cast this.config.get("cdb.view");
 	}
 
-	public function goto2(rootSheet : cdb.Sheet, coords: Array<{line: Int, column: Int}>, ?scriptLine: Int) {
+	public function goto2(rootSheet : cdb.Sheet, path: hide.comp.cdb.Editor.Path) {
 
 
 		var sheets = [for( s in getSheets() ) s.name];
 		var index = sheets.indexOf(rootSheet.name);
 		if( index < 0 ) return;
-		tabs.currentTab = tabContents[index].parent();
+		if (tabs.currentTab.get(0) != tabContents[index].parent().get(0)) {
+			tabs.currentTab = tabContents[index].parent();
+		}
 		editor.setFilter(null);
 		var curTable = @:privateAccess editor.tables[0];
-		for (i in 0...coords.length) {
+		var lastCell = null;
+		for (i => part in path) {
+			var lineNo = 0;
+			var colNo = 0;
+			switch (part) {
+				case Id(idcol, name, target):
+					for (l in curTable.lines) {
+						if (Reflect.field(l.obj, idcol) == name) {
+							break;
+						}
+						lineNo +=1;
+					}
+					if (target != null) {
+						for (c in curTable.columns) {
+							if (c.name == target) {
+								break;
+							}
+							colNo += 1;
+						}
+					}
+				case Prop(name):
+					var props = curTable.sheet.lines[0];
+					var cols = curTable.columns;
+
+					if (props != null) {
+						for (c in curTable.columns) {
+							if (c.name == name)
+								break;
+							if (curTable.shouldDisplayProp(props, c)) {
+								lineNo += 1;
+							}
+						}
+					}
+				case Line(id):
+					lineNo += 1;
+				case Script(line):
+					var cell = lastCell;
+					if (cell != null) {
+						//cell.open(false);
+						var scr = Std.downcast(cell.line.subTable, hide.comp.cdb.ScriptTable);
+						if (scr != null) {
+							haxe.Timer.delay(function() {
+								@:privateAccess scr.script.editor.setPosition({column:0, lineNumber: line+1});
+								haxe.Timer.delay(() ->@:privateAccess scr.script.editor.revealLineInCenter(line+1), 1);
+							}, 1);
+						}
+					}
+					colNo = -1;
+					lineNo = -1;
+			}
+
+			if (i == path.length-1) {
+				editor.pushCursorState();
+			}
+			trace(i, colNo, lineNo);
+			if (colNo >= 0 && lineNo >= 0) {
+				editor.cursor.set(curTable, colNo, lineNo, i == path.length-1);
+				lastCell = editor.cursor.getCell();
+				if( editor.cursor.table != null) {
+					editor.cursor.table.expandLine(lineNo);
+					if (i < path.length) {
+						var sub = editor.cursor.getLine().subTable;
+						var cell = editor.cursor.getCell();
+						if (sub != null && sub.cell == cell) {
+							curTable = sub;
+						}
+						else {
+							cell.open(false);
+							curTable = editor.cursor.table;
+						}
+					}
+				}
+			}
+
+		}
+		haxe.Timer.delay(editor.focus,1);
+		/*for (i in 0...coords.length) {
 			var c = coords[i];
 			editor.cursor.set(curTable, c.column, c.line);
 			if( editor.cursor.table != null && c.line != null ) {
 				editor.cursor.table.expandLine(c.line);
 				if (i < coords.length - 1) {
-					editor.cursor.getCell().open(false);
-					curTable = editor.cursor.table;
+					var sub = editor.cursor.getLine().subTable;
+					var cell = editor.cursor.getCell();
+					if (sub != null && sub.cell == cell) {
+						curTable = sub;
+					}
+					else {
+						cell.open(false);
+						curTable = editor.cursor.table;
+					}
 				}
 			}
 			else
 				break;
-		}
+		}*/
 
 	}
 

+ 15 - 12
hide/view/RefViewer.hx

@@ -1,21 +1,24 @@
 package hide.view;
 
-enum Info {
-	Script(line: Int);
-	Cell(sheet: cdb.Sheet, line: Int, column : Int, ?scriptLine: Int);
-}
-
-class Data {
-	var refs : Array<Info>;
-}
-
+typedef Data = Array<{str:String, goto:()->Void}>;
 class RefViewer extends hide.ui.View<Data> {
-	public function new(state: Data) {
+
+	public function new(state: Dynamic) {
 		super(state);
 	}
 
-	override function onDisplay() {
-		element.append(new Element("<p> hello worlds ?</p>"));
+	public function showRefs(refs: Data) {
+		element.html("");
+		var div = new Element('<div class="refviewer hide-scroll">').appendTo(element);
+
+		new Element('<p>Number of references : ${refs.length}</p>').appendTo(element);
+		var ul = new Element('<ul>').appendTo(div);
+		for (ref in refs) {
+			var link = new Element('<li><a>${ref.str}</a></li>').appendTo(ul);
+			if (ref.goto != null) {
+				link.click((e) -> ref.goto());
+			}
+		}
 	}
 
 	static var _ = hide.ui.View.register(RefViewer, {position: Bottom, width: 100});

+ 3 - 0
libs/monaco/ScriptEditor.hx

@@ -17,6 +17,9 @@ extern class ScriptEditor {
 	function updateOptions( options : Dynamic ) : Void;
 	function getPosition() : Position;
 	function setPosition( p : Position ) : Void;
+	function revealLine(lineNumber: Int, ?ScrollType: Int) : Void;
+	function revealLineInCenter(lineNumber: Int, ?ScrollType: Int) : Void;
+
 
 	public static function create( elt : js.html.Element, ?options : Dynamic ) : ScriptEditor;