}
public class Position : Object, Gee.Comparable<Position> {
+
+ public Position(uint line, uint chr)
+ {
+ this.line = line;
+ this.character = chr;
+ }
/**
* Line position in a document (zero-based).
*/
public uint character { get; set; default = -1; }
public int compare_to (Position other) {
+
return line > other.line ? 1 :
(line == other.line ?
(character > other.character ? 1 :
}
public Position translate (int dl = 0, int dc = 0) {
- return new Position () {
- line = this.line + dl,
- character = this.character + dc
- };
+ return new Position (this.character + dc, this.character + dc) ;
}
}
public class Range : Object, Gee.Hashable<Range>, Gee.Comparable<Range> {
public Range.simple(uint line, uint pos) {
- var p = new Position () {
- line = line,
- character = pos
- };
+ var p = new Position (line,pos);
this.start = p;
this.end = p;
}
public bool contains (Position pos) {
- return start.compare_to (pos) <= 0 && pos.compare_to (end) <= 0;
+
+ var ret = start.compare_to (pos) <= 0 && pos.compare_to (end) <= 0;
+ // GLib.debug( "range contains %d (%d-%d) %s", (int)pos.line, (int)start.line, (int)end.line, ret ? "Y" : "N");
+ return ret;
}
}
return this.kind.sort_key().to_string() + "=" + this.name;
}
}
+
+ public DocumentSymbol? containsLine(uint line, uint chr)
+ {
+ if (!this.range.contains(new Position(line, chr))) {
+ return null;
+ }
+
+ for(var i = 0; i < this.children.get_n_items();i++) {
+ var el = (DocumentSymbol)this.children.get_item(i);
+ var ret = el.containsLine(line,chr);
+ if (ret != null) {
+ return ret;
+ }
+ }
+ return this;
+
+ }
+ public bool equals(DocumentSymbol sym) {
+ return this.name == sym.name && this.kind == sym.kind && sym.range.equals(this.range);
+ }
}