Skip to content

Commit 62dacba

Browse files
vinistockgraphite-app[bot]
authored andcommitted
Add missing kinds for indexer entries (#3803)
### Motivation Closes #3781 We were missing some possible entries and returning a `nil` kind can cause trouble for editors. ### Implementation I added a fallback with `NULL` and a test that indexes our own codebase and checks that no kinds are `NULL`. This should help us prevent regressions.
1 parent 5a8c717 commit 62dacba

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

lib/ruby_lsp/requests/support/common.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,25 @@ def each_constant_path_part(node, &block)
140140
end
141141
end
142142

143-
#: (RubyIndexer::Entry entry) -> Integer?
143+
#: (RubyIndexer::Entry entry) -> Integer
144144
def kind_for_entry(entry)
145145
case entry
146146
when RubyIndexer::Entry::Class
147147
Constant::SymbolKind::CLASS
148148
when RubyIndexer::Entry::Module
149149
Constant::SymbolKind::NAMESPACE
150-
when RubyIndexer::Entry::Constant
150+
when RubyIndexer::Entry::Constant, RubyIndexer::Entry::UnresolvedConstantAlias, RubyIndexer::Entry::ConstantAlias
151151
Constant::SymbolKind::CONSTANT
152-
when RubyIndexer::Entry::Method
152+
when RubyIndexer::Entry::Method, RubyIndexer::Entry::UnresolvedMethodAlias, RubyIndexer::Entry::MethodAlias
153153
entry.name == "initialize" ? Constant::SymbolKind::CONSTRUCTOR : Constant::SymbolKind::METHOD
154154
when RubyIndexer::Entry::Accessor
155155
Constant::SymbolKind::PROPERTY
156-
when RubyIndexer::Entry::InstanceVariable
156+
when RubyIndexer::Entry::InstanceVariable, RubyIndexer::Entry::ClassVariable
157157
Constant::SymbolKind::FIELD
158+
when RubyIndexer::Entry::GlobalVariable
159+
Constant::SymbolKind::VARIABLE
160+
else
161+
Constant::SymbolKind::NULL
158162
end
159163
end
160164
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# typed: true
2+
# frozen_string_literal: true
3+
4+
require "test_helper"
5+
6+
module RubyLsp
7+
class CommonTest < Minitest::Test
8+
include Requests::Support::Common
9+
10+
def test_kinds_are_defined_for_every_entry
11+
index = RubyIndexer::Index.new
12+
index.index_all
13+
14+
entries = index.instance_variable_get(:@entries).values.flatten
15+
entries.each do |entry|
16+
kind = kind_for_entry(entry)
17+
refute_equal(kind, Constant::SymbolKind::NULL, "Kind not defined for entry: #{entry.inspect}")
18+
end
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)