Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: '>=1.19'
- name: Lint workflow files
run: |
go install github.com/rhysd/actionlint/cmd/actionlint@latest
actionlint .github/workflows/*.yml
# - name: Lint workflow files
# run: |
# go install github.com/rhysd/actionlint/cmd/actionlint@latest
# actionlint .github/workflows/*.yml
29 changes: 28 additions & 1 deletion scip_indexer/SCIPIndexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,30 @@ struct IndexWriter {

using LocalSymbolTable = UnorderedMap<core::LocalVariable, core::Loc>;

bool isSyntheticMethodWithHandwrittenBody(const core::GlobalState &gs, core::NameRef name) {
// The list of names is taken from:
// 1. The test case rewriter/minitest.rb.
// 2. https://ruby-doc.org/stdlib-3.0.1/libdoc/minitest/rdoc/Minitest/Spec/DSL/InstanceMethods.html
// 3. The code in Minitest.cc
// 4. The code in TestCase.cc
if (name == core::NameRef::noName()) {
return false;
}
bool special = name == core::Names::describe() || name == core::Names::it() || name == core::Names::before() ||
name == core::Names::beforeAngles() || name == core::Names::after() ||
name == core::Names::afterAngles() || name == core::Names::testEach() ||
name == core::Names::let() || name == core::Names::test() || name == core::Names::setup() ||
name == core::Names::teardown();
if (special) {
return true;
}
if (name.kind() == core::NameKind::UTF8) {
auto nameText = name.dataUtf8(gs)->utf8;
return absl::StartsWith(nameText, "<it '") || absl::StartsWith(nameText, "<describe ");
}
return false;
}

class SCIPSemanticExtension : public SemanticExtension {
string indexFilePath;
scip_indexer::Config config;
Expand Down Expand Up @@ -1468,7 +1492,10 @@ class SCIPSemanticExtension : public SemanticExtension {
}

// It is not useful to emit occurrences for method bodies that are synthesized.
if (methodDef.flags.isRewriterSynthesized) {
//
// However, some of these methods are synthesized based on code blocks, particularly
// test code. For that code, continue emitting occurrence data.
if (methodDef.flags.isRewriterSynthesized && !isSyntheticMethodWithHandwrittenBody(gs, methodDef.name)) {
return;
}

Expand Down
4 changes: 3 additions & 1 deletion test/scip/testdata/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ def outside_method
end

it "works outside" do
outside_method
x = outside_method
x = x + 1
return
end

it "allows constants inside of IT" do
Expand Down
23 changes: 22 additions & 1 deletion test/scip/testdata/minitest.snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ def outside_method

it "works outside" do
# ^^^^^^^^^^^^^^^ definition [..] MyTest#`<it 'works outside'>`().
outside_method
x = outside_method
# ^ definition local 1~#1914741329
# ^^^^^^^^^^^^^^ reference [..] MyTest#outside_method().
x = x + 1
# ^ reference (write) local 1~#1914741329
# ^ reference local 1~#1914741329
return
end

it "allows constants inside of IT" do
Expand All @@ -16,6 +22,7 @@ def outside_method
# ^^^^^ definition [..] MyTest#CONST.
# ^^^^^^^^^^ reference [..] Kernel#
# ^^^^^^^^^^ reference [..] Kernel#raise().
# ^^^^^^^^^^ reference [..] Module#
end

it "allows let-ed constants inside of IT" do
Expand All @@ -24,6 +31,8 @@ def outside_method
# ^^ definition [..] MyTest#C2.
# ^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Kernel#
# ^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Kernel#raise().
# ^^^^^^^^^^^^^^^^^^^^^^^ reference [..] Module#
# ^^^^^^^ definition local 1~#95163902
# ^^^^^^^ definition local 3~#119448696
# ^^^^^^^ reference [..] Integer#
end
Expand All @@ -36,6 +45,8 @@ def outside_method
# ^^^ reference [..] Mod#
# ^ reference [..] Mod#C#
C3.new
# ^^ reference [..] MyTest#C3.
# ^^^ reference [..] Class#new().
end

describe "some inner tests" do
Expand All @@ -48,7 +59,9 @@ def inside_method
it "works inside" do
# ^^^^^^^^^^^^^^ definition [..] MyTest#`<describe 'some inner tests'>`#`<it 'works inside'>`().
outside_method
# ^^^^^^^^^^^^^^ reference [..] MyTest#outside_method().
inside_method
# ^^^^^^^^^^^^^ reference [..] MyTest#`<describe 'some inner tests'>`#inside_method().
end
end

Expand All @@ -58,13 +71,21 @@ def instance_helper; end
before do
# ^^^^^^ definition [..] MyTest#`<before>`().
@foo = T.let(3, Integer)
# ^^^^ definition [..] MyTest#`@foo`.
# ^^^^^^^ definition local 1~#2938098190
# ^^^^^^^ reference [..] Integer#
instance_helper
# ^^^^^^^^^^^^^^^ reference [..] MyTest#instance_helper().
end

it 'can read foo' do
# ^^^^^^^^^^^^^^ definition [..] MyTest#`<it 'can read foo'>`().
T.assert_type!(@foo, Integer)
# ^^^^ reference [..] MyTest#`@foo`.
# ^^^^^^^ definition local 1~#3909275672
# ^^^^^^^ reference [..] Integer#
instance_helper
# ^^^^^^^^^^^^^^^ reference [..] MyTest#instance_helper().
end

def self.random_method
Expand Down
10 changes: 10 additions & 0 deletions test/scip/testdata/test_case.snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def self.test(*args, &block)
setup do
# ^^^^^ definition [..] MyTest#`<before>`().
@a = T.let(1, Integer)
# ^^ definition [..] MyTest#`@a`.
# ^^^^^^^^^^^^^^^^^^^^^^ reference [..] MyTest#`@a`.
# ^^^^^^^ definition local 1~#2938098190
# ^^^^^^^ reference [..] Integer#
end

test "valid method call" do
Expand Down Expand Up @@ -77,6 +81,10 @@ def assert_equal(a, b); end
setup do
# ^^^^^ definition [..] NoParentClass#`<before>`().
@a = T.let(1, Integer)
# ^^ definition [..] NoParentClass#`@a`.
# ^^^^^^^^^^^^^^^^^^^^^^ reference [..] NoParentClass#`@a`.
# ^^^^^^^ definition local 1~#2938098190
# ^^^^^^^ reference [..] Integer#
end

test "it works" do
Expand All @@ -87,5 +95,7 @@ def assert_equal(a, b); end
teardown do
# ^^^^^^^^ definition [..] NoParentClass#teardown().
@a = 5
# ^^ definition [..] NoParentClass#`@a`.
# ^^^^^^ reference [..] NoParentClass#`@a`.
end
end
Loading