starscope 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2235e7d803ca938cc48e75eee57d14eb6b5b7a9d
4
- data.tar.gz: 20c2ff4775299f5b0fa8b96aa38d260a62a48149
3
+ metadata.gz: 63556d4e16d22bf281211c311fa2ca379b7ec631
4
+ data.tar.gz: c48c940ea99cd383e0aa6f90a19b0cc2f9df6d96
5
5
  SHA512:
6
- metadata.gz: 900973601a54f6383c1b58f2302d5c9f6f37e6333540b4ff36167bff8523038d842bf78f6b2337b518208381e2b395634cf93e429750ec879a1b828b4825ef5e
7
- data.tar.gz: 6570238f423d05dcf5e17f3b133380f2d7e77f542520d7d65e3572062de9f93c87ac8f97350c8b47903a82e881ba0361c19a4358769d9f87ce78311e70a22647
6
+ metadata.gz: ad88485b560c0b4f56aa48c76b7b42451d1e91e9f72ff65689207db6ffc1b85cc2c84966399965f4cdf08489d9f5f771bcefda1bc2f61dd83be38f59564f3346
7
+ data.tar.gz: e03b09376ac960ea2316e5436a9963af358862cebaf51bee7565607bd06b4f60c89df4e5bc5e4802345cd3f7d43f282eac321b853327de8c2ca2959b059dfb8a
data/CHANGELOG.md CHANGED
@@ -1,7 +1,25 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
- v1.1.2 (trunk)
4
+ v1.2.0 (trunk)
5
+ --------------------
6
+
7
+ Improvements:
8
+ * You can now specify `--export` multiple times with different formats in a
9
+ single run.
10
+ * Language extractors are now individually versioned. When an extractor is
11
+ upgraded, files it owns will be automatically re-parsed.
12
+ * Deduplicated some metadata, shrinking database size. This comes with a
13
+ related reduction in read/write time and memory usage.
14
+
15
+ Bug Fixes:
16
+ * Proper handling of golang string literal escapes.
17
+
18
+ Misc:
19
+ * Lots of internal refactoring and test suite improvements for better
20
+ maintainability going forward.
21
+
22
+ v1.1.2 (2014-07-29)
5
23
  --------------------
6
24
 
7
25
  Bug Fixes:
@@ -105,7 +123,7 @@ v0.1.10 (2014-02-24)
105
123
  --------------------
106
124
 
107
125
  Improvements:
108
- * Import new ruby parser version and make necessary changes so that StarScope
126
+ * Import new ruby parser version and make necessary changes so that Starscope
109
127
  now runs on older Ruby versions (1.9.2 and 1.8.7)
110
128
 
111
129
  v0.1.9 (2014-02-22)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- starscope (1.1.2)
4
+ starscope (1.2.0)
5
5
  oj (~> 2.9)
6
6
  parser (~> 2.1)
7
7
  ruby-progressbar (~> 1.5)
@@ -11,8 +11,11 @@ GEM
11
11
  specs:
12
12
  ast (2.0.0)
13
13
  coderay (1.1.0)
14
+ metaclass (0.0.4)
14
15
  method_source (0.8.2)
15
16
  minitest (5.4.0)
17
+ mocha (1.1.0)
18
+ metaclass (~> 0.0.1)
16
19
  oj (2.9.9)
17
20
  parser (2.1.9)
18
21
  ast (>= 1.1, < 3.0)
@@ -31,6 +34,7 @@ PLATFORMS
31
34
  DEPENDENCIES
32
35
  bundler (~> 1.5)
33
36
  minitest
37
+ mocha
34
38
  pry
35
39
  rake
