Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ranking: standardize ctags kind names before scoring #674

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
64 changes: 64 additions & 0 deletions build/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,16 @@ func TestScoring(t *testing.T) {
t.Fatal(err)
}

examplePython, err := os.ReadFile("./testdata/example.py")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow-up, I'll try to pull in SCIP ctags so we can run the same tests using that binary.

if err != nil {
t.Fatal(err)
}

exampleRuby, err := os.ReadFile("./testdata/example.rb")
if err != nil {
t.Fatal(err)
}

exampleScala, err := os.ReadFile("./testdata/example.scala")
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -1088,6 +1098,60 @@ func Get() {
wantScore: 8110,
},
//
// Python
//
{
fileName: "example.py",
content: examplePython,
query: &query.Substring{Content: true, Pattern: "C1"},
wantLanguage: "Python",
// 7000 (symbol) + 1000 (Python class) + 500 (word) + 10 (file order)
wantScore: 8510,
},
{
fileName: "example.py",
content: examplePython,
query: &query.Substring{Content: true, Pattern: "g"},
wantLanguage: "Python",
// 7000 (symbol) + 800 (Python function) + 500 (word) + 10 (file order)
wantScore: 8310,
},
{
fileName: "example.py",
content: examplePython,
query: &query.Substring{Content: true, Pattern: "__init__"},
wantLanguage: "Python",
// 7000 (symbol) + 400 (Python member) + 50 (partial word) + 10 (file order)
wantScore: 7460,
},
//
// Ruby
//
{
fileName: "example.rb",
content: exampleRuby,
query: &query.Substring{Content: true, Pattern: "Parental"},
wantLanguage: "Ruby",
// 7000 (symbol) + 1000 (Ruby class) + 500 (word) + 10 (file order)
wantScore: 8510,
},
{
fileName: "example.rb",
content: exampleRuby,
query: &query.Substring{Content: true, Pattern: "parental_func"},
wantLanguage: "Ruby",
// 7000 (symbol) + 900 (Ruby method) + 500 (word) + 10 (file order)
wantScore: 8410,
},
{
fileName: "example.rb",
content: exampleRuby,
query: &query.Substring{Content: true, Pattern: "MyModule"},
wantLanguage: "Ruby",
// 7000 (symbol) + 500 (Ruby module) + 500 (word) + 10 (file order)
wantScore: 8210,
},
//
// Scala
//
{
Expand Down
94 changes: 94 additions & 0 deletions build/testdata/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# v py.f def
# v py.f.x def
def f(x):

# v py.f.g def
def g():
y = 5

if True:
# v py.f.x ref
y = x # < "y" py.f.y def
else:
l1 = 3 # < "l1" py.f.l1 def

# v py.f.i def
for i in range(10):
# v py.f.i ref
l2 = i # < "l2" py.f.l2 def

while False:
l3 = 3 # < "l3" py.f.l3 def

try:
l4 = 3 # < "l4" py.f.l4 def
# v py.f.e def
except Exception as e:
l5 = 3 # < "l5" py.f.l5 def
# v py.f.e ref
_ = e

# vvvv py.f.file def
with open("file.txt") as file:
# vvvv py.f.file fef
print(file)

# vvv py.f.lam def
# vvv py.f.lam ref
_ = lambda lam: lam

# v py.f.y ref
# vv py.f.l1 ref
# vv py.f.l2 ref
# vv py.f.l3 ref
# vv py.f.l4 ref
# vv py.f.l5 ref
# v py.f.g ref
_ = y + l1 + l2 + l3 + l4 + l5 + g()

# vvv recursive.foo ref,nodef
recursive = recursive.foo


# vv py.C1 def
class C1:
x = 5 # < "x" py.C1.x def

def __init__(self, y):
# v py.C1.y def
self.y = y

def f(self):
# v py.C1.x ref
# v py.C1.g ref
self.x = self.g()

# v py.C1.g def
def g(self):
# v py.C1.y ref
return self.y


class C2(C1):
y = C1()

def f(self, c1: C1):
c = c1
# v py.C1.g ref
# v py.C1.x ref
return self.g() + c.x


def newC1() -> C1:
return C1()


# v py.C1.x ref
_ = newC1().x

# v py.C1.x ref
# v py.C1.x ref
_ = C1().x + C2().y.x

if False:
f(3) # < "f" py.f ref
77 changes: 77 additions & 0 deletions build/testdata/example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
SOME_CONSTANT = 2.718

if true
a = 1
elsif false
b = 2
else
c = 3
end

(1..5).each do |counter|
z = 3
end

for counter in 1..5
y = 10
end

counter = 1
while counter <= 5 do
no = true
counter += 1
end

begin
raise NoMemoryError, 'Z.'
rescue NoMemoryError => exception_variable
puts 'A', exception_variable
rescue RuntimeError => other_exception_variable
puts 'K'
else
puts 'L'
ensure
puts 'O'
end

grade = 42
case grade
when 0.100
shouldntgetcaptured = true
puts 'you got a grade i guess'
end

module MyModule
def self.abc(base)
end

class MyClass
def yay
end

def self.woo(base)
end
end
end

class Foo
attr_accessor :bar
attr_reader :baz
attr_writer :qux
end

class Aliased
def bar
end

alias_method :baz, :bar
end

class Parental
def parental_func()
end
end

class Composed
include Parental
end
Loading
Loading