Skip to content

Commit

Permalink
Workaround for GCompareDataFunc target issue (#54)
Browse files Browse the repository at this point in the history
Avoid grabbing an extra reference to Vls.ListSymbols by avoiding the
implicit use of GCompareDataFunc in Gee.TreeMap.
  • Loading branch information
Prince781 committed Mar 21, 2020
1 parent 9a38e6b commit 92770ea
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/find_symbol.vala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Vls.FindSymbol : Vala.CodeVisitor {
return false; // we only want to find symbols, right?
}

if (begin.compare (pos) <= 0 && pos.compare (end) <= 0 && (end_pos == null || end.compare (end_pos) <= 0)) {
if (begin.compare_to (pos) <= 0 && pos.compare_to (end) <= 0 && (end_pos == null || end.compare_to (end_pos) <= 0)) {
debug ("Got node: %s (%s) @ %s", node.type_name, node.to_string (), sr.to_string ());
return true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/list_symbols.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Vls.ListSymbols : Vala.CodeVisitor {
this.file = file;
this.top_level_syms = new Gee.LinkedList<DocumentSymbol> ();
this.containers = new Gee.LinkedList<DocumentSymbol> ();
this.syms_flat = new Gee.TreeMap<Range, DocumentSymbol> ((r1, r2) => r1.start.compare (r2.start));
this.syms_flat = new Gee.TreeMap<Range, DocumentSymbol> ();
this.all_syms = new Gee.LinkedList<DocumentSymbol> ();
this.ns_name_to_dsym = new Gee.HashMap<string, DocumentSymbol> ();

Expand Down
4 changes: 2 additions & 2 deletions src/main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ class Vls.Server : Object {
var node_begin = new Position.from_libvala (node.source_reference.begin);
var node_end = new Position.from_libvala (node.source_reference.end);

if (best_begin.compare (node_begin) <= 0 && node_end.compare (best_end) <= 0 &&
if (best_begin.compare_to (node_begin) <= 0 && node_end.compare_to (best_end) <= 0 &&
!(best.source_reference.begin.column == node.source_reference.begin.column &&
node.source_reference.end.column == best.source_reference.end.column &&
// don't get implicit `this` accesses
Expand Down Expand Up @@ -1824,7 +1824,7 @@ class Vls.Server : Object {
var sr_begin = new Position () { line = sr.begin.line, character = sr.begin.column - 1 };

// don't show local variables that are declared ahead of the cursor
if (sr_begin.compare (fs.pos) > 0)
if (sr_begin.compare_to (fs.pos) > 0)
continue;
completions.add (new CompletionItem.from_symbol (sym,
(sym is Vala.Constant) ? CompletionItemKind.Constant : CompletionItemKind.Variable,
Expand Down
14 changes: 9 additions & 5 deletions src/protocol.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace LanguageServer {
Hint = 4
}

class Position : Object {
class Position : Object, Gee.Comparable<Position> {
/**
* Line position in a document (zero-based).
*/
Expand All @@ -56,7 +56,7 @@ namespace LanguageServer {
*/
public uint character { get; set; default = -1; }

public int compare (Position other) {
public int compare_to (Position other) {
return line > other.line ? 1 :
(line == other.line ?
(character > other.character ? 1 :
Expand Down Expand Up @@ -85,7 +85,7 @@ namespace LanguageServer {
}
}

class Range : Object, Gee.Hashable<Range> {
class Range : Object, Gee.Hashable<Range>, Gee.Comparable<Range> {
/**
* The range's start position.
*/
Expand All @@ -110,13 +110,17 @@ namespace LanguageServer {

public bool equal_to (Range other) { return this.to_string () == other.to_string (); }

public int compare_to (Range other) {
return start.compare_to (other.start);
}

/**
* Return a new range that includes `this` and `other`.
*/
public Range union (Range other) {
return new Range () {
start = start.compare (other.start) < 0 ? start : other.start,
end = end.compare (other.end) < 0 ? other.end : end
start = start.compare_to (other.start) < 0 ? start : other.start,
end = end.compare_to (other.end) < 0 ? other.end : end
};
}
}
Expand Down

0 comments on commit 92770ea

Please sign in to comment.