36
40
  starscope!
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- StarScope
1
+ Starscope
2
2
  =========
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/starscope.png)](http://badge.fury.io/rb/starscope)
@@ -8,10 +8,10 @@ Anyone who has done much programming in C (or C++) on a Unix-based OS has come
8
8
  across the fantastic [Cscope](http://cscope.sourceforge.net/) tool. Sadly, it
9
9
  only works for C (and sort of works for C++).
10
10
 
11
- StarScope is a similar tool for [Ruby](https://www.ruby-lang.org/) and
11
+ Starscope is a similar tool for [Ruby](https://www.ruby-lang.org/) and
12
12
  [Golang](http://golang.org/), with a design intended to make it easy to add
13
13
  [support for other languages](doc/LANGUAGE_SUPPORT.md) within the same framework
14
- (thus the name StarScope, i.e. \*scope).
14
+ (thus the name Starscope, i.e. \*scope).
15
15
 
16
16
  Install it as a gem:
17
17
  ```
@@ -29,14 +29,12 @@ Ask it things directly:
29
29
  $ starscope -q calls,new # Lists all callers of new
30
30
  ```
31
31
 
32
- Export it to various formats for use with your editor:
32
+ Export it to various existing formats for automatic integration with your editor:
33
33
  ```
34
34
  $ starscope -e ctags
35
35
  $ starscope -e cscope
36
36
  ```
37
37
 
38
- More flags and options are available, run `starscope --help` for the complete list.
39
-
40
38
  More Documentation
41
39
  ------------------
42
40
 
@@ -48,5 +46,5 @@ More Documentation
48
46
  Other Uses
49
47
  ----------
50
48
 
51
- StarScope is a supported backend for
49
+ Starscope is a supported backend for
52
50
  [CodeQuery](https://github.com/ruben2020/codequery).
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new do |t|
5
- t.test_files = FileList['test/unit/test_*.rb', 'test/functional/test_*.rb']
5
+ t.test_files = FileList['test/**/*_test.rb']
6
6
  end
7
7
 
8
8
  desc 'Run tests'
data/bin/starscope CHANGED
@@ -8,14 +8,13 @@ require 'readline'
8
8
  require 'starscope'
9
9
 
10
10
  DEFAULT_DB='.starscope.db'
11
- DEFAULT_CTAGS='tags'
12
- DEFAULT_CSCOPE='cscope.out'
13
11
 
14
12
  options = {:read => true,
15
13
  :write => true,
16
14
  :update => true,
17
15
  :output => :normal,
18
- :db => DEFAULT_DB
16
+ :export => [],
17
+ :db => DEFAULT_DB,
19
18
  }
20
19
 
21
20
  # Options Parsing
@@ -25,7 +24,7 @@ Usage: starscope [options] [PATHS]
25
24
 
26
25
  The default database is `#{DEFAULT_DB}` if you don't specify one with -f.
27
26
  The default behaviour is to read and update the database.
28
- If no database exists and no PATHS are specified, StarScope builds a new
27
+ If no database exists and no PATHS are specified, Starscope builds a new
29
28
  database by recursing in the current directory.
30
29
 
31
30
  Scoped queries must use `::` as the scope separator, even for languages which
@@ -51,7 +50,7 @@ END
51
50
 
52
51
  opts.separator "\nDatabase Management"
53
52
  opts.on("-e", "--export FORMAT[,PATH]", "Export in FORMAT to PATH, (see EXPORTING)") do |export|
54
- options[:export] = export
53
+ options[:export] << export
55
54
  end
56
55
  opts.on("-f", "--file FILE", "Use FILE instead of `#{DEFAULT_DB}`") do |path|
57
56
  options[:db] = path
@@ -72,7 +71,7 @@ END
72
71
 
73
72
  opts.separator "\nMisc"
74
73
  opts.on("-v", "--version", "Print the version number") do
75
- puts StarScope::VERSION
74
+ puts Starscope::VERSION
76
75
  exit
77
76
  end
78
77
  opts.on("--verbose", "Print extra status messages") do
@@ -93,22 +92,26 @@ END
93
92
  opts.separator <<END
94
93
  \nEXPORTING
95
94
  At the moment two export formats are supported: 'ctags' and 'cscope'. If
96
- you don't specify a path, the output is written to the file '#{DEFAULT_CTAGS}' (for
97
- ctags) or '#{DEFAULT_CSCOPE}' (for cscope) in the current directory.
95
+ you don't specify a path, the output is written to the file '#{Starscope::Export::CTAGS_DEFAULT_PATH}' (for
96
+ ctags) or '#{Starscope::Export::CSCOPE_DEFAULT_PATH}' (for cscope) in the current directory.
98
97
  END
99
98
 
100
99
  end.parse!
101
100
 
102
101
  def print_summary(db)
103
- summary = db.summary
104
- puts "No tables" if summary.empty?
105
- summary.each do |name, count|
106
- printf("%-8s %5d records\n", name, count)
102
+ tables = db.tables
103
+ puts "No tables" if tables.empty?
104
+ tables.sort {|a,b| a.to_s <=> b.to_s}.each do |table|
105
+ printf("%-8s %5d records\n", table, db.records(table).length)
107
106
  end
108
107
  end
109
108
 
109
+ def format_record(db, rec)
110
+ "#{rec[:name].join " "} -- #{rec[:file]}:#{rec[:line_no]} (#{db.line_for_record(rec).strip})"
111
+ end
112
+
110
113
  def run_query(db, table, value)
111
- if not value
114
+ if !value
112
115
  $stderr.puts "Invalid input - no query found."
113
116
  return false
114
117
  end
@@ -117,55 +120,60 @@ def run_query(db, table, value)
117
120
  puts "No results found."
118
121
  else
119
122
  results.sort_by {|x| x[:name].join(' ')}.each do |rec|
120
- puts StarScope::Record.format(rec)
123
+ puts format_record(db, rec)
121
124
  end
122
125
  end
123
126
  return true
124
- rescue StarScope::DB::NoTableError
127
+ rescue Starscope::DB::NoTableError
125
128
  $stderr.puts "Table '#{table}' doesn't exist."
126
129
  return false
127
130
  end
128
131
 
132
+ def dump_table(db, table)
133
+ records = db.records(table).sort {|a,b|
134
+ a[:name][-1].to_s.downcase <=> b[:name][-1].to_s.downcase
135
+ }
136
+
137
+ puts "== Table: #{table} =="
138
+ puts "No records" if records.empty?
139
+
140
+ records.each do |record|
141
+ puts format_record(db, record)
142
+ end
143
+ end
144
+
129
145
  def dump(db, table)
130
- if table.nil?
131
- db.dump_all
132
- elsif table.start_with?('_')
133
- db.dump_meta(table[1..-1].to_sym)
146
+
147
+ case table
148
+ when nil
149
+ db.tables.each {|t| dump_table(db, t)}
150
+ when "_meta"
151
+ puts db.metadata
152
+ when /^_/
153
+ puts db.metadata(table[1..-1].to_sym)
134
154
  else
135
- db.dump_table(table.to_sym)
155
+ dump_table(db, table.to_sym)
136
156
  end
157
+
137
158
  return true
138
- rescue StarScope::DB::NoTableError
159
+ rescue Starscope::DB::NoTableError
139
160
  $stderr.puts "Table '#{table}' doesn't exist."
140
161
  return false
141
162
  end
142
163
 
143
- def export(db, param, output)
164
+ def export(db, param)
144
165
  format, path = param.split(',', 2)
145
-
146
- case format
147
- when 'ctags'; path ||= DEFAULT_CTAGS
148
- when 'cscope'; path ||= DEFAULT_CSCOPE
149
- else
150
- $stderr.puts "Unrecognized export format \"#{format}\""
151
- return
152
- end
153
-
154
- print "Exporting to '#{path}' in format '#{format}'... " unless output == :quiet
155
- File.open(path, 'w') do |file|
156
- case format
157
- when 'ctags'; db.export_ctags(file)
158
- when 'cscope'; db.export_cscope(file)
159
- end
160
- end
161
- puts "done" unless output == :quiet
166
+ db.export(format.to_sym, path)
167
+ rescue Starscope::Export::UnknownExportFormatError
168
+ $stderr.puts "Unrecognized export format \"#{format}\""
162
169
  end
163
170
 
164
- db = StarScope::DB.new(options[:output])
171
+ output = Starscope::Output.new(options[:output])
172
+ db = Starscope::DB.new(output)
165
173
 
166
174
  db_exists = File.exists?(options[:db])
167
175
 
168
- if options[:read] and db_exists
176
+ if options[:read] && db_exists
169
177
  new_data = db.load(options[:db])
170
178
  else
171
179
  # no need to run an update if we didn't read any old data
@@ -177,11 +185,11 @@ if options[:exclude]
177
185
  new_data = true
178
186
  end
179
187
 
180
- if not ARGV.empty?
188
+ if !ARGV.empty?
181
189
  # paths specified, add them
182
190
  db.add_paths(ARGV)
183
191
  new_data = true
184
- elsif not (options[:read] and db_exists)
192
+ elsif !(options[:read] && db_exists)
185
193
  # no paths were specified and the database was not read or did not exist;
186
194
  # default to building a new DB in the current directory
187
195
  db.add_paths(['.'])
@@ -191,9 +199,9 @@ end
191
199
  updated = db.update() if options[:update]
192
200
  new_data ||= updated
193
201
 
194
- db.save(options[:db]) if options[:write] and (new_data or not db_exists)
202
+ db.save(options[:db]) if options[:write] && (new_data || !db_exists)
195
203
 
196
- export(db, options[:export], options[:output]) if options[:export]
204
+ options[:export].each { |target| export(db, target) }
197
205
 
198
206
  if options[:query]
199
207
  table, query = options[:query].split(',', 2)
@@ -237,7 +245,7 @@ if options[:linemode]
237
245
  dump(db, param)
238
246
  when "export"
239
247
  if param
240
- export(db, param, :normal)
248
+ export(db, param)
241
249
  else
242
250
  puts "!export requires an argument"
243
251
  end
@@ -245,11 +253,11 @@ if options[:linemode]
245
253
  print_summary(db)
246
254
  when "update"
247
255
  changed = db.update
248
- db.save(options[:db]) if options[:write] and changed
256
+ db.save(options[:db]) if options[:write] && changed
249
257
  when "help"
250
258
  puts linemode_help
251
259
  when "version"
252
- puts StarScope::VERSION
260
+ puts Starscope::VERSION
253
261
  when "quit"
254
262
  exit
255
263
  else
data/doc/DB_FORMAT.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Database Format
2
2
  ===============
3
3
 
4
- The StarScope database format has gone through a couple of iterations over the
4
+ The Starscope database format has gone through a couple of iterations over the
5
5
  last year, but the current one is pretty nice and I don't see it changing again
6
6
  in the near future. We magically read old formats and convert them, so we only
7
7
  document the current version here.
@@ -17,8 +17,8 @@ compression, the file has three lines:
17
17
  Version Number
18
18
  --------------
19
19
 
20
- This is just the ascii character '5'. If the format changes signficantly, it
21
- will be increased, but that is unlikely.
20
+ This is just the ASCII character '5'. If the format changes significantly, it
21
+ will be incremented, but that is unlikely.
22
22
 
23
23
  Metadata
24
24
  --------
@@ -28,7 +28,7 @@ This is a [JSON](https://en.wikipedia.org/wiki/Json) object. Keys include:
28
28
  * `:excludes` - the paths and patterns to exclude from scanning
29
29
  * `:files` - the files previously scanned (including things like last-modified
30
30
  time)
31
- * `:version` - The StarScope version which wrote the database (not the same as
31
+ * `:version` - The Starscope version which wrote the database (not the same as
32
32
  the database format version).
33
33
 
34
34
  Databases
@@ -20,8 +20,9 @@ For this doc, we're going to pretend to add support for a language called
20
20
  drop the following template in:
21
21
 
22
22
  ```ruby
23
- module StarScope::Lang
23
+ module Starscope::Lang
24
24
  module Mylanguage
25
+ VERSION = 1
25
26
 
26
27
  def self.match_file(name)
27
28
  name.end_with?(".mylang")
@@ -30,13 +31,16 @@ module StarScope::Lang
30
31
  def self.extract(file)
31
32
  # TODO
32
33
  end
33
-
34
34
  end
35
35
  end
36
36
  ```
37
37
 
38
38
  This code is pretty simple: we define a module called
39
- `StarScope::Lang::Mylanguage` and give it two public module methods:
39
+ `Starscope::Lang::Mylanguage` and give it one constant and two public module
40
+ methods:
41
+ * `VERSION` is a constant integer defining the current version of the
42
+ extractor. It should be incremented when the extractor has changed enough
43
+ that any existing files should be re-parsed with the new version.
40
44
  * `match_file` takes the name of the file and returns a boolean if that file is
41
45
  written in MyLanguage or not. This can be as simple as checking the file
42
46
  extension (which the sample code does) or looking for a shell #! line, or
@@ -74,7 +78,7 @@ you want. Some existing ones that you may want to use include:
74
78
  * `col` for the column in the line where the name occurs
75
79
  * `type` for the type of definition (`:func`, `:class`, etc)
76
80
 
77
- And that's it! Parse your files, yield your records, and the StarScope engine
81
+ And that's it! Parse your files, yield your records, and the Starscope engine
78
82
  takes care of everything else for you. If you've added support for a language
79
83
  that you think others might find useful, please contribute it (with tests!) via
80
84
  pull request.
data/doc/USER_GUIDE.md CHANGED
@@ -1,6 +1,17 @@
1
- StarScope User Guide
1
+ Starscope User Guide
2
2
  ====================
3
3
 
4
+ * [About](#about)
5
+ * [Installation](#installation)
6
+ * [Quick Start](#quick-start)
7
+ * [Editor and Workflow Integration](#editor-and-workflow-integration)
8
+ * [Database Options](#database-options)
9
+ * [Paths](#paths)
10
+ * [Queries](#queries)
11
+ * [Exporting](#exporting)
12
+ * [Line-Mode](#line-mode)
13
+ * [Miscellaneous](#miscellaneous)
14
+
4
15
  About
5
16
  -----
6
17
 
@@ -8,15 +19,15 @@ Anyone who has done much programming in C (or C++) on a Unix-based OS has come
8
19
  across the fantastic [Cscope](http://cscope.sourceforge.net/) tool. Sadly, it
9
20
  only works for C (and sort of works for C++).
10
21
 
11
- StarScope is a similar tool for [Ruby](https://www.ruby-lang.org/) and
22
+ Starscope is a similar tool for [Ruby](https://www.ruby-lang.org/) and
12
23
  [Golang](http://golang.org/), with a design intended to make it easy to add
13
- [support for other languages](doc/LANGUAGE_SUPPORT.md) within the same framework
14
- (thus the name StarScope, i.e. \*scope).
24
+ [support for other languages](LANGUAGE_SUPPORT.md) within the same framework
25
+ (thus the name Starscope, i.e. \*scope).
15
26
 
16
27
  Installation
17
28
  ------------
18
29
 
19
- StarScope is a ruby gem available at https://rubygems.org/gems/starscope.
30
+ Starscope is a ruby gem available at https://rubygems.org/gems/starscope.
20
31
  Install it with:
21
32
  ```
22
33
  $ gem install starscope
@@ -38,12 +49,28 @@ Ask it things directly:
38
49
  $ starscope -q calls,new # Lists all callers of new
39
50
  ```
40
51
 
41
- Export it to various formats for use with your editor:
52
+ Export it to various existing formats for automatic integration with your editor:
42
53
  ```
43
54
  $ starscope -e ctags
44
55
  $ starscope -e cscope
45
56
  ```
46
57
 
58
+ Editor and Workflow Integration
59
+ -------------------------------
60
+
61
+ While I don't know of any editors that interface natively with Starscope
62
+ (if you find one, let me know!) there is a much simpler solution. Almost
63
+ all modern editors know how to read Cscope and Ctags files, and Starscope
64
+ can export to both of those file formats. Simply export to the appropriate
65
+ file (see the section on [Exporting](#exporting) below), then use your
66
+ editor's existing integration and it should just work.
67
+
68
+ Many people also like to have this kind of tool automatically run when
69
+ certain events happen, such as a `git commit`. Tim Pope has an excellent
70
+ article on [how to do this with Ctags](http://tbaggery.com/2011/08/08/effortless-ctags-with-git.html)
71
+ and with Starscope it is even simpler. Just place the line
72
+ `starscope --quiet -e cscope &` into the hooks documented by Tim.
73
+
47
74
  Database Options
48
75
  ----------------
49
76
 
@@ -60,9 +87,9 @@ flag.
60
87
  Paths
61
88
  -----
62
89
 
63
- StarScope has powerful options with sane defaults for managing which paths get
90
+ Starscope has powerful options with sane defaults for managing which paths get
64
91
  scanned for files and which do not. By default when creating a new database,
65
- StarScope will scan all files recursively in the current directory. To scan
92
+ Starscope will scan all files recursively in the current directory. To scan
66
93
  specific paths or files instead, pass them as arguments (so `starscope myfolder`
67
94
  would only scan files in `myfolder/`).
68
95
 
@@ -100,7 +127,7 @@ scope separator).
100
127
  Exporting
101
128
  ---------
102
129
 
103
- StarScope can export its database into two other formats for use with
130
+ Starscope can export its database into two other formats for use with
104
131
  third-party tools:
105
132
  * cscope format (default path: `cscope.out`)
106
133
  * ctags format (default path: `tags`)