@@ -117,6 +117,85 @@ local function calls(opts, direction)
117117 end )
118118end
119119
120+ local function type_hierarchy (opts , method , title , item )
121+ lsp .buf_request (opts .bufnr , method , { item = item }, function (err , result )
122+ if err then
123+ utils .notify (" lsp.type_hierarchy" , { msg = title .. " : " .. err .message , level = " ERROR" })
124+ return
125+ end
126+
127+ if not result or vim .tbl_isempty (result ) then
128+ return
129+ end
130+
131+ local locations = {}
132+ for _ , unit in pairs (result ) do
133+ local rng = unit .range
134+ table.insert (locations , {
135+ filename = vim .uri_to_fname (unit .uri ),
136+ text = unit .name ,
137+ lnum = rng .start .line + 1 ,
138+ col = rng .start .character + 1 ,
139+ })
140+ end
141+
142+ pickers
143+ .new (opts , {
144+ prompt_title = title ,
145+ finder = finders .new_table {
146+ results = locations ,
147+ entry_maker = opts .entry_maker or make_entry .gen_from_quickfix (opts ),
148+ },
149+ previewer = conf .qflist_previewer (opts ),
150+ sorter = conf .generic_sorter (opts ),
151+ push_cursor_on_edit = true ,
152+ push_tagstack_on_edit = true ,
153+ })
154+ :find ()
155+ end )
156+ end
157+
158+ local function pick_type_hierarchy_item (type_hierarchy_items )
159+ if not type_hierarchy_items or vim .tbl_isempty (type_hierarchy_items ) then
160+ return
161+ end
162+ if # type_hierarchy_items == 1 then
163+ return type_hierarchy_items [1 ]
164+ end
165+ local items = {}
166+ for i , item in pairs (type_hierarchy_items ) do
167+ local entry = item .detail or item .name
168+ table.insert (items , string.format (" %d. %s" , i , entry ))
169+ end
170+ local choice = vim .fn .inputlist (items )
171+ if choice < 1 or choice > # items then
172+ return
173+ end
174+ return type_hierarchy_items [choice ]
175+ end
176+
177+ --- @param direction ' super' | ' sub'
178+ local function types (opts , direction )
179+ local params = client_position_params ()
180+ lsp .buf_request (opts .bufnr , " textDocument/prepareTypeHierarchy" , params , function (err , result )
181+ if err then
182+ utils .notify (" lsp.types" , { msg = err .message , level = " ERROR" })
183+ return
184+ end
185+
186+ local type_hierarchy_item = pick_type_hierarchy_item (result )
187+ if not type_hierarchy_item then
188+ return
189+ end
190+
191+ if direction == " super" then
192+ type_hierarchy (opts , " typeHierarchy/supertypes" , " LSP Super Types" , type_hierarchy_item )
193+ else
194+ type_hierarchy (opts , " typeHierarchy/subtypes" , " LSP Sub Types" , type_hierarchy_item )
195+ end
196+ end )
197+ end
198+
120199M .incoming_calls = function (opts )
121200 calls (opts , " from" )
122201end
@@ -125,6 +204,14 @@ M.outgoing_calls = function(opts)
125204 calls (opts , " to" )
126205end
127206
207+ M .super_types = function (opts )
208+ types (opts , " super" )
209+ end
210+
211+ M .sub_types = function (opts )
212+ types (opts , " sub" )
213+ end
214+
128215--- @alias telescope.lsp.list_or_jump_action
129216--- | " textDocument/references"
130217--- | " textDocument/definition"
0 commit comments