@@ -88,6 +88,27 @@ local jump_to_location = function(opts, result, enc)
8888 return vim .lsp .util .jump_to_location (result , enc )
8989end
9090
91+ local regex_filter_fn = function (regex_filter )
92+ if type (regex_filter ) == " string" then
93+ regex_filter = { regex_filter }
94+ end
95+ if type (regex_filter ) == " function" then
96+ return regex_filter
97+ end
98+ if type (regex_filter ) == " table" and type (regex_filter [1 ]) == " string" then
99+ return function (item , _ )
100+ if not item .text then return true end
101+ local is_match = item .text :match (regex_filter [1 ]) ~= nil
102+ if regex_filter .exclude then
103+ return not is_match
104+ else
105+ return is_match
106+ end
107+ end
108+ end
109+ return false
110+ end
111+
91112local function location_handler (opts , cb , _ , result , ctx , _ )
92113 local encoding = vim .lsp .get_client_by_id (ctx .client_id ).offset_encoding
93114 result = utils .tbl_islist (result ) and result or { result }
@@ -101,12 +122,15 @@ local function location_handler(opts, cb, _, result, ctx, _)
101122 end , result )
102123 end
103124 local items = {}
125+ if opts .regex_filter and opts ._regex_filter_fn == nil then
126+ opts ._regex_filter_fn = regex_filter_fn (opts .regex_filter )
127+ end
104128 -- Although `make_entry.file` filters for `cwd_only` we filter
105129 -- here to accurately determine `jump_to_single_result` (#980)
106130 result = vim .tbl_filter (function (x )
107131 local item = vim .lsp .util .locations_to_items ({ x }, encoding )[1 ]
108132 if (opts .cwd_only and not path .is_relative_to (item .filename , opts .cwd )) or
109- (opts .regex_filter and not item . text : match ( opts . regex_filter )) then
133+ (opts ._regex_filter_fn and not opts . _regex_filter_fn ( item , core . CTX () )) then
110134 return false
111135 end
112136 table.insert (items , item )
@@ -116,9 +140,6 @@ local function location_handler(opts, cb, _, result, ctx, _)
116140 if opts .jump_to_single_result and # result == 1 then
117141 jump_to_location (opts , result [1 ], encoding )
118142 end
119- if opts .filter and type (opts .filter ) == " function" then
120- items = opts .filter (items )
121- end
122143 for _ , entry in ipairs (items ) do
123144 if not opts .current_buffer_only or core .CTX ().bname == entry .filename then
124145 entry = make_entry .lcol (entry , opts )
@@ -193,9 +214,12 @@ local function symbol_handler(opts, cb, _, result, _, _)
193214 else
194215 items = vim .lsp .util .symbols_to_items (result , core .CTX ().bufnr )
195216 end
217+ if opts .regex_filter and opts ._regex_filter_fn == nil then
218+ opts ._regex_filter_fn = regex_filter_fn (opts .regex_filter )
219+ end
196220 for _ , entry in ipairs (items ) do
197221 if (not opts .current_buffer_only or core .CTX ().bname == entry .filename ) and
198- (not opts .regex_filter or entry . text : match ( opts . regex_filter )) then
222+ (not opts ._regex_filter_fn or opts . _regex_filter_fn ( entry , core . CTX () )) then
199223 local mbicon_align = 0
200224 if opts .fn_reload and type (opts .query ) == " string" and # opts .query > 0 then
201225 -- highlight exact matches with `live_workspace_symbols` (#1028)
0 commit comments