starscope 1.5.6 → 1.6.1

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: a672745a78f09d23b3777f8f11ca3725f673afe6
4
- data.tar.gz: 7ec09bdfae0344c549d6c145d10dfc6593bf6bfc
2
+ SHA256:
3
+ metadata.gz: b664cd1fd9107436e9a2bf94a21c00249ed8970b905b34c8649eba4cca7336c7
4
+ data.tar.gz: 39aa4d99d25f820db321b1c5b58d9e8662ed45812a8636c047df52f25a9d38b1
5
5
  SHA512:
6
- metadata.gz: 7026d21cc7c2c1be4755db9f6b4c5ab93cbed8073c31b417d39dc9d8ffdf8bb2c028cb5d999cff4185795a86c19fedc7d0a45ecadd9bbb1d14effbce1265ada1
7
- data.tar.gz: 2fe2786def57bbbae6e24d4baeee414dc971a7c6b07e0b7f1b0ed56e5db03f723da28b9023bc245ff810e4ce5c7f812144e466c2476cfc1c6a0807b32bb27450
6
+ metadata.gz: 1fb43999baa94336ac2265045f0e7a06e18070d2199489bdc489155bc9baf03b9541922c8a9791b6d3a9578cda6cd2a75d20076a73b86d0d9481d2ae9659da05
7
+ data.tar.gz: a9ee933fffe03daf2b50f017499b188da833305da02012283823c771c5daa10e7c9a293486925f30afde29342e192a5bfbd1606ced1c8f20e848741eac839f27
@@ -0,0 +1,26 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
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/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  *.rbc
3
3
  .starscope.db
4
4
  .bundle
5
+ .byebug_history
5
6
  .config
6
7
  Gemfile.lock
7
8
  coverage
data/.rubocop.yml CHANGED
@@ -1,6 +1,15 @@
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
@@ -17,9 +26,6 @@ Metrics/ClassLength:
17
26
  Metrics/CyclomaticComplexity:
18
27
  Enabled: false
19
28
 
20
- Metrics/LineLength:
21
- Max: 120
22
-
23
29
  Metrics/MethodLength:
24
30
  Enabled: false
25
31
 
