starscope 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/bin/starscope.rb +1 -1
- data/lib/starscope/datum.rb +1 -3
- data/lib/starscope/db.rb +11 -3
- data/lib/starscope/langs/ruby.rb +1 -1
- data/lib/starscope/version.rb +1 -1
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/bin/starscope.rb
CHANGED
@@ -35,7 +35,7 @@ END
|
|
35
35
|
opts.on("-n", "--no-auto", "Don't automatically update/create the database") do
|
36
36
|
options[:auto] = false
|
37
37
|
end
|
38
|
-
opts.on("-r", "--read-db
|
38
|
+
opts.on("-r", "--read-db PATH", "Reads the DB from PATH instead of the default") do |path|
|
39
39
|
options[:read] = path
|
40
40
|
end
|
41
41
|
opts.on("-w", "--write-db PATH", "Writes the DB to PATH instead of the default") do |path|
|
data/lib/starscope/datum.rb
CHANGED
@@ -15,10 +15,8 @@ class StarScope::Datum
|
|
15
15
|
fqn[0...-1].reverse.each do |test|
|
16
16
|
if test.to_sym == @scope[i]
|
17
17
|
score += 5
|
18
|
-
elsif Regexp.new(test).match(@scope[i])
|
19
|
-
score += 3
|
20
18
|
elsif Regexp.new(test, Regexp::IGNORECASE).match(@scope[i])
|
21
|
-
score +=
|
19
|
+
score += 2
|
22
20
|
end
|
23
21
|
i -= 1
|
24
22
|
end
|
data/lib/starscope/db.rb
CHANGED
@@ -6,6 +6,8 @@ LANGS = [StarScope::Lang::Ruby]
|
|
6
6
|
|
7
7
|
class StarScope::DB
|
8
8
|
|
9
|
+
DB_FORMAT = 1
|
10
|
+
|
9
11
|
def initialize
|
10
12
|
@dirs = []
|
11
13
|
@files = {}
|
@@ -15,7 +17,7 @@ class StarScope::DB
|
|
15
17
|
def load(file)
|
16
18
|
File.open(file, 'r') do |file|
|
17
19
|
Zlib::GzipReader.wrap(file) do |file|
|
18
|
-
raise "
|
20
|
+
raise "Database format not recognized" if DB_FORMAT != file.gets.to_i
|
19
21
|
@dirs = load_part(file)
|
20
22
|
@files = load_part(file)
|
21
23
|
@tables = load_part(file)
|
@@ -26,7 +28,7 @@ class StarScope::DB
|
|
26
28
|
def save(file)
|
27
29
|
File.open(file, 'w') do |file|
|
28
30
|
Zlib::GzipWriter.wrap(file) do |file|
|
29
|
-
file.puts
|
31
|
+
file.puts DB_FORMAT
|
30
32
|
save_part(file, @dirs)
|
31
33
|
save_part(file, @files)
|
32
34
|
save_part(file, @tables)
|
@@ -73,7 +75,13 @@ class StarScope::DB
|
|
73
75
|
def query(table, value)
|
74
76
|
fqn = value.split("::")
|
75
77
|
results = @tables[table][fqn[-1].to_sym]
|
76
|
-
|
78
|
+
results.sort! {|a,b| b.score_match(fqn) <=> a.score_match(fqn)}
|
79
|
+
best_score = results[0].score_match(fqn)
|
80
|
+
results.each do |result|
|
81
|
+
# 4 is a guess at the best heuristic, not magic
|
82
|
+
return if best_score - result.score_match(fqn) > 4
|
83
|
+
puts result
|
84
|
+
end
|
77
85
|
end
|
78
86
|
|
79
87
|
private
|
data/lib/starscope/langs/ruby.rb
CHANGED
@@ -48,7 +48,7 @@ module StarScope::Lang
|
|
48
48
|
yield :calls, scoped_name(node), node.source_map.expression.line
|
49
49
|
|
50
50
|
if node.children[0].nil? and node.children[1] == :require and node.children[2].type == :str
|
51
|
-
yield :
|
51
|
+
yield :requires, node.children[2].children[0].split("/"), node.source_map.expression.line
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
data/lib/starscope/version.rb
CHANGED