linecache 0.46-java → 1.3.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ChangeLog +0 -620
- data/NEWS +11 -6
- data/README.md +34 -0
- data/Rakefile +28 -54
- data/lib/linecache.rb +65 -78
- data/lib/linecache/trace_nums.rb +1 -1
- data/lib/linecache/version.rb +1 -1
- metadata +83 -94
- data/README +0 -50
data/NEWS
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
1.3.1
|
2
|
+
15-09-19
|
3
|
+
|
4
|
+
- JRuby fix, sync with ruby-2.1 and ruby-1.9
|
5
|
+
|
1
6
|
0.46
|
2
7
|
06-12-19
|
3
|
-
- A require_relative dependency snuck in.
|
8
|
+
- A require_relative dependency snuck in.
|
4
9
|
Add a rbx-require-relative to handle this.
|
5
10
|
|
6
11
|
0.45
|
@@ -12,7 +17,7 @@
|
|
12
17
|
06-12-08
|
13
18
|
- tolerance for finding windows extension in lib rather than ext.
|
14
19
|
|
15
|
-
0.41
|
20
|
+
0.41
|
16
21
|
- add test/data/* to gem.
|
17
22
|
|
18
23
|
0.4
|
@@ -21,15 +26,15 @@
|
|
21
26
|
0.3
|
22
27
|
- Add tracelines: get line numbers that can be stopped at.
|
23
28
|
|
24
|
-
- Add routines to allow line-number
|
25
|
-
remapping and filename remapping.
|
29
|
+
- Add routines to allow line-number
|
30
|
+
remapping and filename remapping.
|
26
31
|
|
27
32
|
- Add access methods to get the number of lines in a file.
|
28
33
|
|
29
34
|
0.2
|
30
35
|
- Make this work with ruby-debug-base. Add reload-on-change parameters.
|
31
|
-
add checkcache, cache, cached? sha1, and stat methods.
|
32
|
-
|
36
|
+
add checkcache, cache, cached? sha1, and stat methods.
|
37
|
+
|
33
38
|
- Use SCRIPT_LINES__.
|
34
39
|
|
35
40
|
0.1
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
The LineCache module allows one to get any line from any file, caching
|
2
|
+
the lines and file information on first access to the file. Although
|
3
|
+
the file may be any file, the common use is when the file is a Ruby
|
4
|
+
script since parsing of the file is done to figure out where the
|
5
|
+
statement boundaries are, and we also cache syntax formatting.
|
6
|
+
|
7
|
+
The routines here may be is useful when a small random sets of lines
|
8
|
+
are read from a single file, in particular in a debugger to show
|
9
|
+
source lines.
|
10
|
+
|
11
|
+
*Example*:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'linecache'
|
15
|
+
lines = LineCache::getlines('/tmp/myruby.rb')
|
16
|
+
# The following lines have same effect as the above.
|
17
|
+
$: << '/tmp'
|
18
|
+
Dir.chdir('/tmp') {lines = LineCache::getlines('myruby.rb')
|
19
|
+
|
20
|
+
line = LineCache::getline('/tmp/myruby.rb', 6)
|
21
|
+
# Note lines[6] == line (if /tmp/myruby.rb has 6 lines)
|
22
|
+
|
23
|
+
LineCache::clear_file_cache
|
24
|
+
LineCache::clear_file_cache('/tmp/myruby.rb')
|
25
|
+
LineCache::update_cache # Check for modifications of all cached files.
|
26
|
+
```
|
27
|
+
|
28
|
+
The master branch handles *ruby-1.8* and *jruby*.
|
29
|
+
|
30
|
+
Use git branches *ruby-1.9* and *ruby-2.1* for code for those respective
|
31
|
+
Ruby versions. However a patched version of Ruby is needed for this to work. The patches sources are [here](https://sourceforge.net/projects/ruby-debugger-runtime/). For 1.9 and 2.x versions that don't require patched ruby see
|
32
|
+
https://rubygems.org/search?utf8=%E2%9C%93&query=linecache
|
33
|
+
|
34
|
+
I'm sorry there are so many branches and forks of essentially the same thing.
|
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ FILES = FileList[
|
|
21
21
|
'COPYING',
|
22
22
|
'ChangeLog',
|
23
23
|
'NEWS',
|
24
|
-
'README',
|
24
|
+
'README.md',
|
25
25
|
'Rakefile',
|
26
26
|
'ext/linecache/trace_nums.c',
|
27
27
|
'ext/linecache/trace_nums.h',
|
@@ -30,7 +30,7 @@ FILES = FileList[
|
|
30
30
|
'test/*.rb',
|
31
31
|
'test/data/*.rb',
|
32
32
|
'test/short-file'
|
33
|
-
]
|
33
|
+
]
|
34
34
|
|
35
35
|
desc 'Test everything'
|
36
36
|
Rake::TestTask.new(:test) do |t|
|
@@ -51,7 +51,7 @@ end
|
|
51
51
|
desc 'Test everything - same as test.'
|
52
52
|
task :check => :test
|
53
53
|
|
54
|
-
desc 'Create a GNU-style ChangeLog via
|
54
|
+
desc 'Create a GNU-style ChangeLog via git2cl'
|
55
55
|
task :ChangeLog do
|
56
56
|
system('git log --pretty --numstat --summary | git2cl > ChangeLog')
|
57
57
|
end
|
@@ -61,7 +61,7 @@ gem_file = nil
|
|
61
61
|
# Base GEM Specification
|
62
62
|
default_spec = Gem::Specification.new do |spec|
|
63
63
|
spec.name = 'linecache'
|
64
|
-
|
64
|
+
|
65
65
|
spec.homepage = 'http://rubyforge.org/projects/rocky-hacks/linecache'
|
66
66
|
spec.summary = 'Read file with caching'
|
67
67
|
spec.description = <<-EOF
|
@@ -73,18 +73,18 @@ EOF
|
|
73
73
|
|
74
74
|
spec.author = 'R. Bernstein'
|
75
75
|
spec.email = 'rockyb@rubyforge.net'
|
76
|
+
spec.licenses = ['GPL2']
|
76
77
|
spec.platform = Gem::Platform::RUBY
|
77
78
|
spec.require_path = 'lib'
|
78
|
-
spec.files = FILES.to_a
|
79
|
+
spec.files = FILES.to_a
|
79
80
|
spec.extensions = ['ext/linecache/extconf.rb']
|
80
81
|
|
81
82
|
spec.required_ruby_version = '>= 1.8.7'
|
82
83
|
spec.date = Time.now
|
83
|
-
|
84
|
-
|
84
|
+
|
85
85
|
# rdoc
|
86
86
|
spec.has_rdoc = true
|
87
|
-
spec.extra_rdoc_files = ['README', 'lib/linecache.rb', 'lib/linecache/tracelines.rb']
|
87
|
+
spec.extra_rdoc_files = ['README.md', 'lib/linecache.rb', 'lib/linecache/tracelines.rb']
|
88
88
|
|
89
89
|
spec.test_files = FileList['test/*.rb']
|
90
90
|
gem_file = "#{spec.name}-#{spec.version}.gem"
|
@@ -122,29 +122,8 @@ task :win32_gem do
|
|
122
122
|
rm(target)
|
123
123
|
end
|
124
124
|
|
125
|
-
desc 'Publish linecache to RubyForge.'
|
126
|
-
task :publish do
|
127
|
-
require 'rake/contrib/sshpublisher'
|
128
|
-
|
129
|
-
# Get ruby-debug path.
|
130
|
-
ruby_debug_path = File.expand_path(File.dirname(__FILE__))
|
131
|
-
|
132
|
-
publisher = Rake::SshDirPublisher.new('rockyb@rubyforge.org',
|
133
|
-
'/var/www/gforge-projects/rocky-hacks/linecache', ruby_debug_path)
|
134
|
-
end
|
135
|
-
|
136
|
-
desc 'Remove residue from running patch'
|
137
|
-
task :rm_patch_residue do
|
138
|
-
FileUtils.rm_rf Dir.glob('**/*.{rej,orig}'), :verbose => true
|
139
|
-
end
|
140
|
-
|
141
|
-
desc 'Remove ~ backup files'
|
142
|
-
task :rm_tilde_backups do
|
143
|
-
FileUtils.rm_rf Dir.glob('**/*~'), :verbose => true
|
144
|
-
end
|
145
|
-
|
146
125
|
desc 'Remove built files'
|
147
|
-
task :clean => [:clobber_package, :clobber_rdoc, :rm_patch_residue,
|
126
|
+
task :clean => [:clobber_package, :clobber_rdoc, :rm_patch_residue,
|
148
127
|
:rm_tilde_backups] do
|
149
128
|
cd 'ext' do
|
150
129
|
if File.exists?('Makefile')
|
@@ -157,24 +136,22 @@ task :clean => [:clobber_package, :clobber_rdoc, :rm_patch_residue,
|
|
157
136
|
end
|
158
137
|
|
159
138
|
# --------- RDoc Documentation ------
|
160
|
-
|
161
|
-
|
139
|
+
require 'rdoc/task'
|
140
|
+
desc "Generate rdoc documentation"
|
141
|
+
Rake::RDocTask.new("rdoc") do |rdoc|
|
162
142
|
rdoc.rdoc_dir = 'doc'
|
163
|
-
rdoc.title = "
|
164
|
-
rdoc.options << '--main' << 'README'
|
165
|
-
rdoc.rdoc_files.include('ext/**/*.c',
|
166
|
-
'lib/*.rb',
|
167
|
-
'README',
|
168
|
-
'COPYING')
|
169
|
-
end
|
143
|
+
rdoc.title = "LineCache #{LineCache::VERSION} Documentation"
|
170
144
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
145
|
+
# Show source inline with line numbers
|
146
|
+
rdoc.options += %w(--inline-source --line-numbers)
|
147
|
+
|
148
|
+
# Make the README.md file the start page for the generated html
|
149
|
+
rdoc.options += %w(--main README.md)
|
150
|
+
|
151
|
+
rdoc.rdoc_files.include('lib/*.rb', 'README.md', 'COPYING')
|
177
152
|
end
|
153
|
+
desc "Same as rdoc"
|
154
|
+
task :doc => :rdoc
|
178
155
|
|
179
156
|
desc 'Install the gem locally'
|
180
157
|
task :install => :gem do
|
@@ -183,13 +160,10 @@ task :install => :gem do
|
|
183
160
|
end
|
184
161
|
end
|
185
162
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
Gem::PackageTask.new(jruby_spec) {}
|
194
|
-
end
|
163
|
+
namespace :jruby do
|
164
|
+
jruby_spec = default_spec.clone
|
165
|
+
jruby_spec.platform = "java"
|
166
|
+
jruby_spec.files = jruby_spec.files.reject {|f| f =~ /^ext/ }
|
167
|
+
jruby_spec.extensions = []
|
168
|
+
Gem::PackageTask.new(jruby_spec) {}
|
195
169
|
end
|
data/lib/linecache.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
#
|
4
|
-
# Copyright (C) 2007, 2008, 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007, 2008, 2010-2012, 2015 Rocky Bernstein <rockyb@rubyforge.net>
|
5
4
|
#
|
6
5
|
# This program is free software; you can redistribute it and/or modify
|
7
6
|
# it under the terms of the GNU General Public License as published by
|
@@ -22,12 +21,12 @@
|
|
22
21
|
# Author:: Rocky Bernstein (mailto:rockyb@rubyforge.net)
|
23
22
|
#
|
24
23
|
# = linecache
|
25
|
-
# A module to read and cache lines of a Ruby program.
|
24
|
+
# A module to read and cache lines of a Ruby program.
|
26
25
|
|
27
26
|
# == SYNOPSIS
|
28
27
|
#
|
29
28
|
# The LineCache module allows one to get any line from any file,
|
30
|
-
# caching lines of the file on first access to the file. Although the
|
29
|
+
# caching lines of the file on first access to the file. Although the
|
31
30
|
# file may be any file, the common use is when the file is a Ruby
|
32
31
|
# script since parsing of the file is done to figure out where the
|
33
32
|
# statement boundaries are.
|
@@ -47,6 +46,7 @@
|
|
47
46
|
# # Note lines[6] == line (if /tmp/myruby.rb has 6 lines)
|
48
47
|
#
|
49
48
|
# LineCache::clear_file_cache
|
49
|
+
# LineCache::clear_file_cache('/tmp/myruby.rb')
|
50
50
|
# LineCache::update_cache # Check for modifications of all cached files.
|
51
51
|
#
|
52
52
|
# Some parts of the interface is derived from the Python module of the
|
@@ -67,20 +67,19 @@ require 'linecache/version'
|
|
67
67
|
# require 'ruby-debug' ; Debugger.start
|
68
68
|
|
69
69
|
# = module LineCache
|
70
|
-
# A module to read and cache lines of a Ruby program.
|
70
|
+
# A module to read and cache lines of a Ruby program.
|
71
71
|
module LineCache
|
72
72
|
LineCacheInfo = Struct.new(:stat, :line_numbers, :lines, :path, :sha1) unless
|
73
73
|
defined?(LineCacheInfo)
|
74
|
-
|
75
|
-
# The file cache. The key is a name as would be given by Ruby for
|
76
|
-
# __FILE__. The value is a LineCacheInfo object.
|
77
|
-
@@file_cache = {}
|
78
|
-
@@script_cache = {}
|
79
74
|
|
75
|
+
# The file cache. The key is a name as would be given by Ruby for
|
76
|
+
# __FILE__. The value is a LineCacheInfo object.
|
77
|
+
@@file_cache = {}
|
78
|
+
@@script_cache = {}
|
80
79
|
|
81
80
|
# Used for CodeRay syntax highlighting
|
82
81
|
@@ruby_highlighter = nil
|
83
|
-
|
82
|
+
|
84
83
|
# Maps a string filename (a String) to a key in @@file_cache (a
|
85
84
|
# String).
|
86
85
|
#
|
@@ -93,9 +92,9 @@ module LineCache
|
|
93
92
|
# Another related use is when a template system is used. Here we'll
|
94
93
|
# probably want to remap not only the file name but also line
|
95
94
|
# ranges. Will probably use this for that, but I'm not sure.
|
96
|
-
@@file2file_remap = {}
|
95
|
+
@@file2file_remap = {}
|
97
96
|
@@file2file_remap_lines = {}
|
98
|
-
@@script2file = {}
|
97
|
+
@@script2file = {}
|
99
98
|
|
100
99
|
module_function
|
101
100
|
|
@@ -106,10 +105,11 @@ module LineCache
|
|
106
105
|
end
|
107
106
|
at_exit { remove_script_temps }
|
108
107
|
|
109
|
-
|
110
|
-
# Clear the file cache entirely.
|
108
|
+
|
109
|
+
# Clear the file cache. If no filename is given clear it entirely.
|
110
|
+
# if a filename is given, clear just that filename.
|
111
111
|
def clear_file_cache(filename=nil)
|
112
|
-
if filename
|
112
|
+
if filename
|
113
113
|
if @@file_cache[filename]
|
114
114
|
@@file_cache.delete(filename)
|
115
115
|
end
|
@@ -122,7 +122,7 @@ module LineCache
|
|
122
122
|
|
123
123
|
# Remove syntax-formatted lines in the cache. Use this
|
124
124
|
# when you change the CodeRay syntax or Token formatting
|
125
|
-
# and want to redo how files may have previously been
|
125
|
+
# and want to redo how files may have previously been
|
126
126
|
# syntax marked.
|
127
127
|
def clear_file_format_cache
|
128
128
|
@@file_cache.each_pair do |fname, cache_info|
|
@@ -135,7 +135,7 @@ module LineCache
|
|
135
135
|
|
136
136
|
# Remove syntax-formatted lines in the cache. Use this
|
137
137
|
# when you change the CodeRay syntax or Token formatting
|
138
|
-
# and want to redo how files may have previously been
|
138
|
+
# and want to redo how files may have previously been
|
139
139
|
# syntax marked.
|
140
140
|
def clear_file_format_cache
|
141
141
|
@@file_cache.each_pair do |fname, cache_info|
|
@@ -163,13 +163,13 @@ module LineCache
|
|
163
163
|
# is found, it will be kept. Return a list of invalidated filenames.
|
164
164
|
# nil is returned if a filename was given but not found cached.
|
165
165
|
def checkcache(filename=nil, opts=false)
|
166
|
-
use_script_lines =
|
166
|
+
use_script_lines =
|
167
167
|
if opts.kind_of?(Hash)
|
168
168
|
opts[:use_script_lines]
|
169
169
|
else
|
170
170
|
opts
|
171
171
|
end
|
172
|
-
|
172
|
+
|
173
173
|
if !filename
|
174
174
|
filenames = @@file_cache.keys()
|
175
175
|
elsif @@file_cache.member?(filename)
|
@@ -186,7 +186,7 @@ module LineCache
|
|
186
186
|
cache_info = @@file_cache[filename].stat
|
187
187
|
stat = File.stat(path)
|
188
188
|
if cache_info
|
189
|
-
if stat &&
|
189
|
+
if stat &&
|
190
190
|
(cache_info.size != stat.size or cache_info.mtime != stat.mtime)
|
191
191
|
result << filename
|
192
192
|
update_cache(filename, opts)
|
@@ -208,17 +208,6 @@ module LineCache
|
|
208
208
|
script
|
209
209
|
end
|
210
210
|
|
211
|
-
# Cache file name or script object if it's not already cached.
|
212
|
-
# Return the expanded filename for it in the cache if a filename,
|
213
|
-
# or the script, or nil if we can't find the file.
|
214
|
-
def cache(file_or_script, reload_on_change=false)
|
215
|
-
if file_or_script.kind_of?(String)
|
216
|
-
cache_file(file_or_script, reload_on_change)
|
217
|
-
else
|
218
|
-
cache_script(file_or_script)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
211
|
# Cache filename if it's not already cached.
|
223
212
|
# Return the expanded filename for it in the cache
|
224
213
|
# or nil if we can't find the file.
|
@@ -252,12 +241,12 @@ module LineCache
|
|
252
241
|
nil
|
253
242
|
end
|
254
243
|
end
|
255
|
-
|
244
|
+
|
256
245
|
# Return true if file_or_script is cached
|
257
246
|
def cached?(file_or_script)
|
258
|
-
if file_or_script.kind_of?(String)
|
247
|
+
if file_or_script.kind_of?(String)
|
259
248
|
@@file_cache.member?(unmap_file(file_or_script))
|
260
|
-
else
|
249
|
+
else
|
261
250
|
cached_script?(file_or_script)
|
262
251
|
end
|
263
252
|
end
|
@@ -265,7 +254,7 @@ module LineCache
|
|
265
254
|
def cached_script?(filename)
|
266
255
|
SCRIPT_LINES__.member?(unmap_file(filename))
|
267
256
|
end
|
268
|
-
|
257
|
+
|
269
258
|
def empty?(filename)
|
270
259
|
filename=unmap_file(filename)
|
271
260
|
!!@@file_cache[filename].lines[:plain]
|
@@ -274,22 +263,22 @@ module LineCache
|
|
274
263
|
# Get line +line_number+ from file named +filename+. Return nil if
|
275
264
|
# there was a problem. If a file named filename is not found, the
|
276
265
|
# function will look for it in the $: array.
|
277
|
-
#
|
266
|
+
#
|
278
267
|
# Examples:
|
279
|
-
#
|
268
|
+
#
|
280
269
|
# lines = LineCache::getline('/tmp/myfile.rb')
|
281
270
|
# # Same as above
|
282
271
|
# $: << '/tmp'
|
283
272
|
# lines = LineCache.getlines('myfile.rb')
|
284
273
|
#
|
285
274
|
def getline(file_or_script, line_number, opts=true)
|
286
|
-
reload_on_change =
|
275
|
+
reload_on_change =
|
287
276
|
if opts.kind_of?(Hash)
|
288
277
|
opts[:reload_on_change]
|
289
278
|
else
|
290
279
|
opts
|
291
280
|
end
|
292
|
-
lines =
|
281
|
+
lines =
|
293
282
|
if file_or_script.kind_of?(String)
|
294
283
|
filename = unmap_file(file_or_script)
|
295
284
|
filename, line_number = unmap_file_line(filename, line_number)
|
@@ -309,7 +298,7 @@ module LineCache
|
|
309
298
|
# if we can't get lines
|
310
299
|
def getlines(filename, opts=false)
|
311
300
|
if opts.kind_of?(Hash)
|
312
|
-
reload_on_change, use_script_lines =
|
301
|
+
reload_on_change, use_script_lines =
|
313
302
|
[opts[:reload_on_change], opts[:use_script_lines]]
|
314
303
|
else
|
315
304
|
reload_on_change, use_script_lines = [opts, false]
|
@@ -320,7 +309,7 @@ module LineCache
|
|
320
309
|
if @@file_cache.member?(filename)
|
321
310
|
lines = @@file_cache[filename].lines
|
322
311
|
if opts[:output] && !lines[format]
|
323
|
-
lines[format] =
|
312
|
+
lines[format] =
|
324
313
|
highlight_string(lines[:plain].join(''), format).split(/\n/)
|
325
314
|
end
|
326
315
|
return lines[format]
|
@@ -363,7 +352,7 @@ module LineCache
|
|
363
352
|
def remap_file_lines(from_file, to_file, range, start)
|
364
353
|
range = (range..range) if range.kind_of?(Fixnum)
|
365
354
|
to_file = from_file unless to_file
|
366
|
-
if @@file2file_remap_lines[to_file]
|
355
|
+
if @@file2file_remap_lines[to_file]
|
367
356
|
# FIXME: need to check for overwriting ranges: whether
|
368
357
|
# they intersect or one encompasses another.
|
369
358
|
@@file2file_remap_lines[to_file] << [from_file, range, start]
|
@@ -372,12 +361,12 @@ module LineCache
|
|
372
361
|
end
|
373
362
|
end
|
374
363
|
module_function :remap_file_lines
|
375
|
-
|
364
|
+
|
376
365
|
# Return SHA1 of filename.
|
377
366
|
def sha1(filename)
|
378
367
|
filename = unmap_file(filename)
|
379
368
|
return nil unless @@file_cache.member?(filename)
|
380
|
-
return @@file_cache[filename].sha1.hexdigest if
|
369
|
+
return @@file_cache[filename].sha1.hexdigest if
|
381
370
|
@@file_cache[filename].sha1
|
382
371
|
sha1 = Digest::SHA1.new
|
383
372
|
@@file_cache[filename].lines[:plain].each do |line|
|
@@ -386,7 +375,7 @@ module LineCache
|
|
386
375
|
@@file_cache[filename].sha1 = sha1
|
387
376
|
sha1.hexdigest
|
388
377
|
end
|
389
|
-
|
378
|
+
|
390
379
|
# Return the number of lines in filename
|
391
380
|
def size(file_or_script)
|
392
381
|
cache(file_or_script)
|
@@ -416,13 +405,13 @@ module LineCache
|
|
416
405
|
return nil unless fullname
|
417
406
|
e = @@file_cache[filename]
|
418
407
|
unless e.line_numbers
|
419
|
-
e.line_numbers =
|
408
|
+
e.line_numbers =
|
420
409
|
TraceLineNumbers.lnums_for_str_array(e.lines[:plain])
|
421
410
|
e.line_numbers = false unless e.line_numbers
|
422
411
|
end
|
423
412
|
e.line_numbers
|
424
413
|
end
|
425
|
-
|
414
|
+
|
426
415
|
def unmap_file(file)
|
427
416
|
@@file2file_remap[file] ? @@file2file_remap[file] : file
|
428
417
|
end
|
@@ -432,8 +421,8 @@ module LineCache
|
|
432
421
|
if @@file2file_remap_lines[file]
|
433
422
|
@@file2file_remap_lines[file].each do |from_file, range, start|
|
434
423
|
if range === line
|
435
|
-
from_file = from_file || file
|
436
|
-
return [from_file, start+line-range.begin]
|
424
|
+
from_file = from_file || file
|
425
|
+
return [from_file, start+line-range.begin]
|
437
426
|
end
|
438
427
|
end
|
439
428
|
end
|
@@ -441,15 +430,15 @@ module LineCache
|
|
441
430
|
end
|
442
431
|
|
443
432
|
# Update a cache entry. If something is wrong, return nil. Return
|
444
|
-
# true if the cache was updated and false if not.
|
433
|
+
# true if the cache was updated and false if not.
|
445
434
|
def update_script_cache(script, opts)
|
446
435
|
# return false unless script_is_eval?(script)
|
447
436
|
# string = opts[:string] || script.eval_source
|
448
437
|
lines = {:plain => string.split(/\n/)}
|
449
438
|
lines[opts[:output]] = highlight_string(string, opts[:output]) if
|
450
439
|
opts[:output]
|
451
|
-
@@script_cache[script] =
|
452
|
-
LineCacheInfo.new(nil, nil, lines, nil, opts[:sha1],
|
440
|
+
@@script_cache[script] =
|
441
|
+
LineCacheInfo.new(nil, nil, lines, nil, opts[:sha1],
|
453
442
|
opts[:compiled_method])
|
454
443
|
return true
|
455
444
|
end
|
@@ -470,13 +459,13 @@ module LineCache
|
|
470
459
|
|
471
460
|
@@file_cache.delete(filename)
|
472
461
|
path = File.expand_path(filename)
|
473
|
-
|
462
|
+
|
474
463
|
if use_script_lines
|
475
464
|
list = [filename]
|
476
465
|
list << @@file2file_remap[path] if @@file2file_remap[path]
|
477
|
-
list.each do |name|
|
466
|
+
list.each do |name|
|
478
467
|
if !SCRIPT_LINES__[name].nil? && SCRIPT_LINES__[name] != true
|
479
|
-
begin
|
468
|
+
begin
|
480
469
|
stat = File.stat(name)
|
481
470
|
rescue
|
482
471
|
stat = nil
|
@@ -484,7 +473,7 @@ module LineCache
|
|
484
473
|
raw_lines = SCRIPT_LINES__[name]
|
485
474
|
lines = {:plain => raw_lines}
|
486
475
|
lines[opts[:output]] =
|
487
|
-
highlight_string(raw_lines.join, opts[:output]).split(/\n/) if
|
476
|
+
highlight_string(raw_lines.join, opts[:output]).split(/\n/) if
|
488
477
|
opts[:output]
|
489
478
|
@@file_cache[filename] = LineCacheInfo.new(stat, nil, lines, path, nil)
|
490
479
|
@@file2file_remap[path] = filename
|
@@ -492,7 +481,7 @@ module LineCache
|
|
492
481
|
end
|
493
482
|
end
|
494
483
|
end
|
495
|
-
|
484
|
+
|
496
485
|
if File.exist?(path)
|
497
486
|
stat = File.stat(path)
|
498
487
|
elsif File.basename(filename) == filename
|
@@ -508,15 +497,13 @@ module LineCache
|
|
508
497
|
return false unless stat
|
509
498
|
end
|
510
499
|
begin
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
opts[:output]
|
519
|
-
rescue
|
500
|
+
# (GF) rewind does not work in JRuby with a jar:file:... filename
|
501
|
+
# (GF) read file once and only create string if required by opts[:output]
|
502
|
+
lines = { :plain => File.readlines(path) }
|
503
|
+
if opts[:output]
|
504
|
+
lines[opts[:output]] = highlight_string(lines[:plain].join, opts[:output]).split(/\n/)
|
505
|
+
end
|
506
|
+
rescue
|
520
507
|
## print '*** cannot open', path, ':', msg
|
521
508
|
return nil
|
522
509
|
end
|
@@ -529,15 +516,15 @@ module LineCache
|
|
529
516
|
end
|
530
517
|
|
531
518
|
# example usage
|
532
|
-
if __FILE__ == $0
|
533
|
-
def yes_no(var)
|
519
|
+
if __FILE__ == $0
|
520
|
+
def yes_no(var)
|
534
521
|
return var ? "" : "not "
|
535
522
|
end
|
536
523
|
|
537
524
|
lines = LineCache::getlines(__FILE__)
|
538
525
|
puts "#{__FILE__} has #{LineCache.size(__FILE__)} lines"
|
539
526
|
line = LineCache::getline(__FILE__, 6)
|
540
|
-
puts "The 6th line is\n#{line}"
|
527
|
+
puts "The 6th line is\n#{line}"
|
541
528
|
line = LineCache::remap_file(__FILE__, 'another_name')
|
542
529
|
puts LineCache::getline('another_name', 7)
|
543
530
|
|
@@ -545,21 +532,21 @@ if __FILE__ == $0
|
|
545
532
|
LineCache::update_cache(__FILE__)
|
546
533
|
LineCache::checkcache(__FILE__)
|
547
534
|
puts "#{__FILE__} has #{LineCache::size(__FILE__)} lines"
|
548
|
-
puts "#{__FILE__} trace line numbers:\n" +
|
535
|
+
puts "#{__FILE__} trace line numbers:\n" +
|
549
536
|
"#{LineCache::trace_line_numbers(__FILE__).to_a.sort.inspect}"
|
550
|
-
puts("#{__FILE__} is %scached." %
|
537
|
+
puts("#{__FILE__} is %scached." %
|
551
538
|
yes_no(LineCache::cached?(__FILE__)))
|
552
539
|
puts LineCache::stat(__FILE__).inspect
|
553
540
|
puts "Full path: #{LineCache::path(__FILE__)}"
|
554
541
|
LineCache::checkcache # Check all files in the cache
|
555
|
-
LineCache::clear_file_cache
|
556
|
-
puts("#{__FILE__} is now %scached." %
|
542
|
+
LineCache::clear_file_cache
|
543
|
+
puts("#{__FILE__} is now %scached." %
|
557
544
|
yes_no(LineCache::cached?(__FILE__)))
|
558
545
|
digest = SCRIPT_LINES__.select{|k,v| k =~ /digest.rb$/}
|
559
546
|
puts digest.first[0] if digest
|
560
547
|
line = LineCache::getline(__FILE__, 7)
|
561
|
-
puts "The 7th line is\n#{line}"
|
548
|
+
puts "The 7th line is\n#{line}"
|
562
549
|
LineCache::remap_file_lines(__FILE__, 'test2', (10..20), 6)
|
563
|
-
|
564
|
-
puts "Remapped
|
550
|
+
line = LineCache::getline('test2', 11)
|
551
|
+
puts "Remapped 11th line of test2 is\n#{line}"
|
565
552
|
end
|