Module: Canopus::Workspace::HierarchyAware
- Defined in:
- lib/canopus/workspace/hierarchy_aware.rb
Constant Summary collapse
- HIERARCHY_ITEM_LIMIT =
1_000- HIERARCHY_TOTAL_LIMIT =
10_000- HIERARCHY_DEPTH_LIMIT =
32- HIERARCHY_REQUEST_LIMIT =
64- HIERARCHY_TEXT_LIMIT =
4_096- HIERARCHY_URI_LIMIT =
16_384- HIERARCHY_ITEM_BYTES_LIMIT =
1 << 20
Instance Method Summary collapse
- #accept_hierarchy_root(palette, index) ⇒ Object
- #hierarchy_tree ⇒ Object
- #invalidate_hierarchy(buffer = nil, client: nil, editor: nil) ⇒ Object
- #show_call_hierarchy(current = editor) ⇒ Object
- #show_hierarchy(kind, current = editor) ⇒ Object
- #show_type_hierarchy(current = editor) ⇒ Object
Instance Method Details
#accept_hierarchy_root(palette, index) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/canopus/workspace/hierarchy_aware.rb', line 54 def accept_hierarchy_root(palette, index) state = palette[:hierarchy] item = index && palette[:items]&.[](index) unless item && hierarchy_context_valid?(state) @message = "Hierarchy context changed; request again" return false end install_hierarchy(state, item) end |
#hierarchy_tree ⇒ Object
16 17 18 19 20 |
# File 'lib/canopus/workspace/hierarchy_aware.rb', line 16 def hierarchy_tree @hierarchy_tree ||= Zaniah::UI::TreeView.new([], height: 320).on_select do |value, _event, _context| select_hierarchy_item(value) end end |
#invalidate_hierarchy(buffer = nil, client: nil, editor: nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/canopus/workspace/hierarchy_aware.rb', line 65 def invalidate_hierarchy(buffer = nil, client: nil, editor: nil) invalidated = false @hierarchy_prepare_requests&.delete_if do |_id, snapshot| matches = (!buffer || snapshot[:buffer].equal?(buffer)) && (!client || snapshot[:client]&.equal?(client)) && (!editor || snapshot[:editor].equal?(editor)) if matches snapshot[:future]&.cancel release_hierarchy_snapshot(snapshot) invalidated = true end matches end candidate = @palette&.dig(:kind) == :hierarchy_roots && @palette[:hierarchy] candidate_matches = candidate && (!buffer || candidate[:buffer].equal?(buffer)) && (!client || candidate[:client]&.equal?(client)) && (!editor || candidate[:editor].equal?(editor)) self.palette = nil if candidate_matches state = @hierarchy_state clear_state = state && (!buffer || state[:buffer].equal?(buffer)) && (!client || state[:client].equal?(client)) && (!editor || state[:editor].equal?(editor)) if clear_state cancel_hierarchy_children(state) @hierarchy_state = nil hierarchy_tree.replace([]) @panels.hide("hierarchy") if @panels.key?("hierarchy") invalidated = true end @hierarchy_generation = @hierarchy_generation.to_i + 1 if invalidated || candidate_matches @window&.request_frame unless @closed nil end |
#show_call_hierarchy(current = editor) ⇒ Object
22 |
# File 'lib/canopus/workspace/hierarchy_aware.rb', line 22 def show_call_hierarchy(current = editor) = show_hierarchy(:call, current) |
#show_hierarchy(kind, current = editor) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/canopus/workspace/hierarchy_aware.rb', line 25 def show_hierarchy(kind, current = editor) raise ArgumentError, "invalid hierarchy kind" unless %i[call type].include?(kind) self.palette = nil invalidate_hierarchy unless current&.buffer&.path @message = "Save the document before requesting a hierarchy" return false end snapshot = hierarchy_snapshot(kind, current) if snapshot[:client] && !snapshot[:capability] release_hierarchy_snapshot(snapshot) @message = "#{hierarchy_title(kind)} is not supported by this language server" return false end requests = @hierarchy_prepare_requests ||= {} id = @hierarchy_prepare_request_id = @hierarchy_prepare_request_id.to_i + 1 requests[id] = snapshot start_hierarchy_prepare(id, snapshot) @message = "Preparing #{hierarchy_title(kind).downcase}…" nil rescue StandardError => error @hierarchy_prepare_requests&.delete_if { |_id, request| request.equal?(snapshot) } release_hierarchy_snapshot(snapshot) if snapshot @message = error. false end |
#show_type_hierarchy(current = editor) ⇒ Object
23 |
# File 'lib/canopus/workspace/hierarchy_aware.rb', line 23 def show_type_hierarchy(current = editor) = show_hierarchy(:type, current) |