rbx-linecache 1.2-universal-rubinius-1.2 → 1.4-universal-rubinius-1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +2737 -268
- data/NEWS +15 -7
- data/README +16 -20
- data/Rakefile +87 -22
- data/lib/linecache.rb +56 -56
- data/test/data/block1.rb +1 -1
- data/test/data/case1.rb +1 -1
- data/test/data/case2.rb +1 -1
- data/test/data/case3.rb +1 -1
- data/test/data/case4.rb +1 -1
- data/test/data/case5.rb +1 -1
- data/test/data/if1.rb +1 -1
- data/test/data/if2.rb +1 -1
- data/test/data/if3.rb +1 -1
- data/test/data/if4.rb +1 -1
- data/test/data/if5.rb +1 -1
- data/test/data/if6.rb +1 -1
- data/test/data/if7.rb +1 -1
- data/test/test-linecache.rb +15 -15
- data/test/test-tracelines.rb +1 -1
- metadata +38 -42
data/NEWS
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
1.4
|
2
|
+
- static_scope -> constant_scope to rubinius 2.0.rc1
|
3
|
+
|
4
|
+
1.3
|
5
|
+
- CompiledMethod#lines tuple changes and allow rubinius 2.0.pre
|
6
|
+
|
7
|
+
1.2
|
8
|
+
- Add CompiledMethod caching.
|
9
|
+
|
1
10
|
1.1.1
|
2
11
|
March 15, 2011
|
3
12
|
- Cache compiled methods for rbx-trepanning
|
@@ -10,14 +19,14 @@ December 25, 2010
|
|
10
19
|
- Handle Rubinius eval_source to temp file remapping.
|
11
20
|
|
12
21
|
October 27, 2010
|
13
|
-
- First gemcutter rubinius release
|
22
|
+
- First gemcutter rubinius release
|
14
23
|
|
15
24
|
|
16
25
|
0.43
|
17
26
|
06-12-08
|
18
27
|
- tolerance for finding windows extension in lib rather than ext.
|
19
28
|
|
20
|
-
0.41
|
29
|
+
0.41
|
21
30
|
- add test/data/* to gem.
|
22
31
|
|
23
32
|
0.4
|
@@ -26,18 +35,17 @@ October 27, 2010
|
|
26
35
|
0.3
|
27
36
|
- Add tracelines: get line numbers that can be stopped at.
|
28
37
|
|
29
|
-
- Add routines to allow line-number
|
30
|
-
remapping and filename remapping.
|
38
|
+
- Add routines to allow line-number
|
39
|
+
remapping and filename remapping.
|
31
40
|
|
32
41
|
- Add access methods to get the number of lines in a file.
|
33
42
|
|
34
43
|
0.2
|
35
44
|
- Make this work with ruby-debug-base. Add reload-on-change parameters.
|
36
|
-
add checkcache, cache, cached? sha1, and stat methods.
|
37
|
-
|
45
|
+
add checkcache, cache, cached? sha1, and stat methods.
|
46
|
+
|
38
47
|
- Use SCRIPT_LINES__.
|
39
48
|
|
40
49
|
0.1
|
41
50
|
|
42
51
|
- Initial release of LineCache, a module for reading and caching lines.
|
43
|
-
|
data/README
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
== SYNOPSIS
|
1
|
+
## LineCache - A module to read and cache file information of a Ruby program.
|
4
2
|
|
5
3
|
The LineCache module allows one to get any line from any file, caching
|
6
4
|
the lines and file information on first access to the file. Although
|
@@ -12,39 +10,37 @@ The routines here may be is useful when a small random sets of lines
|
|
12
10
|
are read from a single file, in particular in a debugger to show
|
13
11
|
source lines.
|
14
12
|
|
15
|
-
|
13
|
+
## Summary
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
require 'linecache'
|
16
|
+
lines = LineCache::getlines('/tmp/myruby.rb')
|
17
|
+
# The following lines have same effect as the above.
|
18
|
+
$: << '/tmp'
|
19
|
+
Dir.chdir('/tmp') {lines = LineCache::getlines('myruby.rb')
|
22
20
|
|
23
|
-
|
24
|
-
|
21
|
+
line = LineCache::getline('/tmp/myruby.rb', 6)
|
22
|
+
# Note lines[6] == line (if /tmp/myruby.rb has 6 lines)
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
LineCache::clear_file_cache
|
25
|
+
LineCache::clear_file_cache('/tmp/myruby.rb')
|
26
|
+
LineCache::update_cache # Check for modifications of all cached files.
|
29
27
|
|
30
|
-
|
28
|
+
## Credits
|
31
29
|
|
32
30
|
This is a port of the module of the same name from the Python distribution.
|
33
31
|
|
34
32
|
The idea for how TraceLineNumbers works, and some code was taken
|
35
33
|
from ParseTree by Ryan Davis.
|
36
34
|
|
37
|
-
|
35
|
+
## Other stuff
|
38
36
|
|
39
37
|
Author:: Rocky Bernstein <rockyb@rubyforge.net>
|
40
|
-
License:: Copyright (c) 2007, 2008 Rocky Bernstein
|
38
|
+
License:: Copyright (c) 2007, 2008, 2013 Rocky Bernstein
|
41
39
|
Released under the GNU GPL 2 license
|
42
40
|
|
43
|
-
|
41
|
+
## Warranty
|
44
42
|
|
45
43
|
This program is distributed in the hope that it will be useful,
|
46
44
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
47
45
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
48
46
|
GNU General Public License for more details.
|
49
|
-
|
50
|
-
$Id: README 169 2009-02-08 17:19:33Z rockyb $
|
data/Rakefile
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
Rubinius
|
7
|
-
|
2
|
+
# -*- Ruby -*-
|
3
|
+
# Are we Rubinius? The right versions of it?
|
4
|
+
raise RuntimeError,
|
5
|
+
'This package is for Rubinius 1.2.[34] or 2.0.x only!' unless
|
6
|
+
Object.constants.include?('Rubinius') &&
|
7
|
+
Rubinius.constants.include?('VM') &&
|
8
|
+
Rubinius::VERSION =~ /1\.2\.[34]/ || Rubinius::VERSION =~ /2\.0/
|
8
9
|
|
9
10
|
require 'rubygems'
|
10
|
-
require 'rake/gempackagetask'
|
11
|
-
require 'rake/rdoctask'
|
12
|
-
require 'rake/testtask'
|
13
11
|
|
14
12
|
ROOT_DIR = File.dirname(__FILE__)
|
15
13
|
Gemspec_filename = 'rbx-linecache.gemspec'
|
@@ -19,28 +17,80 @@ def gemspec
|
|
19
17
|
@gemspec ||= eval(File.read(Gemspec_filename), binding, Gemspec_filename)
|
20
18
|
end
|
21
19
|
|
20
|
+
require 'rubygems/package_task'
|
22
21
|
desc "Build the gem"
|
23
22
|
task :package=>:gem
|
24
23
|
task :gem=>:gemspec do
|
25
24
|
Dir.chdir(ROOT_DIR) do
|
26
25
|
sh "gem build #{Gemspec_filename}"
|
27
26
|
FileUtils.mkdir_p 'pkg'
|
28
|
-
FileUtils.mv
|
27
|
+
FileUtils.mv gemspec.file_name, 'pkg'
|
28
|
+
|
29
|
+
# Now make a 2.0 package by changing 1.2 to 2.0 in the gemspec
|
30
|
+
# and creating another gemspec and moving that accordingly
|
31
|
+
lines = File.open(Gemspec_filename).readlines.map{|line|
|
32
|
+
line.gsub(/'universal', 'rubinius', '1\.2'/,
|
33
|
+
"'universal', 'rubinius', '2.0'");
|
34
|
+
}
|
35
|
+
|
36
|
+
two_filename = gemspec.file_name.gsub(/1\.2/, '2.0')
|
37
|
+
gemspec_filename2 = "rbx-linecache2.gemspec"
|
38
|
+
f = File.open(gemspec_filename2, "w")
|
39
|
+
f.write(lines); f.close
|
40
|
+
sh "gem build #{gemspec_filename2}"
|
41
|
+
FileUtils.mv("#{two_filename}", "pkg/")
|
29
42
|
end
|
30
43
|
end
|
31
44
|
|
32
|
-
task :default => [:test]
|
33
|
-
|
34
45
|
desc 'Install the gem locally'
|
35
|
-
task :install => :
|
46
|
+
task :install => :gem do
|
36
47
|
Dir.chdir(ROOT_DIR) do
|
37
48
|
sh %{gem install --local pkg/#{gemspec.file_name}}
|
38
49
|
end
|
39
|
-
end
|
50
|
+
end
|
51
|
+
|
52
|
+
require 'rake/testtask'
|
53
|
+
desc "Test everything."
|
54
|
+
Rake::TestTask.new(:test) do |t|
|
55
|
+
t.libs << './lib'
|
56
|
+
t.pattern = 'test/test-*.rb'
|
57
|
+
t.verbose = true
|
58
|
+
end
|
59
|
+
task :test => :lib
|
60
|
+
|
61
|
+
desc "same as test"
|
62
|
+
task :check => :test
|
63
|
+
|
64
|
+
require 'rbconfig'
|
65
|
+
def RbConfig.ruby
|
66
|
+
File.join(RbConfig::CONFIG['bindir'],
|
67
|
+
RbConfig::CONFIG['RUBY_INSTALL_NAME'] +
|
68
|
+
RbConfig::CONFIG['EXEEXT'])
|
69
|
+
end unless defined? RbConfig.ruby
|
70
|
+
|
71
|
+
def run_standalone_ruby_files(list, opts={})
|
72
|
+
puts '*' * 40
|
73
|
+
list.each do |ruby_file|
|
74
|
+
system(RbConfig.ruby, ruby_file)
|
75
|
+
p $?.exitstatus
|
76
|
+
break if $?.exitstatus != 0 && !opts[:continue]
|
77
|
+
end
|
78
|
+
end
|
40
79
|
|
41
|
-
|
80
|
+
def run_standalone_ruby_file(directory, opts={})
|
81
|
+
puts(('*' * 10) + ' ' + directory + ' ' + ('*' * 10))
|
82
|
+
Dir.chdir(directory) do
|
83
|
+
Dir.glob('*.rb').each do |ruby_file|
|
84
|
+
puts(('-' * 20) + ' ' + ruby_file + ' ' + ('-' * 20))
|
85
|
+
system(RbConfig.ruby, ruby_file)
|
86
|
+
break if $?.exitstatus != 0 && !opts[:continue]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
desc 'Create a GNU-style ChangeLog via git2cl'
|
42
92
|
task :ChangeLog do
|
43
|
-
system(
|
93
|
+
system('git log --pretty --numstat --summary | git2cl > ChangeLog')
|
44
94
|
end
|
45
95
|
|
46
96
|
desc 'Test units - the smaller tests'
|
@@ -50,17 +100,21 @@ Rake::TestTask.new(:'test') do |t|
|
|
50
100
|
t.options = '--verbose' if $VERBOSE
|
51
101
|
end
|
52
102
|
|
103
|
+
desc "Default action is same as 'test'."
|
104
|
+
task :default => :test
|
105
|
+
|
53
106
|
desc "Generate the gemspec"
|
54
107
|
task :generate do
|
55
108
|
puts gemspec.to_ruby
|
56
109
|
end
|
57
110
|
|
58
|
-
desc
|
111
|
+
desc 'Validate the gemspec'
|
59
112
|
task :gemspec do
|
60
113
|
gemspec.validate
|
61
114
|
end
|
62
115
|
|
63
116
|
# --------- RDoc Documentation ------
|
117
|
+
require 'rdoc/task'
|
64
118
|
desc "Generate rdoc documentation"
|
65
119
|
Rake::RDocTask.new("rdoc") do |rdoc|
|
66
120
|
rdoc.rdoc_dir = 'doc'
|
@@ -68,16 +122,27 @@ Rake::RDocTask.new("rdoc") do |rdoc|
|
|
68
122
|
rdoc.rdoc_files.include(%w(lib/*.rb))
|
69
123
|
end
|
70
124
|
|
71
|
-
desc
|
125
|
+
desc 'Same as rdoc'
|
72
126
|
task :doc => :rdoc
|
73
127
|
|
74
128
|
task :clobber_package do
|
75
|
-
FileUtils.rm_rf File.join(ROOT_DIR, 'pkg')
|
129
|
+
FileUtils.rm_rf File.join(ROOT_DIR, 'pkg'), :verbose => true
|
76
130
|
end
|
77
131
|
|
78
132
|
task :clobber_rdoc do
|
79
|
-
FileUtils.rm_rf File.join(ROOT_DIR, 'doc')
|
133
|
+
FileUtils.rm_rf File.join(ROOT_DIR, 'doc'), :verbose => true
|
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
|
80
144
|
end
|
81
145
|
|
82
|
-
desc
|
83
|
-
task :clean => [:clobber_package, :clobber_rdoc
|
146
|
+
desc 'Remove built files'
|
147
|
+
task :clean => [:clobber_package, :clobber_rdoc, :rm_patch_residue,
|
148
|
+
:rm_tilde_backups]
|
data/lib/linecache.rb
CHANGED
@@ -21,12 +21,12 @@
|
|
21
21
|
# Author:: Rocky Bernstein (mailto:rockyb@rubyforge.net)
|
22
22
|
#
|
23
23
|
# = linecache
|
24
|
-
# A module to read and cache lines of a Ruby program.
|
24
|
+
# A module to read and cache lines of a Ruby program.
|
25
25
|
|
26
26
|
# == SYNOPSIS
|
27
27
|
#
|
28
28
|
# The LineCache module allows one to get any line from any file,
|
29
|
-
# 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
|
30
30
|
# file may be any file, the common use is when the file is a Ruby
|
31
31
|
# script since parsing of the file is done to figure out where the
|
32
32
|
# statement boundaries are.
|
@@ -62,22 +62,22 @@ require 'require_relative'
|
|
62
62
|
require_relative 'tracelines'
|
63
63
|
|
64
64
|
# = module LineCache
|
65
|
-
# A module to read and cache lines of a Ruby program.
|
65
|
+
# A module to read and cache lines of a Ruby program.
|
66
66
|
module LineCache
|
67
|
-
VERSION = '1.
|
68
|
-
LineCacheInfo = Struct.new(:stat, :line_numbers, :lines, :path,
|
67
|
+
VERSION = '1.4'
|
68
|
+
LineCacheInfo = Struct.new(:stat, :line_numbers, :lines, :path,
|
69
69
|
:sha1, :compiled_method) unless
|
70
70
|
defined?(LineCacheInfo)
|
71
|
-
|
72
|
-
# The file cache. The key is a name as would be given by Ruby for
|
73
|
-
# __FILE__. The value is a LineCacheInfo object.
|
74
|
-
@@file_cache = {}
|
75
|
-
@@script_cache = {}
|
71
|
+
|
72
|
+
# The file cache. The key is a name as would be given by Ruby for
|
73
|
+
# __FILE__. The value is a LineCacheInfo object.
|
74
|
+
@@file_cache = {}
|
75
|
+
@@script_cache = {}
|
76
76
|
|
77
77
|
|
78
78
|
# Used for CodeRay syntax highlighting
|
79
79
|
@@ruby_highlighter = nil
|
80
|
-
|
80
|
+
|
81
81
|
# Maps a string filename (a String) to a key in @@file_cache (a
|
82
82
|
# String).
|
83
83
|
#
|
@@ -90,10 +90,10 @@ module LineCache
|
|
90
90
|
# Another related use is when a template system is used. Here we'll
|
91
91
|
# probably want to remap not only the file name but also line
|
92
92
|
# ranges. Will probably use this for that, but I'm not sure.
|
93
|
-
@@file2file_remap = {}
|
93
|
+
@@file2file_remap = {}
|
94
94
|
@@file2file_remap_lines = {}
|
95
95
|
|
96
|
-
@@script2file = {}
|
96
|
+
@@script2file = {}
|
97
97
|
|
98
98
|
module_function
|
99
99
|
|
@@ -104,10 +104,10 @@ module LineCache
|
|
104
104
|
end
|
105
105
|
at_exit { remove_script_temps }
|
106
106
|
|
107
|
-
|
107
|
+
|
108
108
|
# Clear the file cache entirely.
|
109
109
|
def clear_file_cache(filename=nil)
|
110
|
-
if filename
|
110
|
+
if filename
|
111
111
|
if @@file_cache[filename]
|
112
112
|
@@file_cache.delete(filename)
|
113
113
|
end
|
@@ -120,7 +120,7 @@ module LineCache
|
|
120
120
|
|
121
121
|
# Remove syntax-formatted lines in the cache. Use this
|
122
122
|
# when you change the CodeRay syntax or Token formatting
|
123
|
-
# and want to redo how files may have previously been
|
123
|
+
# and want to redo how files may have previously been
|
124
124
|
# syntax marked.
|
125
125
|
def clear_file_format_cache
|
126
126
|
@@file_cache.each_pair do |fname, cache_info|
|
@@ -165,7 +165,7 @@ module LineCache
|
|
165
165
|
cache_info = @@file_cache[filename].stat
|
166
166
|
stat = File.stat(path)
|
167
167
|
if cache_info
|
168
|
-
if stat &&
|
168
|
+
if stat &&
|
169
169
|
(cache_info.size != stat.size or cache_info.mtime != stat.mtime)
|
170
170
|
result << filename
|
171
171
|
update_cache(filename, opts)
|
@@ -214,12 +214,12 @@ module LineCache
|
|
214
214
|
nil
|
215
215
|
end
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
# Return true if file_or_script is cached
|
219
219
|
def cached?(file_or_script)
|
220
|
-
if file_or_script.kind_of?(String)
|
220
|
+
if file_or_script.kind_of?(String)
|
221
221
|
@@file_cache.member?(map_file(file_or_script))
|
222
|
-
else
|
222
|
+
else
|
223
223
|
cached_script?(file_or_script)
|
224
224
|
end
|
225
225
|
end
|
@@ -227,7 +227,7 @@ module LineCache
|
|
227
227
|
def cached_script?(script)
|
228
228
|
@@script_cache.member?(script)
|
229
229
|
end
|
230
|
-
|
230
|
+
|
231
231
|
def empty?(filename)
|
232
232
|
filename=map_file(filename)
|
233
233
|
!!@@file_cache[filename].lines[:plain]
|
@@ -236,16 +236,16 @@ module LineCache
|
|
236
236
|
# Get line +line_number+ from file named +filename+. Return nil if
|
237
237
|
# there was a problem. If a file named filename is not found, the
|
238
238
|
# function will look for it in the $: array.
|
239
|
-
#
|
239
|
+
#
|
240
240
|
# Examples:
|
241
|
-
#
|
241
|
+
#
|
242
242
|
# lines = LineCache::getline('/tmp/myfile.rb')
|
243
243
|
# # Same as above
|
244
244
|
# $: << '/tmp'
|
245
245
|
# lines = LineCache.getlines('myfile.rb')
|
246
246
|
#
|
247
247
|
def getline(file_or_script, line_number, opts={})
|
248
|
-
lines =
|
248
|
+
lines =
|
249
249
|
if file_or_script.kind_of?(String)
|
250
250
|
filename = map_file(file_or_script)
|
251
251
|
filename, line_number = map_file_line(filename, line_number)
|
@@ -265,7 +265,7 @@ module LineCache
|
|
265
265
|
# if we can't get lines
|
266
266
|
def script_getlines(script, opts={})
|
267
267
|
format = opts[:output] || :plain
|
268
|
-
line_formats =
|
268
|
+
line_formats =
|
269
269
|
if @@script_cache.member?(script)
|
270
270
|
@@script_cache[script].lines
|
271
271
|
else
|
@@ -294,7 +294,7 @@ module LineCache
|
|
294
294
|
if @@file_cache.member?(filename)
|
295
295
|
lines = @@file_cache[filename].lines
|
296
296
|
if opts[:output] && !lines[format]
|
297
|
-
lines[format] =
|
297
|
+
lines[format] =
|
298
298
|
highlight_string(lines[:plain].join(''), format).split(/\n/)
|
299
299
|
end
|
300
300
|
return lines[format]
|
@@ -337,7 +337,7 @@ module LineCache
|
|
337
337
|
def remap_file_lines(from_file, to_file, range, start)
|
338
338
|
range = (range..range) if range.kind_of?(Fixnum)
|
339
339
|
to_file = from_file unless to_file
|
340
|
-
if @@file2file_remap_lines[to_file]
|
340
|
+
if @@file2file_remap_lines[to_file]
|
341
341
|
# FIXME: need to check for overwriting ranges: whether
|
342
342
|
# they intersect or one encompasses another.
|
343
343
|
@@file2file_remap_lines[to_file] << [from_file, range, start]
|
@@ -346,11 +346,11 @@ module LineCache
|
|
346
346
|
end
|
347
347
|
end
|
348
348
|
module_function :remap_file_lines
|
349
|
-
|
349
|
+
|
350
350
|
# Return any compiled method saved for a filename.
|
351
351
|
def compiled_method(filename)
|
352
352
|
if (file = map_file(filename)) && @@file_cache[file]
|
353
|
-
return @@file_cache[file].compiled_method
|
353
|
+
return @@file_cache[file].compiled_method
|
354
354
|
else
|
355
355
|
return nil
|
356
356
|
end
|
@@ -360,7 +360,7 @@ module LineCache
|
|
360
360
|
def sha1(filename)
|
361
361
|
filename = map_file(filename)
|
362
362
|
return nil unless @@file_cache.member?(filename)
|
363
|
-
return @@file_cache[filename].sha1.hexdigest if
|
363
|
+
return @@file_cache[filename].sha1.hexdigest if
|
364
364
|
@@file_cache[filename].sha1
|
365
365
|
sha1 = Digest::SHA1.new
|
366
366
|
@@file_cache[filename].lines[:plain].each do |line|
|
@@ -369,7 +369,7 @@ module LineCache
|
|
369
369
|
@@file_cache[filename].sha1 = sha1
|
370
370
|
sha1.hexdigest
|
371
371
|
end
|
372
|
-
|
372
|
+
|
373
373
|
# Return the number of lines in filename
|
374
374
|
def size(file_or_script)
|
375
375
|
cache(file_or_script)
|
@@ -399,21 +399,21 @@ module LineCache
|
|
399
399
|
return nil unless fullname
|
400
400
|
e = @@file_cache[filename]
|
401
401
|
unless e.line_numbers
|
402
|
-
e.line_numbers =
|
402
|
+
e.line_numbers =
|
403
403
|
TraceLineNumbers.lnums_for_str_array(e.lines[:plain])
|
404
404
|
e.line_numbers = false unless e.line_numbers
|
405
405
|
end
|
406
406
|
e.line_numbers
|
407
407
|
end
|
408
|
-
|
408
|
+
|
409
409
|
def map_file(file)
|
410
410
|
@@file2file_remap[file] ? @@file2file_remap[file] : file
|
411
411
|
end
|
412
412
|
|
413
413
|
def map_script(script)
|
414
|
-
if @@script2file[script]
|
415
|
-
@@script2file[script]
|
416
|
-
else
|
414
|
+
if @@script2file[script]
|
415
|
+
@@script2file[script]
|
416
|
+
else
|
417
417
|
# Doc says there's new takes an optional string parameter
|
418
418
|
# But it doesn't work for me
|
419
419
|
sha1 = Digest::SHA1.new
|
@@ -431,8 +431,8 @@ module LineCache
|
|
431
431
|
if @@file2file_remap_lines[file]
|
432
432
|
@@file2file_remap_lines[file].each do |from_file, range, start|
|
433
433
|
if range === line
|
434
|
-
from_file = from_file || file
|
435
|
-
return [from_file, start+line-range.begin]
|
434
|
+
from_file = from_file || file
|
435
|
+
return [from_file, start+line-range.begin]
|
436
436
|
end
|
437
437
|
end
|
438
438
|
end
|
@@ -444,15 +444,15 @@ module LineCache
|
|
444
444
|
end
|
445
445
|
|
446
446
|
# Update a cache entry. If something is wrong, return nil. Return
|
447
|
-
# true if the cache was updated and false if not.
|
447
|
+
# true if the cache was updated and false if not.
|
448
448
|
def update_script_cache(script, opts)
|
449
449
|
return false unless script_is_eval?(script)
|
450
450
|
string = opts[:string] || script.eval_source
|
451
451
|
lines = {:plain => string.split(/\n/)}
|
452
452
|
lines[opts[:output]] = highlight_string(string, opts[:output]) if
|
453
453
|
opts[:output]
|
454
|
-
@@script_cache[script] =
|
455
|
-
LineCacheInfo.new(nil, nil, lines, nil, opts[:sha1],
|
454
|
+
@@script_cache[script] =
|
455
|
+
LineCacheInfo.new(nil, nil, lines, nil, opts[:sha1],
|
456
456
|
opts[:compiled_method])
|
457
457
|
return true
|
458
458
|
end
|
@@ -466,7 +466,7 @@ module LineCache
|
|
466
466
|
|
467
467
|
@@file_cache.delete(filename)
|
468
468
|
path = File.expand_path(filename)
|
469
|
-
|
469
|
+
|
470
470
|
if File.exist?(path)
|
471
471
|
stat = File.stat(path)
|
472
472
|
elsif File.basename(filename) == filename
|
@@ -487,15 +487,15 @@ module LineCache
|
|
487
487
|
fp.rewind
|
488
488
|
lines = {:plain => fp.readlines}
|
489
489
|
fp.close()
|
490
|
-
lines[opts[:output]] =
|
491
|
-
highlight_string(raw_string, opts[:output]).split(/\n/) if
|
490
|
+
lines[opts[:output]] =
|
491
|
+
highlight_string(raw_string, opts[:output]).split(/\n/) if
|
492
492
|
opts[:output]
|
493
|
-
rescue
|
493
|
+
rescue
|
494
494
|
## print '*** cannot open', path, ':', msg
|
495
495
|
return nil
|
496
496
|
end
|
497
|
-
@@file_cache[filename] =
|
498
|
-
LineCacheInfo.new(File.stat(path), nil, lines, path, nil,
|
497
|
+
@@file_cache[filename] =
|
498
|
+
LineCacheInfo.new(File.stat(path), nil, lines, path, nil,
|
499
499
|
opts[:compiled_method])
|
500
500
|
@@file2file_remap[path] = filename
|
501
501
|
return true
|
@@ -503,15 +503,15 @@ module LineCache
|
|
503
503
|
end
|
504
504
|
|
505
505
|
# example usage
|
506
|
-
if __FILE__ == $0
|
507
|
-
def yes_no(var)
|
506
|
+
if __FILE__ == $0
|
507
|
+
def yes_no(var)
|
508
508
|
return var ? "" : "not "
|
509
509
|
end
|
510
510
|
|
511
511
|
lines = LineCache::getlines(__FILE__)
|
512
512
|
puts "#{__FILE__} has #{LineCache.size(__FILE__)} lines"
|
513
513
|
line = LineCache::getline(__FILE__, 6)
|
514
|
-
puts "The 6th line is\n#{line}"
|
514
|
+
puts "The 6th line is\n#{line}"
|
515
515
|
line = LineCache::remap_file(__FILE__, 'another_name')
|
516
516
|
puts LineCache::getline('another_name', 7)
|
517
517
|
|
@@ -519,23 +519,23 @@ if __FILE__ == $0
|
|
519
519
|
LineCache::update_cache(__FILE__)
|
520
520
|
LineCache::checkcache(__FILE__)
|
521
521
|
puts "#{__FILE__} has #{LineCache::size(__FILE__)} lines"
|
522
|
-
puts "#{__FILE__} trace line numbers:\n" +
|
522
|
+
puts "#{__FILE__} trace line numbers:\n" +
|
523
523
|
"#{LineCache::trace_line_numbers(__FILE__).to_a.sort.inspect}"
|
524
|
-
puts("#{__FILE__} is %scached." %
|
524
|
+
puts("#{__FILE__} is %scached." %
|
525
525
|
yes_no(LineCache::cached?(__FILE__)))
|
526
526
|
puts LineCache::stat(__FILE__).inspect
|
527
527
|
puts "Full path: #{LineCache::path(__FILE__)}"
|
528
528
|
LineCache::checkcache # Check all files in the cache
|
529
|
-
LineCache::clear_file_cache
|
530
|
-
puts("#{__FILE__} is now %scached." %
|
529
|
+
LineCache::clear_file_cache
|
530
|
+
puts("#{__FILE__} is now %scached." %
|
531
531
|
yes_no(LineCache::cached?(__FILE__)))
|
532
532
|
# digest = SCRIPT_LINES__.select{|k,v| k =~ /digest.rb$/}
|
533
533
|
# puts digest.first[0] if digest
|
534
534
|
line = LineCache::getline(__FILE__, 7)
|
535
|
-
puts "The 7th line is\n#{line}"
|
535
|
+
puts "The 7th line is\n#{line}"
|
536
536
|
LineCache::remap_file_lines(__FILE__, 'test2', (10..20), 6)
|
537
537
|
puts LineCache::getline('test2', 10)
|
538
|
-
puts "Remapped 10th line of test2 is\n#{line}"
|
538
|
+
puts "Remapped 10th line of test2 is\n#{line}"
|
539
539
|
eval("loc = Rubinius::VM::backtrace(0)[0]
|
540
540
|
puts LineCache::getline(loc.static_scope.script, 1)")
|
541
541
|
eval("loc = Rubinius::VM::backtrace(0)[0]
|