@@ -4,6 +4,71 @@ local fs = require("peekstack.util.fs")
44
55local M = {}
66
7+ --- @param chunks table
8+ --- @param path string
9+ --- @param dir_hl ? string
10+ --- @param file_hl ? string
11+ function M .append_path_chunks (chunks , path , dir_hl , file_hl )
12+ local file_group = file_hl or " Directory"
13+ local dir , base = path :match (" ^(.*[/\\ ])(.+)$" )
14+ if dir and base then
15+ if type (dir_hl ) == " string" and dir_hl ~= " " then
16+ chunks [# chunks + 1 ] = { dir , dir_hl }
17+ else
18+ chunks [# chunks + 1 ] = { dir , file_group }
19+ end
20+ chunks [# chunks + 1 ] = { base , file_group }
21+ return
22+ end
23+ chunks [# chunks + 1 ] = { path , file_group }
24+ end
25+
26+ --- @param text ? string
27+ --- @return string
28+ local function normalize_label_text (text )
29+ if type (text ) ~= " string" then
30+ return " "
31+ end
32+ local normalized = text :gsub (" [\r\n\t ]+" , " " ):gsub (" %s+" , " " )
33+ return vim .trim (normalized )
34+ end
35+
36+ --- @param suffix string
37+ --- @return string , integer , integer
38+ local function parse_suffix_location (suffix )
39+ local path , line , col = suffix :match (" ^(.*):(%d+):(%d+)$" )
40+ if not path then
41+ return suffix , 0 , 0
42+ end
43+ return path , tonumber (line ) or 0 , tonumber (col ) or 0
44+ end
45+
46+ --- @param loc PeekstackLocation
47+ --- @param preview_lines integer
48+ --- @param opts PeekstackDisplayTextOpts
49+ --- @return { label : string , symbol : string , path : string , display_lnum : integer , display_col : integer }
50+ local function build_location_label_payload (loc , preview_lines , opts )
51+ local suffix = location .display_text (loc , 0 , opts )
52+ local path , display_lnum , display_col = parse_suffix_location (suffix )
53+ local symbol = preview_lines > 0 and normalize_label_text (loc .text ) or " "
54+ if symbol == " " then
55+ return {
56+ label = suffix ,
57+ symbol = " " ,
58+ path = path ,
59+ display_lnum = display_lnum ,
60+ display_col = display_col ,
61+ }
62+ end
63+ return {
64+ label = string.format (" %s - %s" , symbol , suffix ),
65+ symbol = symbol ,
66+ path = path ,
67+ display_lnum = display_lnum ,
68+ display_col = display_col ,
69+ }
70+ end
71+
772--- @return PeekstackDisplayTextOpts
873local function display_text_opts ()
974 local ui_path = config .get ().ui .path or {}
@@ -24,8 +89,9 @@ function M.build_items(locations, preview_lines)
2489 local opts = display_text_opts ()
2590 local items = {}
2691 for _ , loc in ipairs (locations ) do
92+ local payload = build_location_label_payload (loc , preview_lines , opts )
2793 table.insert (items , {
28- label = location . display_text ( loc , preview_lines , opts ) ,
94+ label = payload . label ,
2995 value = loc ,
3096 })
3197 end
@@ -40,8 +106,13 @@ function M.build_external_items(locations, preview_lines)
40106 local items = {}
41107 for _ , loc in ipairs (locations ) do
42108 local start = loc .range and loc .range .start or {}
109+ local payload = build_location_label_payload (loc , preview_lines , opts )
43110 table.insert (items , {
44- label = location .display_text (loc , preview_lines , opts ),
111+ label = payload .label ,
112+ symbol = payload .symbol ,
113+ path = payload .path ,
114+ display_lnum = payload .display_lnum ,
115+ display_col = payload .display_col ,
45116 value = loc ,
46117 file = fs .uri_to_fname (loc .uri ),
47118 lnum = (start .line or 0 ) + 1 ,
0 commit comments