Commit b2c51212 authored by Daniel Espinosa Ortiz's avatar Daniel Espinosa Ortiz

server: added new GDocumentSymbol

It now tracks symbols along the document and its
position, so it is used by SourceView to
highlight source keywords.

Fix #39
parent 56d5572c
/* GVls-gserver.vala
*
* Copyright 2018 Daniel Espinosa <esodan@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
public class GVls.GDocumentSymbol : Object, ListModel, Container, DocumentSymbol, Symbol {
private Symbol _symbol;
private Location _location;
public GDocumentSymbol (Symbol sym, Location loc) {
_symbol = sym;
_location = loc;
}
// DocumentSymbol
public string name { get { return _symbol.name; } }
public string? detail { get { return _symbol.detail; } }
public SymbolKind kind { get { return _symbol.kind; } }
public bool deprecated { get { return _symbol.deprecated; } }
public Range range { get { return _location as Range; } }
public Range selection_range { get { return _location as Range; } }
public Container children { get { return _symbol.children; } }
// Container
public void add (Object object) { _symbol.add (object); }
public void remove (Object object) { _symbol.remove (object); }
public Object? find (Object key) { return _symbol.find (key); }
// ListModel implementation
public Object? get_item (uint position) { return _symbol.get_item (position); }
public Type get_item_type () { return typeof (Symbol); }
public uint get_n_items () { return _symbol.get_n_items (); }
public Object? get_object (uint position) { return get_item (position); }
// Symbol
public Location location { get { return _location; } }
public Package package { get { return _symbol.package; } }
public Documentation documentation { get { return _symbol.documentation; } }
public SymbolKind symbol_kind { get { return _symbol.symbol_kind; } }
public string full_name { owned get { return _symbol.full_name; } }
public string data_type { get { return _symbol.data_type; } }
public Symbol? get_child (string name) { return _symbol.get_child (name); }
public void add_child (Symbol sym) { _symbol.add_child (sym); }
}
......@@ -25,7 +25,6 @@ public class GVls.GKeyword : GVls.GStatement
}
public GKeyword (string name, Location loc) {
_location = loc;
word_location = loc;
_name = name;
}
}
......@@ -188,8 +188,8 @@ public class GVls.GServer : GLib.Object, ContainerHashable, Server
sc.identifier.connect ((loc, n)=>{
var sym = get_symbol (n);
if (sym != null) {
sym.word_location = loc;
l.add (sym);
var ns = new GDocumentSymbol (sym, loc);
l.add (ns);
}
});
try {
......
......@@ -39,7 +39,6 @@ public class GVls.GStatement : Object,
st.source_reference.begin.column,
st.source_reference.end.line,
st.source_reference.end.column);
word_location = _location;
}
// ListModel
public Object? get_item (uint position) {
......@@ -74,7 +73,6 @@ public class GVls.GStatement : Object,
public Container children { get { return _children; } }
// Symbol
public Location location { get { return _location; } }
public Location word_location { get; set; }
public Package package { get { return _package; } }
public Documentation documentation { get { return _documentation; } }
public SymbolKind symbol_kind { get { return symbol_kind; } }
......
......@@ -47,7 +47,6 @@ public class GVls.GSymbol : Gee.AbstractMap<string,GVls.Symbol>,
}
}
public Location location { get { return _location; } }
public Location word_location { get; set; }
public Package package { get { return _package; } }
public Documentation documentation { get { return _documentation; } }
......@@ -111,7 +110,6 @@ public class GVls.GSymbol : Gee.AbstractMap<string,GVls.Symbol>,
} else {
_location = new GLocation ();
}
word_location = _location;
var ns = new Vala.Namespace ("<NoNamespace>");
_package = new GPackage (ns, file);
_documentation = new GDocumentation (sym);
......@@ -461,8 +459,8 @@ public class GVls.GSymbol : Gee.AbstractMap<string,GVls.Symbol>,
public string? detail { get { return null; } }
public SymbolKind kind { get { return symbol_kind; } } // FIXME: duplicated
public bool deprecated { get { return false; } }
public Range range { get { return word_location as Range; } }
public Range selection_range { get { return word_location as Range; } }
public Range range { get { return location as Range; } }
public Range selection_range { get { return location as Range; } }
public Container children { get { return this as Container; } }
}
......@@ -19,7 +19,6 @@
public interface GVls.Symbol : GLib.Object, GLib.ListModel, Container, DocumentSymbol
{
public abstract Location location { get; }
public abstract Location word_location { get; set; }
public abstract Package package { get; }
public abstract Documentation documentation { get; }
public abstract SymbolKind symbol_kind { get; }
......@@ -29,20 +28,20 @@ public interface GVls.Symbol : GLib.Object, GLib.ListModel, Container, DocumentS
public abstract void add_child (Symbol sym);
public virtual bool is_at (Location loc) {
if (word_location.file.get_uri () != loc.file.get_uri ()) {
if (location.file.get_uri () != loc.file.get_uri ()) {
return false;
}
if (word_location.start.line < 0 || word_location.end.line < 0 || word_location.end.character < 0 || word_location.end.line < 0) {
if (location.start.line < 0 || location.end.line < 0 || location.end.character < 0 || location.end.line < 0) {
return false;
}
if (loc.start.line < 0 || loc.end.line < 0 || loc.end.character < 0 || loc.end.line < 0) {
return false;
}
if (loc.start.line != word_location.start.line) {
if (loc.start.line != location.start.line) {
return false;
}
if (loc.start.character < word_location.start.character
|| loc.end.character > word_location.end.character) {
if (loc.start.character < location.start.character
|| loc.end.character > location.end.character) {
return false;
}
return true;
......
......@@ -58,6 +58,7 @@ gvls_sources = [
'gvls-gcontainer.vala',
'gvls-gcontainer-key.vala',
'gvls-gdocumentation.vala',
'gvls-gdocument-symbol.vala',
'gvls-gkeyword.vala',
'gvls-glocation.vala',
'gvls-gpackage.vala',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment