starscope 1.5.4 → 1.6.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
- SHA1:
3
- metadata.gz: fe59ab1f2e2cf5aaee13db7f085dc708323a3c50
4
- data.tar.gz: 2d32eee21d9bc30996097deb13ac9c6fcb2363cb
2
+ SHA256:
3
+ metadata.gz: d71f7d9d5748e9df63987f08669e56866a5669a7877a5b78bec7274ae6b11e3b
4
+ data.tar.gz: a037cc0b16644f69a37c1d9a00f076a036353cb84cbcaef39e17f864af2c70eb
5
5
  SHA512:
6
- metadata.gz: 21d7d6d5d3cb0eb6b9f7903d54fdc90e1ac9abc34b1e0c6751e3814a664987bea98756a34c7f0d3b1fa08d78f61de9212b1714bfb38bccc48c3dc899ded71814
7
- data.tar.gz: 5da04677144db25e80b40a96db6608f4ac32f1de8e2f7f36904726a7da0b6b1cff67df642df74a43b89419aa0bea9cb6ba731b98f5cd6244eac7917291ca41d5
6
+ metadata.gz: 85d4390356102ec0dfc658fa99bb8816a197f48f990abe56fd5b1df7ac85d3d1ffdd93666ca463ca9c42a362ae81a369cc81fa700c83729a9e73a9ba1e431730
7
+ data.tar.gz: 6cb4cc84d760ba1e5114f2401878e9312eff5e1b7d30ae7b3c4feec10a76c0f87f1f3d00de59417aee8e5e57aa2eb9744ae6a851303b964d9b8edaf8fcec3dad
@@ -0,0 +1,26 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: ['2.6', '2.7', '3.0', '3.1']
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Set up Ruby
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby-version }}
22
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
23
+ - name: Run tests
24
+ run: bundle exec rake test
25
+ - name: Lint
26
+ run: bundle exec rubocop
data/.rubocop.yml CHANGED
@@ -1,10 +1,22 @@
1
+ require:
2
+ - rubocop-minitest
3
+ - rubocop-rake
4
+
1
5
  AllCops:
6
+ NewCops: enable
2
7
  Exclude:
3
- - 'test/fixtures/sample_ruby.rb'
8
+ - test/fixtures/sample_ruby.rb
9
+ - vendor/bundle/**/*
10
+
11
+ Layout/LineLength:
12
+ Max: 120
4
13
 
5
14
  Metrics/AbcSize:
6
15
  Enabled: false
7
16
 
17
+ Metrics/BlockLength:
18
+ Enabled: false
19
+
8
20
  Metrics/BlockNesting:
9
21
  Enabled: false
10
22
 
@@ -14,9 +26,6 @@ Metrics/ClassLength:
14
26
  Metrics/CyclomaticComplexity:
15
27
  Enabled: false
16
28
 
17
- Metrics/LineLength:
18
- Max: 120
19
-
20
29
  Metrics/MethodLength:
21
30
  Enabled: false
22
31
 
@@ -34,3 +43,6 @@ Style/SpecialGlobalVars:
34
43
 
35
44
  Style/FrozenStringLiteralComment:
36
45
  Enabled: false
