Skip to content

Commit

Permalink
documentSymbol: evaluate range on property read
Browse files Browse the repository at this point in the history
This allows us to setup the document outline/tree first, and then have
the ranges computed correctly.
  • Loading branch information
Prince781 committed May 6, 2020
1 parent ff272f6 commit bd64b24
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
3 changes: 0 additions & 3 deletions src/list_symbols.vala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class Vls.ListSymbols : Vala.CodeVisitor {
existing_sym.name = dsym.name;
existing_sym.detail = dsym.detail;
existing_sym.kind = dsym.kind;
existing_sym.range = dsym.range;
return existing_sym;
} else if (existing_sym.kind == Property && dsym.kind == Field)
return existing_sym;
Expand Down Expand Up @@ -89,7 +88,6 @@ class Vls.ListSymbols : Vala.CodeVisitor {
if (current_sym != null) {
// debug (@"adding $(dsym.name) to current_sym $(current_sym.name)");
current_sym.children.add (dsym);
current_sym.range = current_sym.range.union (dsym.range);
} else {
if (sym.parent_symbol is Vala.Namespace
&& sym.parent_symbol.to_string () != "(root namespace)") {
Expand All @@ -100,7 +98,6 @@ class Vls.ListSymbols : Vala.CodeVisitor {
parent_dsym = ns_name_to_dsym [sym.parent_symbol.get_full_name ()];
// debug (@"adding $(dsym.name) to $(parent_dsym.name)");
parent_dsym.children.add (dsym);
parent_dsym.range = parent_dsym.range.union (dsym.range);
} else {
// debug (@"adding $(dsym.name) to top_level_syms");
top_level_syms.add (dsym);
Expand Down
23 changes: 21 additions & 2 deletions src/protocol.vala
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,20 @@ namespace LanguageServer {
}

class DocumentSymbol : Object, Json.Serializable {
private Vala.SourceReference? _source_reference;
public string name { get; set; }
public string? detail { get; set; }
public SymbolKind kind { get; set; }
public bool deprecated { get; set; }
public Range range { get; set; }
private Range? _initial_range;
public Range range {
owned get {
if (_initial_range == null)
_initial_range = new Range.from_sourceref (children.first ()._source_reference);

return children.fold<Range> ((child, current_range) => current_range.union (child.range), _initial_range);
}
}
public Range selectionRange { get; set; }
public Gee.List<DocumentSymbol> children { get; private set; default = new Gee.LinkedList<DocumentSymbol> (); }

Expand All @@ -243,10 +252,20 @@ namespace LanguageServer {
* @param sym the symbol
*/
public DocumentSymbol.from_vala_symbol (Vala.DataType? type, Vala.Symbol sym, SymbolKind kind) {
this._initial_range = new Range.from_sourceref (sym.source_reference);
if (sym is Vala.Subroutine) {
var sub = (Vala.Subroutine) sym;
var body_sref = sub.body != null ? sub.body.source_reference : null;
// debug ("subroutine %s found (body @ %s)", sym.get_full_name (),
// body_sref != null ? body_sref.to_string () : null);
if (body_sref != null && (body_sref.begin.line < body_sref.end.line ||
body_sref.begin.line == body_sref.end.line && body_sref.begin.pos <= body_sref.end.pos)) {
this._initial_range = this._initial_range.union (new Range.from_sourceref (body_sref));
}
}
this.name = sym.name;
this.detail = Vls.CodeHelp.get_symbol_representation (type, sym, null);
this.kind = kind;
this.range = Vls.Server.get_best_range (sym);
this.selectionRange = new Range.from_sourceref (sym.source_reference);
this.deprecated = sym.version.deprecated;
}
Expand Down
12 changes: 0 additions & 12 deletions src/server.vala
Original file line number Diff line number Diff line change
Expand Up @@ -909,18 +909,6 @@ class Vls.Server : Object {
});
}

public static Range get_best_range (Vala.Symbol sym) {
var range = new Range.from_sourceref (sym.source_reference);

if (sym is Vala.Method) {
var m = (Vala.Method) sym;
if (m.body != null && m.body.source_reference != null)
range = range.union (get_best_range (m.body));
}

return range;
}

public LanguageServer.MarkupContent? get_symbol_documentation (Project project, Vala.Symbol sym) {
Vala.Symbol real_sym = find_real_sym (project, sym);
sym = real_sym;
Expand Down

0 comments on commit bd64b24

Please sign in to comment.