data/CHANGELOG.md CHANGED
@@ -1,6 +1,41 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ v1.6.1 (2022-08-07)
5
+ -------------------
6
+
7
+ * Support for extracting javascript blocks from vue files.
8
+ * Print a newline when exiting from line-mode via interrupt.
9
+ * Support for Ruby 3.x "def foo = ..." method syntax (#192).
10
+ * Don't generate conflicting `read` and `defs` entries for class and module
11
+ definitions (#176).
12
+
13
+ v1.6.0 (2022-02-10)
14
+ -------------------
15
+
16
+ Improvements:
17
+ * Support per-directory `.starscope.json` config (#181).
18
+ * Support abbreviated special commands in line mode (e.g. `!u`, `!s`, `!q`).
19
+ * Properly support non-ASCII identifiers in Golang.
20
+ * Tiny performance improvements.
21
+
22
+ Bug Fixes:
23
+ * Strip non-ASCII characters from cscope export to avoid cscope crashes (#182).
24
+
25
+ Misc:
26
+ * Drop support for ancient Marshall-format databases.
27
+ * Drop support for several old Ruby versions. 2.6 is now the oldest supported.
28
+ * Dependency upgrades.
29
+ * Documentation improvements.
30
+
31
+ v1.5.7 (2019-04-04)
32
+ --------------------
33
+
34
+ * Use binary mode for file writes to fix compatibility on MS Windows (#171).
35
+ * Make sure the database is still valid when a parse exception happens (#173).
36
+ * Fix handling of `__ENCODING__` literals in ruby parser (#174).
37
+ * Update some dependencies.
38
+
4
39
  v1.5.6 (2018-01-16)
5
40
  --------------------
6
41
 
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,
@@ -21,20 +21,20 @@ options = { read: true,
21
21
 
22
22
  # Options Parsing
23
23
  OptionParser.new do |opts|
24
- opts.banner = <<END
25
- Usage: starscope [options] [PATHS]
24
+ opts.banner = <<~BANNER
25
+ Usage: starscope [options] [PATHS]
26
26
 
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.
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.
31
31
 
32
- Scoped queries must use `::` as the scope separator, even for languages which
33
- have their own scope syntax.
32
+ Scoped queries must use `::` as the scope separator, even for languages which
33
+ have their own scope syntax.
34
34
 
35
- Website: https://github.com/eapache/starscope
36
- User Manual: https://github.com/eapache/starscope/blob/master/doc/USER_GUIDE.md
37
- END
35
+ Website: https://github.com/eapache/starscope
36
+ User Manual: https://github.com/eapache/starscope/blob/master/doc/USER_GUIDE.md
37
+ BANNER
38
38
 
39
39
  opts.separator "\nQueries"
40
40
  opts.on('-d', '--dump [TABLE]', 'Dumps the DB or specified table to stdout') do |tbl|
@@ -81,32 +81,32 @@ END
81
81
  end
82
82
  opts.on('--verbose', 'Print extra status messages') do
83
83
  if options[:output] == :quiet
84
- $stderr.puts "Can't be both verbose and quiet"
84
+ warn "Can't be both verbose and quiet"
85
85
  exit(1)
86
86
  end
87
87
  options[:output] = :verbose
88
88
  end
89
89
  opts.on('--quiet', 'Print fewer messages') do
90
90
  if options[:output] == :verbose
91
- $stderr.puts "Can't be both verbose and quiet"
91
+ warn "Can't be both verbose and quiet"
92
92
  exit(1)
93
93
  end
94
94
  options[:output] = :quiet
95
95
  end
96
96
 
97
- opts.separator <<END
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
- 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
103
103
  end.parse!
104
104
 
105
105
  def print_summary(db)
106
106
  tables = db.tables
107
107
  puts 'No tables' if tables.empty?
108
108
  tables.sort.each do |table|
109
- 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)
110
110
  end
111
111
  end
112
112
 
@@ -134,7 +134,7 @@ def run_query(db, query, separator)
134
134
  match = match.join(separator)
135
135
 
136
136
  if match.empty?
137
- $stderr.puts 'Invalid input - no query found.'
137
+ warn 'Invalid input - no query found.'
138
138
  return false
139
139
  end
140
140
  tables = (table == '*' ? db.tables : table.to_sym)
@@ -146,10 +146,10 @@ def run_query(db, query, separator)
146
146
  puts format_record(db, rec)
147
147
  end
148
148
  end
149
- return true
149
+ true
150
150
  rescue Starscope::DB::NoTableError
151
- $stderr.puts "Table '#{table}' doesn't exist."
152
- return false
151
+ warn "Table '#{table}' doesn't exist."
152
+ false
153
153
  end
154
154
 
155
155
  def dump_table(db, table)
@@ -174,22 +174,22 @@ def dump(db, table)
174
174
  when '_files'
175
175
  puts db.metadata(:files).keys
176
176
  when /^_/
177
- puts db.metadata(table[1..-1].to_sym)
177
+ puts db.metadata(table[1..].to_sym)
178
178
  else
179
179
  dump_table(db, table.to_sym)
180
180
  end
181
181
 
182
- return true
182
+ true
183
183
  rescue Starscope::DB::NoTableError
184
- $stderr.puts "Table '#{table}' doesn't exist."
185
- return false
184
+ warn "Table '#{table}' doesn't exist."
185
+ false
186
186
  end
187
187
 
188
188
  def export(db, param)
189
189
  format, path = param.split(',', 2)
190
190
  db.export(format.to_sym, path)
191
191
  rescue Starscope::Exportable::UnknownExportFormatError
192
- $stderr.puts "Unrecognized export format \"#{format}\""
192
+ warn "Unrecognized export format \"#{format}\""
193
193
  end
194
194
 
195
195
  output = Starscope::Output.new(options[:output])
@@ -246,18 +246,19 @@ if options[:dump]
246
246
  end
247
247
 
248
248
  def linemode_help
249
- <<END
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
- 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
261
262
  end
262
263
 
263
264
  if options[:linemode]
@@ -265,27 +266,28 @@ if options[:linemode]
265
266
  begin
266
267
  while (input = Readline.readline('> ', true))
267
268
  next if input.empty?
269
+
268
270
  cmd, param = input.split(' ', 2)
269
271
  if cmd[0] == '!'
270
- case cmd[1..-1]
271
- when 'dump'
272
+ case cmd[1..]
273
+ when 'dump', 'd'
272
274
  dump(db, param)
273
- when 'export'
275
+ when 'export', 'e', 'ex'
274
276
  if param
275
277
  export(db, param)
276
278
  else
277
279
  puts '!export requires an argument'
278
280
  end
279
- when 'summary'
281
+ when 'summary', 's', 'sum'
280
282
  print_summary(db)
281
- when 'update'
283
+ when 'update', 'u', 'up'
282
284
  changed = db.update
283
285
  db.save(options[:db]) if options[:write] && changed
284
- when 'help'
286
+ when 'help', 'h'
285
287
  puts linemode_help
286
- when 'version'
288
+ when 'version', 'v'
287
289
  puts Starscope::VERSION
288
- when 'quit'
290
+ when 'quit', 'q'
289
291
  exit
290
292
  else
291
293
  puts "Unknown command: '#{input}', try '!help'."
@@ -296,6 +298,7 @@ if options[:linemode]
296
298
  end
297
299
  end
298
300
  rescue Interrupt
301
+ puts
299
302
  exit
300
303
  end
301
304
  end
@@ -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