46
+
47
+ Style/NumericPredicate:
48
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,7 +1,46 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
- v1.5.4 (unreleased)
4
+ v1.6.0 (2022-02-10)
5
+ -------------------
6
+
7
+ Improvements:
8
+ * Support per-directory `.starscope.json` config (#181).
9
+ * Support abbreviated special commands in line mode (e.g. `!u`, `!s`, `!q`).
10
+ * Properly support non-ASCII identifiers in Golang.
11
+ * Tiny performance improvements.
12
+
13
+ Bug Fixes:
14
+ * Strip non-ASCII characters from cscope export to avoid cscope crashes (#182).
15
+
16
+ Misc:
17
+ * Drop support for ancient Marshall-format databases.
18
+ * Drop support for several old Ruby versions. 2.6 is now the oldest supported.
19
+ * Dependency upgrades.
20
+ * Documentation improvements.
21
+
22
+ v1.5.7 (2019-04-04)
23
+ --------------------
24
+
25
+ * Use binary mode for file writes to fix compatibility on MS Windows (#171).
26
+ * Make sure the database is still valid when a parse exception happens (#173).
27
+ * Fix handling of `__ENCODING__` literals in ruby parser (#174).
28
+ * Update some dependencies.
29
+
30
+ v1.5.6 (2018-01-16)
31
+ --------------------
32
+
33
+ * Be more lenient parsing ERB files: accept some of Erubi's expanded syntax.
34
+ * Drop support for ruby 1.9.3.
35
+ * Update some dependencies.
36
+
37
+ v1.5.5 (2017-01-02)
38
+ --------------------
39
+
40
+ Bug Fixes:
41
+ * Hotfix for missing `require` preventing export in v1.5.4.
42
+
43
+ v1.5.4 (2017-01-01)
5
44
  --------------------
6
45
 
7
46
  Improvements:
data/README.md CHANGED
@@ -2,7 +2,7 @@ Starscope
2
2
  =========
3
3
 
4
4
  [![Gem Version](https://img.shields.io/gem/v/starscope.svg)](https://rubygems.org/gems/starscope)
5
- [![Build Status](https://travis-ci.org/eapache/starscope.svg?branch=master)](https://travis-ci.org/eapache/starscope)
5
+ [![Ruby CI](https://github.com/eapache/starscope/actions/workflows/ruby-ci.yml/badge.svg)](https://github.com/eapache/starscope/actions/workflows/ruby-ci.yml)
6
6
  [![Code of Conduct](https://img.shields.io/badge/code%20of%20conduct-active-blue.svg)](https://eapache.github.io/conduct.html)
7
7
 
8
8
  Starscope is a code indexer, search and navigation tool for
@@ -63,5 +63,3 @@ Other Uses
63
63
 
64
64
  - Starscope is a supported backend for
65
65
  [CodeQuery](https://github.com/ruben2020/codequery).
66
- - Starscope has been [packaged for Arch
67
- Linux](https://aur.archlinux.org/packages/ruby-starscope/).
data/Rakefile CHANGED
@@ -6,7 +6,10 @@ Rake::TestTask.new do |t|
6
6
  t.test_files = FileList['test/**/*_test.rb']
7
7
  end
8
8
 
9
- RuboCop::RakeTask.new
9
+ RuboCop::RakeTask.new do |t|
10
+ t.requires << 'rubocop-minitest'
11
+ t.requires << 'rubocop-rake'
12
+ end
10
13
 
11
14
  desc 'Run tests and style checks'
12
- task default: [:test, :rubocop]
15
+ task default: %i[test rubocop]
data/bin/starscope CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- lib = File.expand_path('../../lib', __FILE__)
3
+ lib = File.expand_path('../lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  require 'oj'
@@ -9,7 +9,7 @@ require 'readline'
9
9
  require 'starscope'
10
10
 
11
11
  DEFAULT_DB = '.starscope.db'.freeze
12
- CONFIG_FILE = File.join(Dir.home, '.starscope.json')
12
+ CONFIG_FILE = File.exist?('.starscope.json') ? '.starscope.json' : File.join(Dir.home, '.starscope.json')
13
13
  GLOBAL_CONFIG = File.exist?(CONFIG_FILE) ? Oj.load_file(CONFIG_FILE, symbol_keys: true) : {}
14
14
 
15
15
  options = { read: true,
@@ -17,25 +17,24 @@ options = { read: true,
17
17
  update: true,
18
18
  output: :normal,
19
19
  export: [],
20
- db: DEFAULT_DB
21
- }
20
+ db: DEFAULT_DB }
22
21
 
23
22
  # Options Parsing
24
23
  OptionParser.new do |opts|
25
- opts.banner = <<END
26
- Usage: starscope [options] [PATHS]
24
+ opts.banner = <<~BANNER
25
+ Usage: starscope [options] [PATHS]
27
26
 
28
- The default database is `#{DEFAULT_DB}` if you don't specify one with -f.
29
- The default behaviour is to read and update the database.
30
- If no database exists and no PATHS are specified, Starscope builds a new
31
- database by recursing in the current directory.
27
+ The default database is `#{DEFAULT_DB}` if you don't specify one with -f.
28
+ The default behaviour is to read and update the database.
29
+ If no database exists and no PATHS are specified, Starscope builds a new
30
+ database by recursing in the current directory.
32
31
 
33
- Scoped queries must use `::` as the scope separator, even for languages which
34
- have their own scope syntax.
32
+ Scoped queries must use `::` as the scope separator, even for languages which
33
+ have their own scope syntax.
35
34
 
36
- Website: https://github.com/eapache/starscope
37
- User Manual: https://github.com/eapache/starscope/blob/master/doc/USER_GUIDE.md
38
- END
35
+ Website: https://github.com/eapache/starscope
36
+ User Manual: https://github.com/eapache/starscope/blob/master/doc/USER_GUIDE.md
37
+ BANNER
39
38
 
40
39
  opts.separator "\nQueries"
41
40
  opts.on('-d', '--dump [TABLE]', 'Dumps the DB or specified table to stdout') do |tbl|
@@ -82,32 +81,32 @@ END
82
81
  end
83
82
  opts.on('--verbose', 'Print extra status messages') do
84
83
  if options[:output] == :quiet
85
- $stderr.puts "Can't be both verbose and quiet"
84
+ warn "Can't be both verbose and quiet"
86
85
  exit(1)
87
86
  end
88
87
  options[:output] = :verbose
89
88
  end
90
89
  opts.on('--quiet', 'Print fewer messages') do
91
90
  if options[:output] == :verbose
92
- $stderr.puts "Can't be both verbose and quiet"
91
+ warn "Can't be both verbose and quiet"
93
92
  exit(1)
94
93
  end
95
94
  options[:output] = :quiet
96
95
  end
97
96
 
98
- opts.separator <<END
99
- \nEXPORTING
100
- At the moment two export formats are supported: 'ctags' and 'cscope'. If
101
- you don't specify a path, the output is written to the file '#{Starscope::Exportable::CTAGS_DEFAULT_PATH}' (for
102
- ctags) or '#{Starscope::Exportable::CSCOPE_DEFAULT_PATH}' (for cscope) in the current directory.
103
- END
97
+ opts.separator <<~TAIL
98
+ \nEXPORTING
99
+ At the moment two export formats are supported: 'ctags' and 'cscope'. If
100
+ you don't specify a path, the output is written to the file '#{Starscope::Exportable::CTAGS_DEFAULT_PATH}' (for
101
+ ctags) or '#{Starscope::Exportable::CSCOPE_DEFAULT_PATH}' (for cscope) in the current directory.
102
+ TAIL
104
103
  end.parse!
105
104
 
106
105
  def print_summary(db)
107
106
  tables = db.tables
108
107
  puts 'No tables' if tables.empty?
109
108
  tables.sort.each do |table|
110
- printf("%-9s %6d records\n", table, db.records(table).length)
109
+ printf("%<table>-9s %<length>6d records\n", table: table, length: db.records(table).length)
111
110
  end
112
111
  end
113
112
 
@@ -135,7 +134,7 @@ def run_query(db, query, separator)
135
134
  match = match.join(separator)
136
135
 
137
136
  if match.empty?
138
- $stderr.puts 'Invalid input - no query found.'
137
+ warn 'Invalid input - no query found.'
139
138
  return false
140
139
  end
141
140
  tables = (table == '*' ? db.tables : table.to_sym)
@@ -147,10 +146,10 @@ def run_query(db, query, separator)
147
146
  puts format_record(db, rec)
148
147
  end
149
148
  end
150
- return true
149
+ true
151
150
  rescue Starscope::DB::NoTableError
152
- $stderr.puts "Table '#{table}' doesn't exist."
153
- return false
151
+ warn "Table '#{table}' doesn't exist."
152
+ false
154
153
  end
155
154
 
156
155
  def dump_table(db, table)
@@ -175,22 +174,22 @@ def dump(db, table)
175
174
  when '_files'
176
175
  puts db.metadata(:files).keys
177
176
  when /^_/
178
- puts db.metadata(table[1..-1].to_sym)
177
+ puts db.metadata(table[1..].to_sym)
179
178
  else
180
179
  dump_table(db, table.to_sym)
181
180
  end
182
181
 
183
- return true
182
+ true
184
183
  rescue Starscope::DB::NoTableError
185
- $stderr.puts "Table '#{table}' doesn't exist."
186
- return false
184
+ warn "Table '#{table}' doesn't exist."
185
+ false
187
186
  end
188
187
 
189
188
  def export(db, param)
190
189
  format, path = param.split(',', 2)
191
190
  db.export(format.to_sym, path)
192
191
  rescue Starscope::Exportable::UnknownExportFormatError
193
- $stderr.puts "Unrecognized export format \"#{format}\""
192
+ warn "Unrecognized export format \"#{format}\""
194
193
  end
195
194
 
196
195
  output = Starscope::Output.new(options[:output])
@@ -247,18 +246,19 @@ if options[:dump]
247
246
  end
248
247
 
249
248
  def linemode_help
250
- <<END
251
- Input can be a query of the form 'TABLE QUERY' or a special command starting
252
- with a '!'. Recognized special commands are:
253
- !dump [TABLE]
254
- !export FORMAT[,PATH]
255
- !summary
256
- !update
257
-
258
- !help
259
- !version
260
- !quit
261
- END
249
+ <<~HELP
250
+ Input can be a query of the form 'TABLE QUERY' or a special command starting
251
+ with a '!'. Recognized special commands are:
252
+ !dump [TABLE]
253
+ !export FORMAT[,PATH]
254
+ !summary
255
+ !update
256
+
257
+ !help
258
+ !version
259
+ !quit
260
+ Abbreviations of special commands (e.g `!u` or `!q`) are also recognized.
261
+ HELP
262
262
  end
263
263
 
264
264
  if options[:linemode]
@@ -266,27 +266,28 @@ if options[:linemode]
266
266
  begin
267
267
  while (input = Readline.readline('> ', true))
268
268
  next if input.empty?
269
+
269
270
  cmd, param = input.split(' ', 2)
270
271
  if cmd[0] == '!'
271
- case cmd[1..-1]
272
- when 'dump'
272
+ case cmd[1..]
273
+ when 'dump', 'd'
273
274
  dump(db, param)
274
- when 'export'
275
+ when 'export', 'e', 'ex'
275
276
  if param
276
277
  export(db, param)
277
278
  else
278
279
  puts '!export requires an argument'
279
280
  end
280
- when 'summary'
281
+ when 'summary', 's', 'sum'
281
282
  print_summary(db)
282
- when 'update'
283
+ when 'update', 'u', 'up'
283
284
  changed = db.update
284
285
  db.save(options[:db]) if options[:write] && changed
285
- when 'help'
286
+ when 'help', 'h'
286
287
  puts linemode_help
287
- when 'version'
288
+ when 'version', 'v'
288
289
  puts Starscope::VERSION
289
- when 'quit'
290
+ when 'quit', 'q'
290
291
  exit
291
292
  else
292
293
  puts "Unknown command: '#{input}', try '!help'."
@@ -9,6 +9,14 @@ Already Supported
9
9
  * [JavaScript](https://en.wikipedia.org/wiki/JavaScript)
10
10
  (including ES6/ES7 and JSX via [Babel](https://babeljs.io/))
11
11
 
12
+ External Support
13
+ -----------------
14
+
15
+ Other languages are sometimes supported in third-party plugin files, or forks
16
+ which don't upstream their changes, but I try and list them here. I make no
17
+ warranty that these are still maintained or even work.
18
+ * [Puppet](https://github.com/fihuer/starscope/tree/language/puppet)
19
+
12
20
  How to Add Another Language
13
21
  ---------------------------
14
22
 
data/doc/USER_GUIDE.md CHANGED
@@ -109,14 +109,22 @@ Excluded patterns are also remembered, and can be added at any time. If an
109
109
  existing file in the database matches a newly added exclusion rule, it will be
110
110
  removed.
111
111
 
112
- For commonly excluded files you can create a `~/.starscope.json` file with
113
- contents like:
112
+ Paths to add and exclude are recursive by default. If you need more control, you
113
+ may use any special characters accepted by Ruby's
114
+ [`File::fnmatch`](https://ruby-doc.org/core-2.6.9/File.html#method-c-fnmatch).
115
+
116
+ You can automatically exclude files on a per-directory basis by creating a
117
+ `.starscope.json` file in a given directory with contents like:
114
118
  ```json
115
119
  {
116
- "excludes": ["foo", "bar"]
120
+ "excludes": ["foo", "bar/", "**/*.ext"]
117
121
  }
118
122
  ```
119
- Patterns listed there will be excluded from all starscope databases by default.
123
+
124
+ For commonly excluded files you can create a home directory config file at
125
+ `~/.starscope.json`. Patterns listed there will be excluded from all starscope
126
+ databases by default. Currently `excludes` is the only valid key for
127
+ `.starscope.json` files.
120
128
 
121
129
  Queries
122
130
  -------
@@ -177,6 +185,8 @@ non-line-mode options:
177
185
  * `!version` - same as the `--version` flag
178
186
  * `!quit` - exit line-mode
179
187
 
188
+ Abbreviations of special commands are also recognized (e.g. `!q` for `!quit`,
189
+ `!s` for `!summary`, etc).
180
190
 
181
191
  Miscellaneous
182
192
  -------------
data/lib/starscope/db.rb CHANGED
@@ -17,7 +17,7 @@ module Starscope
17
17
  FRAGMENT = :'!fragment'
18
18
 
19
19
  # dynamically load all our language extractors
20
- Dir.glob("#{File.dirname(__FILE__)}/langs/*.rb").each { |path| require path }
20
+ Dir.glob("#{File.dirname(__FILE__)}/langs/*.rb").sort.each { |path| require path }
21
21
 
22
22
  langs = {}
23
23
  extractors = []
@@ -31,6 +31,7 @@ module Starscope
31
31
 
32
32
  class NoTableError < StandardError; end
33
33
  class UnknownDBFormatError < StandardError; end
34
+ class TooOldDBFormatError < StandardError; end
34
35
 
35
36
  def initialize(output, config = {})
36
37
  @output = output
@@ -56,7 +57,7 @@ module Starscope
56
57
 
57
58
  @meta[:langs].merge!(LANGS)
58
59
 
59
- File.open(filename, 'w') do |file|
60
+ File.open(filename, 'wb') do |file|
60
61
  Zlib::GzipWriter.wrap(file) do |stream|
61
62
  stream.puts DB_FORMAT
62
63
  stream.puts Oj.dump @meta
@@ -84,9 +85,9 @@ module Starscope
84
85
  paths = paths.map { |p| self.class.normalize_glob(p) }
85
86
  @meta[:paths] += paths
86
87
  @meta[:paths].uniq!
87
- files = Dir.glob(paths).select { |f| File.file? f }
88
- files.delete_if { |f| matches_exclude?(f) }
88
+ files = Dir.glob(paths).select { |f| File.file?(f) && !matches_exclude?(f) }
89
89
  return if files.empty?
90
+
90
91
  @output.new_pbar('Building', files.length)
91
92
  add_files(files)
92
93
  @output.finish_pbar
@@ -148,15 +149,13 @@ module Starscope
148
149
  private
149
150
 
150
151
  def open_db(filename)
151
- File.open(filename, 'r') do |file|
152
- begin
153
- Zlib::GzipReader.wrap(file) do |stream|
154
- parse_db(stream)
155
- end
156
- rescue Zlib::GzipFile::Error
157
- file.rewind
158
- parse_db(file)
152
+ File.open(filename, 'rb') do |file|
153
+ Zlib::GzipReader.wrap(file) do |stream|
154
+ parse_db(stream)
159
155
  end
156
+ rescue Zlib::GzipFile::Error
157
+ file.rewind
158
+ parse_db(file)
160
159
  end
161
160
  end
162
161
 
@@ -166,28 +165,26 @@ module Starscope
166
165
  when DB_FORMAT
167
166
  @meta = Oj.load(stream.gets)
168
167
  @tables = Oj.load(stream.gets)
169
- return true
168
+ true
170
169
  when 3..4
171
170
  # Old format, so read the directories segment then rebuild
172
171
  add_paths(Oj.load(stream.gets))
173
- return false
172
+ false
174
173
  when 0..2
175
- # Old format (pre-json), so read the directories segment then rebuild
176
- len = stream.gets.to_i
177
- add_paths(Marshal.load(stream.read(len)))
178
- return false
174
+ raise TooOldDBFormatError
179
175
  else
180
176
  raise UnknownDBFormatError
181
177
  end
182
178
  rescue Oj::ParseError
183
179
  stream.rewind
184
180
  raise unless stream.gets.to_i == DB_FORMAT
181
+
185
182
  # try reading as formated json, which is much slower, but it is sometimes
186
183
  # useful to be able to directly read your db
187
184
  objects = []
188
185
  Oj.load(stream) { |obj| objects << obj }
189
186
  @meta, @tables = objects
190
- return true
187
+ true
191
188
  end
192
189
 
193
190
  def fixup
@@ -233,7 +230,7 @@ module Starscope
233
230
  self.class.extractors.each do |extractor|
234
231
  begin
235
232
  next unless extractor.match_file file
236
- rescue => e
233
+ rescue StandardError => e
237
234
  @output.normal("#{extractor} raised \"#{e}\" while matching #{file}")
238
235
  next
239
236
  end
@@ -271,16 +268,15 @@ module Starscope
271
268
  extract_file(Starscope::FragmentExtractor.new(lang, frags), file, line_cache, lines)
272
269
  @meta[:files][file][:sublangs] << lang
273
270
  end
274
-
271
+ rescue StandardError => e
272
+ @output.normal("#{extractor} raised \"#{e}\" while extracting #{file}")
273
+ ensure
274
+ # metadata must be created for any record that was inserted into a tbl
275
+ # even if there was later a rescued exception
275
276
  @meta[:files][file][:lang] = extractor.name.split('::').last.to_sym
276
277
  @meta[:files][file][:lines] = lines
277
278
 
278
- if extractor_metadata.is_a? Hash
279
- @meta[:files][file] = extractor_metadata.merge!(@meta[:files][file])
280
- end
281
-
282
- rescue => e
283
- @output.normal("#{extractor} raised \"#{e}\" while extracting #{file}")
279
+ @meta[:files][file] = extractor_metadata.merge!(@meta[:files][file]) if extractor_metadata.is_a? Hash
284
280
  end
285
281
 
286
282
  def file_changed(name)
@@ -299,6 +295,7 @@ module Starscope
299
295
  def language_out_of_date(lang)
300
296
  return false unless lang
301
297
  return true unless LANGS[lang]
298
+
302
299
  (@meta[:langs][lang] || 0) < LANGS[lang]
303
300
  end
304
301
 
@@ -332,7 +329,8 @@ module Starscope
332
329
  args
333
330
  end
334
331
 
335
- def extractors # so we can stub it in tests
332
+ # so we can stub it in tests
333
+ def extractors
336
334
  EXTRACTORS
337
335
  end
338
336
  end