starscope 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- starscope (0.0.1)
4
+ starscope (0.0.3)
5
5
  parser
6
6
 
7
7
  GEM
@@ -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 READ", "Reads the DB from PATH instead of the default") do |path|
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|
@@ -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 += 1
19
+ score += 2
22
20
  end
23
21
  i -= 1
24
22
  end
@@ -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 "File version doesn't match" if StarScope::VERSION != file.gets.chomp
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 StarScope::VERSION
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
- puts results.sort {|a,b| b.score_match(fqn) <=> a.score_match(fqn)}
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
@@ -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 :includes, node.children[2].children[0].split("/"), node.source_map.expression.line
51
+ yield :requires, node.children[2].children[0].split("/"), node.source_map.expression.line
52
52
  end
53
53
  end
54
54
 
@@ -1,3 +1,3 @@
1
1
  module StarScope
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: starscope
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Evan Huus