Skip to content

Commit 0070514

Browse files
fix: Correctly emit refs for entities in the Opus namespace (#223)
Fixes https://linear.app/sourcegraph/issue/GRAPH-857 ### Motivation I think I added a workaround here originally as it wasn't super clear if the extra entities for `encrypted_prop:` would be useful. But the problem is that the workaround would stop code nav for other things inside the Opus namespace in other contexts. Let's fix the immediate issue for now, I've filed a follow-up issue for synthetic references from rewrites here. https://linear.app/sourcegraph/issue/GRAPH-928
1 parent 189e47e commit 0070514

File tree

4 files changed

+93
-6
lines changed

4 files changed

+93
-6
lines changed

scip_indexer/SCIPSymbolRef.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
#include "common/FileSystem.h"
1414
#include "common/sort/sort.h"
15-
#include "core/source_generator/source_generator.h"
1615
#include "core/Loc.h"
16+
#include "core/source_generator/source_generator.h"
1717
#include "main/lsp/LSPLoop.h"
1818

1919
#include "scip_indexer/Debug.h"
@@ -184,10 +184,6 @@ bool GenericSymbolRef::isSorbetInternal(const core::GlobalState &gs, core::Symbo
184184
if (klass == core::Symbols::Sorbet_Private() || klass == core::Symbols::T() || klass == classT) {
185185
return true;
186186
}
187-
auto name = klass.data(gs)->name;
188-
if (name == core::Names::Constants::Opus()) {
189-
return true;
190-
}
191187
}
192188
visited.insert(sym);
193189
sym = sym.owner(gs);
@@ -228,7 +224,8 @@ void GenericSymbolRef::saveDocStrings(const core::GlobalState &gs, core::TypePtr
228224
auto ref = this->selfOrOwner.asMethodRef();
229225
auto recvType = ref.data(gs)->owner.data(gs)->resultType;
230226
checkType(recvType, fmt::format("receiver type for {}", ref.showFullName(gs)));
231-
markdown = core::source_generator::prettyTypeForMethod(gs, ref, recvType, nullptr, nullptr, core::ShowOptions());
227+
markdown =
228+
core::source_generator::prettyTypeForMethod(gs, ref, recvType, nullptr, nullptr, core::ShowOptions());
232229
// FIXME(varun): For some reason, it looks like a bunch of public methods
233230
// get marked as private here. Avoid printing misleading info until we fix that.
234231
// https://github.com/sourcegraph/scip-ruby/issues/33

test/scip/testdata/encrypted_prop.snapshot.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,23 @@ def self.encrypted_prop(opts={}); end
2828
# ^^^^^^^^^^^^^^ definition [..] `<Class:EncryptedProp>`#encrypted_prop().
2929
encrypted_prop :foo
3030
# ^^^^^^^^^^^^^^^^^^^ reference [..] String#
31+
# ^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#
32+
# ^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#
33+
# ^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#Mixins#
34+
# ^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#Mixins#Encryptable#
35+
# ^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#Mixins#Encryptable#EncryptedValue#
36+
# ^^^^^^^^^^^^^^^^^^^ reference [..] Opus#
3137
# ^^^ definition [..] EncryptedProp#`encrypted_foo=`().
3238
# ^^^ definition [..] EncryptedProp#`foo=`().
3339
# ^^^ definition [..] EncryptedProp#encrypted_foo().
3440
# ^^^ definition [..] EncryptedProp#foo().
3541
encrypted_prop :bar, migrating: true, immutable: true
42+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#Mixins#Encryptable#
43+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#
44+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#
45+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#Mixins#
46+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Opus#
47+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#Mixins#Encryptable#EncryptedValue#
3648
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] String#
3749
# ^^^ definition [..] EncryptedProp#bar().
3850
# ^^^ definition [..] EncryptedProp#encrypted_bar().

test/scip/testdata/opus.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# typed: true
2+
3+
class Opus::Base
4+
end
5+
6+
class Opus::Derived < Opus::Base
7+
end
8+
9+
TYPES = T.let({ derived: -> { Opus::Derived } }, T::Hash[Symbol, T.proc.returns(T.class_of(Opus::Base))])
10+
11+
module ABC
12+
TYPES_IN_MODULE = T.let({ derived: -> { Opus::Derived } }, T::Hash[Symbol, T.proc.returns(T.class_of(Opus::Base))])
13+
end
14+
15+
class Other
16+
TYPES_IN_CLASS = T.let({ derived: -> { Opus::Derived } }, T::Hash[Symbol, T.proc.returns(T.class_of(Opus::Base))])
17+
end

test/scip/testdata/opus.snapshot.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# typed: true
2+
3+
class Opus::Base
4+
# ^^^^ reference [..] Opus#
5+
# ^^^^ definition [..] Opus#Base#
6+
end
7+
8+
class Opus::Derived < Opus::Base
9+
# ^^^^ reference [..] Opus#
10+
# ^^^^^^^ definition [..] Opus#Derived#
11+
# ^^^^ reference [..] Opus#
12+
# ^^^^ reference [..] Opus#Base#
13+
end
14+
15+
TYPES = T.let({ derived: -> { Opus::Derived } }, T::Hash[Symbol, T.proc.returns(T.class_of(Opus::Base))])
16+
#^^^^^ definition [..] TYPES.
17+
# ^^ reference [..] Kernel#
18+
# ^^ reference [..] Kernel#lambda().
19+
# ^^^^ reference [..] Opus#
20+
# ^^^^^^^ reference [..] Opus#Derived#
21+
# ^ reference [..] T#
22+
# ^^^^ reference [..] T#Hash#
23+
# ^^^^^^ reference [..] Symbol#
24+
# ^ reference [..] T#
25+
# ^^^^ reference [..] `<Class:T>`#proc().
26+
# ^ reference [..] T#
27+
# ^^^^^^^^ reference [..] `<Class:T>`#class_of().
28+
# ^^^^ reference [..] Opus#
29+
# ^^^^ reference [..] Opus#Base#
30+
# ^^^^^^^ definition local 4~#119448696
31+
# ^^^^^^^^ reference [..] TYPES.
32+
33+
module ABC
34+
# ^^^ definition [..] ABC#
35+
TYPES_IN_MODULE = T.let({ derived: -> { Opus::Derived } }, T::Hash[Symbol, T.proc.returns(T.class_of(Opus::Base))])
36+
# ^^^^^^^^^^^^^^^ definition [..] ABC#TYPES_IN_MODULE.
37+
# ^^ reference [..] Kernel#
38+
# ^^ reference [..] Kernel#lambda().
39+
# ^^^^ reference [..] Opus#
40+
# ^^^^^^^ reference [..] Opus#Derived#
41+
# ^^^^^^ reference [..] Symbol#
42+
# ^^^^ reference [..] Opus#
43+
# ^^^^ reference [..] Opus#Base#
44+
# ^^^^^^^ definition local 4~#119448696
45+
# ^^^^^^^^ reference [..] ABC#TYPES_IN_MODULE.
46+
end
47+
48+
class Other
49+
# ^^^^^ definition [..] Other#
50+
TYPES_IN_CLASS = T.let({ derived: -> { Opus::Derived } }, T::Hash[Symbol, T.proc.returns(T.class_of(Opus::Base))])
51+
# ^^^^^^^^^^^^^^ definition [..] Other#TYPES_IN_CLASS.
52+
# ^^ reference [..] Kernel#
53+
# ^^ reference [..] Kernel#lambda().
54+
# ^^^^ reference [..] Opus#
55+
# ^^^^^^^ reference [..] Opus#Derived#
56+
# ^^^^^^ reference [..] Symbol#
57+
# ^^^^ reference [..] Opus#
58+
# ^^^^ reference [..] Opus#Base#
59+
# ^^^^^^^ definition local 4~#119448696
60+
# ^^^^^^^^ reference [..] Other#TYPES_IN_CLASS.
61+
end

0 commit comments

Comments
 (0)