Skip to content

Commit 27db85a

Browse files
jeremypwzeebok
andauthored
SymbolPane: improve tooltips for C tags (#1636)
* Override add_tooltip(s) for CtagsSymbolOutline * Look on previous line for method type --------- Co-authored-by: Ryan Kornheisl <[email protected]>
1 parent ac43978 commit 27db85a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/SymbolPane/C/CtagsSymbolOutline.vala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,42 @@ public class Scratch.Services.CtagsSymbolOutline : Scratch.Services.SymbolOutlin
275275
destroy_root (root);
276276
root = new_root;
277277

278+
add_tooltips (store.root);
278279
return false;
279280
});
280281
}
281282

283+
protected override void add_tooltips (Code.Widgets.SourceList.ExpandableItem root) {
284+
foreach (var parent in root.children) {
285+
if (parent is Code.Widgets.SourceList.ExpandableItem) {
286+
add_tooltip ((Code.Widgets.SourceList.ExpandableItem) parent);
287+
}
288+
}
289+
}
290+
291+
private void add_tooltip (Code.Widgets.SourceList.ExpandableItem parent) {
292+
if (parent is CtagsSymbol) {
293+
var item = ((CtagsSymbol)parent);
294+
var start = item.line;
295+
var end = item.line;
296+
// The type of a method is often on the previous line
297+
if (item.symbol_type == SymbolType.METHOD) {
298+
start = start > 0 ? start - 1 : start;
299+
}
300+
301+
item.tooltip = Markup.escape_text ("%s".printf (
302+
doc.get_slice (
303+
start,
304+
0,
305+
end,
306+
0
307+
)
308+
));
309+
}
310+
311+
add_tooltips (parent);
312+
}
313+
282314
private void destroy_root (Code.Widgets.SourceList.ExpandableItem to_destroy) {
283315
var children = iterate_children (to_destroy);
284316
to_destroy.clear ();

0 commit comments

Comments
 (0)