From 2c81298b8ed09bbe6e75a5656370cfd19c723833 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Tue, 1 Oct 2024 10:20:02 +0800 Subject: [PATCH 1/2] test: Add negative test for Opus references being missed --- test/scip/testdata/opus.rb | 17 +++++++++ test/scip/testdata/opus.snapshot.rb | 53 +++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 test/scip/testdata/opus.rb create mode 100644 test/scip/testdata/opus.snapshot.rb diff --git a/test/scip/testdata/opus.rb b/test/scip/testdata/opus.rb new file mode 100644 index 000000000..4460e0ca0 --- /dev/null +++ b/test/scip/testdata/opus.rb @@ -0,0 +1,17 @@ +# typed: true + +class Opus::Base +end + +class Opus::Derived < Opus::Base +end + +TYPES = T.let({ derived: -> { Opus::Derived } }, T::Hash[Symbol, T.proc.returns(T.class_of(Opus::Base))]) + +module ABC + TYPES_IN_MODULE = T.let({ derived: -> { Opus::Derived } }, T::Hash[Symbol, T.proc.returns(T.class_of(Opus::Base))]) +end + +class Other + TYPES_IN_CLASS = T.let({ derived: -> { Opus::Derived } }, T::Hash[Symbol, T.proc.returns(T.class_of(Opus::Base))]) +end diff --git a/test/scip/testdata/opus.snapshot.rb b/test/scip/testdata/opus.snapshot.rb new file mode 100644 index 000000000..11b674c43 --- /dev/null +++ b/test/scip/testdata/opus.snapshot.rb @@ -0,0 +1,53 @@ + # typed: true + + class Opus::Base +# ^^^^ reference [..] Opus# +# ^^^^ definition [..] Opus#Base# + end + + class Opus::Derived < Opus::Base +# ^^^^ reference [..] Opus# +# ^^^^^^^ definition [..] Opus#Derived# +# ^^^^ reference [..] Opus# +# ^^^^ reference [..] Opus#Base# + end + + TYPES = T.let({ derived: -> { Opus::Derived } }, T::Hash[Symbol, T.proc.returns(T.class_of(Opus::Base))]) +#^^^^^ definition [..] TYPES. +# ^^ reference [..] Kernel# +# ^^ reference [..] Kernel#lambda(). +# ^^^^ reference [..] Opus# +# ^^^^^^^ reference [..] Opus#Derived# +# ^ reference [..] T# +# ^^^^ reference [..] T#Hash# +# ^^^^^^ reference [..] Symbol# +# ^ reference [..] T# +# ^^^^ reference [..] ``#proc(). +# ^ reference [..] T# +# ^^^^^^^^ reference [..] ``#class_of(). +# ^^^^ reference [..] Opus# +# ^^^^ reference [..] Opus#Base# +# ^^^^^^^ definition local 4~#119448696 +# ^^^^^^^^ reference [..] TYPES. + + module ABC +# ^^^ definition [..] ABC# + TYPES_IN_MODULE = T.let({ derived: -> { Opus::Derived } }, T::Hash[Symbol, T.proc.returns(T.class_of(Opus::Base))]) +# ^^^^^^^^^^^^^^^ definition [..] ABC#TYPES_IN_MODULE. +# ^^ reference [..] Kernel# +# ^^ reference [..] Kernel#lambda(). +# ^^^^^^ reference [..] Symbol# +# ^^^^^^^ definition local 4~#119448696 +# ^^^^^^^^ reference [..] ABC#TYPES_IN_MODULE. + end + + class Other +# ^^^^^ definition [..] Other# + TYPES_IN_CLASS = T.let({ derived: -> { Opus::Derived } }, T::Hash[Symbol, T.proc.returns(T.class_of(Opus::Base))]) +# ^^^^^^^^^^^^^^ definition [..] Other#TYPES_IN_CLASS. +# ^^ reference [..] Kernel# +# ^^ reference [..] Kernel#lambda(). +# ^^^^^^ reference [..] Symbol# +# ^^^^^^^ definition local 4~#119448696 +# ^^^^^^^^ reference [..] Other#TYPES_IN_CLASS. + end From a839dce1d3a12a34532325fa4b46d71bdcf96284 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Tue, 1 Oct 2024 10:37:48 +0800 Subject: [PATCH 2/2] fix: Correctly emit refs for entities in the Opus namespace --- scip_indexer/SCIPSymbolRef.cc | 9 +++------ test/scip/testdata/encrypted_prop.snapshot.rb | 12 ++++++++++++ test/scip/testdata/opus.snapshot.rb | 8 ++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/scip_indexer/SCIPSymbolRef.cc b/scip_indexer/SCIPSymbolRef.cc index 4c5876227..4eea37f50 100644 --- a/scip_indexer/SCIPSymbolRef.cc +++ b/scip_indexer/SCIPSymbolRef.cc @@ -12,8 +12,8 @@ #include "common/FileSystem.h" #include "common/sort/sort.h" -#include "core/source_generator/source_generator.h" #include "core/Loc.h" +#include "core/source_generator/source_generator.h" #include "main/lsp/LSPLoop.h" #include "scip_indexer/Debug.h" @@ -184,10 +184,6 @@ bool GenericSymbolRef::isSorbetInternal(const core::GlobalState &gs, core::Symbo if (klass == core::Symbols::Sorbet_Private() || klass == core::Symbols::T() || klass == classT) { return true; } - auto name = klass.data(gs)->name; - if (name == core::Names::Constants::Opus()) { - return true; - } } visited.insert(sym); sym = sym.owner(gs); @@ -228,7 +224,8 @@ void GenericSymbolRef::saveDocStrings(const core::GlobalState &gs, core::TypePtr auto ref = this->selfOrOwner.asMethodRef(); auto recvType = ref.data(gs)->owner.data(gs)->resultType; checkType(recvType, fmt::format("receiver type for {}", ref.showFullName(gs))); - markdown = core::source_generator::prettyTypeForMethod(gs, ref, recvType, nullptr, nullptr, core::ShowOptions()); + markdown = + core::source_generator::prettyTypeForMethod(gs, ref, recvType, nullptr, nullptr, core::ShowOptions()); // FIXME(varun): For some reason, it looks like a bunch of public methods // get marked as private here. Avoid printing misleading info until we fix that. // https://github.com/sourcegraph/scip-ruby/issues/33 diff --git a/test/scip/testdata/encrypted_prop.snapshot.rb b/test/scip/testdata/encrypted_prop.snapshot.rb index c14889009..e74c21015 100644 --- a/test/scip/testdata/encrypted_prop.snapshot.rb +++ b/test/scip/testdata/encrypted_prop.snapshot.rb @@ -28,11 +28,23 @@ def self.encrypted_prop(opts={}); end # ^^^^^^^^^^^^^^ definition [..] ``#encrypted_prop(). encrypted_prop :foo # ^^^^^^^^^^^^^^^^^^^ reference [..] String# +# ^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB# +# ^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model# +# ^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#Mixins# +# ^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#Mixins#Encryptable# +# ^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#Mixins#Encryptable#EncryptedValue# +# ^^^^^^^^^^^^^^^^^^^ reference [..] Opus# # ^^^ definition [..] EncryptedProp#`encrypted_foo=`(). # ^^^ definition [..] EncryptedProp#`foo=`(). # ^^^ definition [..] EncryptedProp#encrypted_foo(). # ^^^ definition [..] EncryptedProp#foo(). encrypted_prop :bar, migrating: true, immutable: true +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#Mixins#Encryptable# +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB# +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model# +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#Mixins# +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Opus# +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Opus#DB#Model#Mixins#Encryptable#EncryptedValue# # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] String# # ^^^ definition [..] EncryptedProp#bar(). # ^^^ definition [..] EncryptedProp#encrypted_bar(). diff --git a/test/scip/testdata/opus.snapshot.rb b/test/scip/testdata/opus.snapshot.rb index 11b674c43..006872545 100644 --- a/test/scip/testdata/opus.snapshot.rb +++ b/test/scip/testdata/opus.snapshot.rb @@ -36,7 +36,11 @@ module ABC # ^^^^^^^^^^^^^^^ definition [..] ABC#TYPES_IN_MODULE. # ^^ reference [..] Kernel# # ^^ reference [..] Kernel#lambda(). +# ^^^^ reference [..] Opus# +# ^^^^^^^ reference [..] Opus#Derived# # ^^^^^^ reference [..] Symbol# +# ^^^^ reference [..] Opus# +# ^^^^ reference [..] Opus#Base# # ^^^^^^^ definition local 4~#119448696 # ^^^^^^^^ reference [..] ABC#TYPES_IN_MODULE. end @@ -47,7 +51,11 @@ class Other # ^^^^^^^^^^^^^^ definition [..] Other#TYPES_IN_CLASS. # ^^ reference [..] Kernel# # ^^ reference [..] Kernel#lambda(). +# ^^^^ reference [..] Opus# +# ^^^^^^^ reference [..] Opus#Derived# # ^^^^^^ reference [..] Symbol# +# ^^^^ reference [..] Opus# +# ^^^^ reference [..] Opus#Base# # ^^^^^^^ definition local 4~#119448696 # ^^^^^^^^ reference [..] Other#TYPES_IN_CLASS. end