X-Git-Url: http://git.roojs.org/?p=roobuilder;a=blobdiff_plain;f=src%2FLsp.vala;fp=src%2FLsp.vala;h=1f3a428726a99f7b2b13bf8a22d71c01b5dd80b2;hp=ec896eceaf29de5afaca4e0315ce950196f477a4;hb=193e8a594f01bf44ecc2c541a63a6d0db87738e3;hpb=ee48badb20ee4af798c32c9b02bb5feb75d42beb diff --git a/src/Lsp.vala b/src/Lsp.vala index ec896ecea..1f3a42872 100644 --- a/src/Lsp.vala +++ b/src/Lsp.vala @@ -62,6 +62,12 @@ namespace Lsp { } public class Position : Object, Gee.Comparable { + + public Position(uint line, uint chr) + { + this.line = line; + this.character = chr; + } /** * Line position in a document (zero-based). */ @@ -78,6 +84,7 @@ namespace Lsp { 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 : @@ -101,20 +108,14 @@ namespace Lsp { } 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, Gee.Comparable { 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; @@ -172,7 +173,10 @@ namespace Lsp { } 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; } } @@ -444,6 +448,26 @@ namespace Lsp { 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); + } }