redcar-dev 0.12.12dev-java → 0.12.13dev-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.
Files changed (33) hide show
  1. data/Rakefile +1 -1
  2. data/lib/redcar.rb +1 -1
  3. data/lib/tasks/app-bundle.rake +63 -0
  4. data/plugins/application/lib/application.rb +3 -0
  5. data/plugins/project_search/lib/project_search/commands.rb +5 -4
  6. data/plugins/project_search/lib/project_search/images/spinner.gif +0 -0
  7. data/plugins/project_search/lib/project_search/lucene_index.rb +1 -1
  8. data/plugins/project_search/lib/project_search/stylesheets/style.css +105 -37
  9. data/plugins/project_search/lib/project_search/views/_file.html.erb +4 -3
  10. data/plugins/project_search/lib/project_search/views/index.html.erb +42 -16
  11. data/plugins/project_search/lib/project_search/word_search.rb +23 -14
  12. data/plugins/project_search/lib/project_search/word_search_controller.rb +40 -29
  13. metadata +3 -22
  14. data/plugins/javascript/features/fixtures/test.js +0 -0
  15. data/plugins/javascript/features/fixtures/test2.js +0 -5
  16. data/plugins/javascript/features/step_definitions/javascript_steps.rb +0 -16
  17. data/plugins/javascript/features/support/env.rb +0 -18
  18. data/plugins/javascript/features/syntax_check_javascript.feature +0 -70
  19. data/plugins/javascript/lib/syntax_check/javascript.rb +0 -58
  20. data/plugins/javascript/plugin.rb +0 -7
  21. data/plugins/javascript/vendor/jslint.js +0 -539
  22. data/plugins/mirah/README +0 -7
  23. data/plugins/mirah/features/fixtures/test.mirah +0 -2
  24. data/plugins/mirah/features/syntax_check_mirah.feature +0 -46
  25. data/plugins/mirah/lib/mirah.rb +0 -43
  26. data/plugins/mirah/lib/mirah/my_error_handler.rb +0 -22
  27. data/plugins/mirah/lib/mirah/repl_mirror.rb +0 -50
  28. data/plugins/mirah/lib/mirah/syntax_checker.rb +0 -38
  29. data/plugins/mirah/plugin.rb +0 -8
  30. data/plugins/mirah/spec/mirah/repl_mirror_spec.rb +0 -188
  31. data/plugins/mirah/spec/spec_helper.rb +0 -5
  32. data/plugins/mirah/vendor/mirah-parser.jar +0 -0
  33. data/plugins/project_search/TODO.md +0 -11
@@ -1,8 +1,12 @@
1
1
 
2
2
  class ProjectSearch
3
3
  class WordSearch
4
+ java_import org.apache.lucene.util.Version
5
+ java_import org.apache.lucene.analysis.standard.StandardAnalyzer
6
+ java_import org.apache.lucene.queryParser.QueryParser
7
+
4
8
  attr_reader :query_string, :context_size, :project
5
-
9
+
6
10
  def initialize(project, query_string, match_case, context_size)
7
11
  @project = project
8
12
  @query_string = query_string
@@ -25,6 +29,13 @@ class ProjectSearch
25
29
  def regex
26
30
  @regex ||= begin
27
31
  regexp_text = Regexp.escape(@query_string)
32
+ # Replace Lucene wildcards with non-greedy Ruby regex equivalents
33
+ # TODO: determine best (expected?) way of handling phrases
34
+ p [regexp_text]
35
+ regexp_text = regexp_text.gsub(/\\\s+or\\\s+/i,"|").gsub('\\*','.*?').gsub('\\?','.').gsub(/\\\s+/,".*?")
36
+ p regexp_text
37
+ # Match to the next word boundary if the last char is '*'
38
+ regexp_text += "\\b" if regexp_text =~ /\.\*\?$/
28
39
  match_case? ? /#{regexp_text}/ : /#{regexp_text}/i
29
40
  end
30
41
  end
@@ -79,24 +90,22 @@ class ProjectSearch
79
90
  def results
80
91
  @results ||= generate_results
81
92
  end
82
-
83
- def bits
84
- query_string.
85
- gsub(/[^\w]/, " ").
86
- gsub("_", " ").
87
- split(/\s/).
88
- map {|b| b.strip}.
89
- reject {|b| b == "" or org.apache.lucene.analysis.standard.StandardAnalyzer::STOP_WORDS_SET.to_a.include?(b)}
93
+
94
+ def formatted_query
95
+ parser = QueryParser.new(
96
+ Version::LUCENE_29,
97
+ "contents",
98
+ StandardAnalyzer.new(Version::LUCENE_29)
99
+ )
100
+ parser.parse(query_string).to_s
90
101
  end
91
-
102
+
92
103
  def doc_ids
93
104
  @doc_ids ||= begin
94
105
  index = ProjectSearch.indexes[project.path].lucene_index
95
106
  doc_ids = nil
96
- bits.each do |bit|
97
- new_doc_ids = index.find(:contents => bit.downcase).map {|doc| doc.id }
98
- doc_ids = doc_ids ? (doc_ids & new_doc_ids) : new_doc_ids
99
- end
107
+ p [:formatted_query, formatted_query]
108
+ doc_ids = index.find(formatted_query).map {|doc| doc.id}
100
109
  doc_ids.reject {|doc_id| Redcar::Project::FileList.hide_file_path?(doc_id) }
101
110
  end
102
111
  end
@@ -8,11 +8,11 @@ class ProjectSearch
8
8
  def title
9
9
  TITLE
10
10
  end
11
-
11
+
12
12
  def search_copy
13
13
  "Search for complete words only"
14
14
  end
15
-
15
+
16
16
  def show_literal_match_option?
17
17
  false
18
18
  end
@@ -20,31 +20,31 @@ class ProjectSearch
20
20
  def num_context_lines
21
21
  settings['context_lines']
22
22
  end
23
-
23
+
24
24
  def plugin_root
25
25
  File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
26
26
  end
27
-
27
+
28
28
  def settings
29
29
  ProjectSearch.storage
30
30
  end
31
-
31
+
32
32
  def match_case?
33
33
  ProjectSearch.storage['match_case']
34
34
  end
35
-
35
+
36
36
  def context?
37
37
  ProjectSearch.storage['with_context']
38
38
  end
39
-
39
+
40
40
  def context_size
41
41
  context? ? num_context_lines : 0
42
42
  end
43
-
43
+
44
44
  def default_query
45
45
  doc.selected_text if doc && doc.selection?
46
46
  end
47
-
47
+
48
48
  def index
49
49
  render('index')
50
50
  end
@@ -79,20 +79,20 @@ class ProjectSearch
79
79
  @thread = nil
80
80
  super
81
81
  end
82
-
82
+
83
83
  def render(view, bg=nil)
84
84
  erb(view).result(bg || binding)
85
85
  end
86
-
86
+
87
87
  def render_file(bg)
88
88
  @erb ||= erb("_file")
89
89
  @erb.result(bg)
90
90
  end
91
-
91
+
92
92
  def erb(view)
93
93
  ERB.new(File.read(File.join(File.dirname(__FILE__), "views", "#{view.to_s}.html.erb")))
94
94
  end
95
-
95
+
96
96
  def doc
97
97
  Redcar.app.focussed_window.focussed_notebook_tab.edit_view.document rescue false
98
98
  end
@@ -107,11 +107,11 @@ class ProjectSearch
107
107
  ProjectSearch.storage['recent_queries'] = add_or_move_to_top(query, ProjectSearch.storage['recent_queries'])
108
108
  ProjectSearch.storage['match_case'] = (match_case == 'true')
109
109
  ProjectSearch.storage['with_context'] = (with_context == 'true')
110
-
110
+
111
111
  project = Redcar::Project::Manager.focussed_project
112
-
112
+
113
113
  @word_search = WordSearch.new(project, query, match_case?, context_size)
114
-
114
+
115
115
  # kill any existing running search to prevent memory bloat
116
116
  Thread.kill(@thread) if @thread
117
117
  @thread = nil
@@ -122,7 +122,7 @@ class ProjectSearch
122
122
  line_num = 0
123
123
  have_prepared_table = false
124
124
  have_results = false
125
-
125
+
126
126
  @word_search.on_file_results do |hits|
127
127
  next unless hits.any?
128
128
  have_results = true
@@ -130,26 +130,29 @@ class ProjectSearch
130
130
  line_num += hits.length
131
131
  set_file_count(file_num)
132
132
  set_line_count(line_num)
133
- file = hits.first.file
134
-
133
+
135
134
  unless have_prepared_table
136
135
  prepare_results_table
137
136
  have_prepared_table = true
138
137
  end
139
138
 
139
+ file = hits.first.file
140
+ add_nav_link(file,hits.length)
141
+
142
+
140
143
  file_html = render_file(binding)
141
144
  escaped_file_html = escape_javascript(file_html)
142
145
  execute("$('#results table tr:last').after(\"#{escaped_file_html}\");")
143
146
  end
144
-
147
+
145
148
  @word_search.generate_results
146
-
149
+
147
150
  if have_results
148
151
  remove_initial_blank_tr
149
152
  else
150
153
  render_no_results
151
154
  end
152
-
155
+
153
156
  hide_spinner
154
157
  Thread.kill(@thread) if @thread
155
158
  @thread = nil
@@ -160,29 +163,37 @@ class ProjectSearch
160
163
  end
161
164
  nil
162
165
  end
163
-
166
+
164
167
  def initialize_search_output
168
+ image_path = File.expand_path(File.join(plugin_root, %w(lib project_search images)))
165
169
  execute("$('#cached_query').val(\"#{escape_javascript(@word_search.query_string)}\");")
166
- execute("$('#results').html(\"<div id='no_results'>Searching...</div>\");")
170
+ execute("$('#results').html(\"<div id='no_results'>Searching...<br/><img id='spinner' src='#{image_path}/spinner.gif' style='display:none;'/></div>\");")
167
171
  execute("$('#spinner').show();")
168
172
  execute("$('#results_summary').hide();")
169
173
  execute("$('#file_results_count').html(0);")
170
174
  execute("$('#line_results_count').html(0);")
171
175
  end
172
-
176
+
173
177
  def prepare_results_table
174
178
  execute("if ($('#results table').size() == 0) { $('#results').html(\"<table><tr></tr></table>\"); }")
175
179
  execute("if ($('#results_summary').first().is(':hidden')) { $('#results_summary').show(); }")
180
+ execute("$('#files_nav').html('<li></li>');")
176
181
  end
177
-
182
+
178
183
  def set_file_count(value)
179
184
  execute("$('#file_results_count').html(\"#{value}\");")
180
185
  end
181
-
186
+
182
187
  def set_line_count(value)
183
188
  execute("$('#line_results_count').html(\"#{value}\");")
184
189
  end
185
-
190
+
191
+ def add_nav_link(file,hit_count)
192
+ file = File.basename(file)
193
+ link= file.gsub(/\.|:|\\|\//,"")
194
+ execute("$('#files_nav').append('<li><a id=\"link_#{link}\" class=\"file_link\">#{file} (#{hit_count})</a></li>');")
195
+ end
196
+
186
197
  def remove_initial_blank_tr
187
198
  execute("$('#results table tr:first').remove();")
188
199
  end
@@ -191,7 +202,7 @@ class ProjectSearch
191
202
  result = "<div id='no_results'>No results were found using the search terms you provided.</div>"
192
203
  execute("$('#results').html(\"#{escape_javascript(result)}\");")
193
204
  end
194
-
205
+
195
206
  def hide_spinner
196
207
  execute("$('#spinner').hide();")
197
208
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: redcar-dev
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 7
5
- version: 0.12.12dev
5
+ version: 0.12.13dev
6
6
  platform: java
7
7
  authors:
8
8
  - Daniel Lucraft
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-08-14 00:00:00 +01:00
13
+ date: 2011-08-19 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -250,6 +250,7 @@ files:
250
250
  - lib/redcar/ruby_extensions.rb
251
251
  - lib/redcar/runner.rb
252
252
  - lib/redcar/usage.rb
253
+ - lib/tasks/app-bundle.rake
253
254
  - plugins/application/plugin.rb
254
255
  - plugins/application/features/main_menu.feature
255
256
  - plugins/application/features/navigation_history.feature
@@ -570,14 +571,6 @@ files:
570
571
  - plugins/java/features/fixtures/lib/classes.jar
571
572
  - plugins/java/features/support/env.rb
572
573
  - plugins/java/lib/syntax_check/java.rb
573
- - plugins/javascript/plugin.rb
574
- - plugins/javascript/features/syntax_check_javascript.feature
575
- - plugins/javascript/features/fixtures/test.js
576
- - plugins/javascript/features/fixtures/test2.js
577
- - plugins/javascript/features/step_definitions/javascript_steps.rb
578
- - plugins/javascript/features/support/env.rb
579
- - plugins/javascript/lib/syntax_check/javascript.rb
580
- - plugins/javascript/vendor/jslint.js
581
574
  - plugins/key_bindings/plugin.rb
582
575
  - plugins/key_bindings/lib/key_bindings.rb
583
576
  - plugins/key_bindings/spec/spec_helper.rb
@@ -608,17 +601,6 @@ files:
608
601
  - plugins/macros/spec/spec_helper.rb
609
602
  - plugins/macros/spec/macros/predictive/sequence_finder_spec.rb
610
603
  - plugins/macros/views/macro_manager.html.erb
611
- - plugins/mirah/plugin.rb
612
- - plugins/mirah/README
613
- - plugins/mirah/features/syntax_check_mirah.feature
614
- - plugins/mirah/features/fixtures/test.mirah
615
- - plugins/mirah/lib/mirah.rb
616
- - plugins/mirah/lib/mirah/my_error_handler.rb
617
- - plugins/mirah/lib/mirah/repl_mirror.rb
618
- - plugins/mirah/lib/mirah/syntax_checker.rb
619
- - plugins/mirah/spec/spec_helper.rb
620
- - plugins/mirah/spec/mirah/repl_mirror_spec.rb
621
- - plugins/mirah/vendor/mirah-parser.jar
622
604
  - plugins/my_plugin/plugin.rb
623
605
  - plugins/my_plugin/lib/my_plugin.rb
624
606
  - plugins/open_default_app/plugin.rb
@@ -689,7 +671,6 @@ files:
689
671
  - plugins/project/spec/project/adapters/remote_protocols/sftp_spec.rb
690
672
  - plugins/project/views/bulk_rename.html.erb
691
673
  - plugins/project_search/plugin.rb
692
- - plugins/project_search/TODO.md
693
674
  - plugins/project_search/features/word_search.feature
694
675
  - plugins/project_search/features/support/env.rb
695
676
  - plugins/project_search/lib/project_search.rb
File without changes
@@ -1,5 +0,0 @@
1
- boo foo
2
- baz
3
- bee
4
- baux
5
- beau
@@ -1,16 +0,0 @@
1
- When /^I save the tab (\d+) times and wait (\d+) seconds each time$/ do |count,time|
2
- count = count.to_i
3
- time = time.to_i
4
- (1..count).each do |i|
5
- begin
6
- When "I save the tab"
7
- When "I wait #{time} seconds"
8
- rescue => e
9
- add_exception(e)
10
- end
11
- end
12
- end
13
-
14
- Then /^the tab should not have thrown SWT concurrency exceptions$/ do
15
- exception_count.should == 0
16
- end
@@ -1,18 +0,0 @@
1
- After do
2
- # Truncate the test file
3
- File.open(File.expand_path("../../fixtures/test.js", __FILE__), "w")
4
- @exceptions = 0
5
- end
6
-
7
- Before do
8
- @exceptions = 0
9
- end
10
-
11
- def add_exception(e)
12
- @exceptions = @exceptions + 1
13
- p e.message
14
- end
15
-
16
- def exception_count
17
- @exceptions
18
- end
@@ -1,70 +0,0 @@
1
- Feature: Syntax Checking for JavaScript
2
- As a user
3
- I want to get annotations on syntax errors in JavaScript files
4
- #
5
- # Background:
6
- # When I have opened "plugins/javascript/features/fixtures/test.js"
7
- #
8
- # Scenario: A syntax-clean JavaScript file has no syntax error annotations
9
- # When I replace the contents with "var foo = 1;"
10
- # And I save the tab
11
- # Then the tab should not have annotations
12
- #
13
- # Scenario: A syntax-error in a JavaScript file should cause syntax error annotations
14
- # When I replace the contents with "var foo = 1;\nbar"
15
- # And I save the tab
16
- # And I wait 2 seconds
17
- # Then the tab should have annotations
18
- # And the tab should have an annotation on line 2
19
- #
20
- # Scenario: Fixing a syntax-error in a JavaScript file should cause syntax error annotations to vanish
21
- # When I replace the contents with "var foo = 1;\nbar"
22
- # And I save the tab
23
- # And I wait 2 seconds
24
- # Then the tab should have annotations
25
- # When I replace the contents with "var foo = 1;\nvar bar;"
26
- # And I save the tab
27
- # Then the tab should not have annotations
28
- #
29
- # Scenario: Checking for syntax errors on a file with syntax errors should not cause concurrency errors
30
- # When I replace the contents with "foo\nbar\nfunction\nbax\nboo\nbonne"
31
- # And I save the tab 10 times and wait 2 seconds each time
32
- # Then the tab should not have thrown SWT concurrency exceptions
33
- #
34
- # Scenario: Checking for syntax errors between two different error-throwing files should not cause concurrency errors
35
- # When I replace the contents with "foo\nbar\nfunction\nbax\nboo\nbonne"
36
- # And I have opened "plugins/javascript/features/fixtures/test2.js"
37
- # And I replace the contents with "boo foo\nbaz\nbee\nbaux\nbeau"
38
- # And I save the tab
39
- # And I wait 1 seconds
40
- # And I switch up a tab
41
- # And I save the tab
42
- # And I wait 1 seconds
43
- # And I switch down a tab
44
- # And I save the tab
45
- # And I wait 1 seconds
46
- # And I switch up a tab
47
- # And I save the tab
48
- # And I wait 1 seconds
49
- # Then the tab should not have thrown SWT concurrency exceptions
50
- # And the tab should have annotations
51
- # When I switch down a tab
52
- # Then the tab should have annotations
53
- #
54
- # Scenario: Checking rapidly for syntax errors between two files should not cause concurrency errors
55
- # When I replace the contents with "foo\nbar\nfunction\nbax\nboo\nbonne"
56
- # And I have opened "plugins/javascript/features/fixtures/test2.js"
57
- # And I replace the contents with "boo foo\nbaz\nbee\nbaux\nbeau"
58
- # And I save the tab
59
- # And I switch up a tab
60
- # And I save the tab
61
- # And I switch down a tab
62
- # And I save the tab
63
- # And I switch up a tab
64
- # And I save the tab
65
- # And I wait 5 seconds
66
- # Then the tab should not have thrown SWT concurrency exceptions
67
- # And the tab should have annotations
68
- # When I switch down a tab
69
- # Then the tab should have annotations
70
- #
@@ -1,58 +0,0 @@
1
-
2
- module Redcar
3
- module SyntaxCheck
4
- class JavaScript < Checker
5
- supported_grammars "JavaScript", "JavaScript (Rails)",
6
- "jQuery (JavaScript)", "HTML"
7
-
8
- def jslint_path
9
- File.join(File.dirname(__FILE__),'..','..','vendor','jslint.js')
10
- end
11
-
12
- def rhino_path
13
- File.join(Redcar.asset_dir,'js.jar')
14
- end
15
-
16
- def main_method
17
- "org.mozilla.javascript.tools.shell.Main"
18
- end
19
-
20
- def check(*args)
21
- path = manifest_path(doc)
22
- name = File.basename(path)
23
- if t = JavaScript.thread and t.alive?
24
- if t[:doc] and t[:doc] == doc
25
- t.exit
26
- SyntaxCheck.remove_syntax_error_annotations(doc.edit_view)
27
- end
28
- end
29
- JavaScript.thread=Thread.new do
30
- SyntaxCheck.remove_syntax_error_annotations(doc.edit_view)
31
- Thread.current[:doc] = doc
32
- begin
33
- output = `java -cp #{rhino_path} #{main_method} #{jslint_path} #{path}`
34
- output.each_line do |line|
35
- if line =~ /Lint at line (\d+) character (\d+): (.*)/
36
- SyntaxCheck::Error.new(doc, $1.to_i-1, $3).annotate
37
- sleep 1
38
- end
39
- end
40
- rescue Object => e
41
- SyntaxCheck.message(
42
- "An error occurred while parsing #{name}: #{e.message}",:error)
43
- end
44
- end
45
- end
46
-
47
- private
48
-
49
- def self.thread=(thread)
50
- @thread=thread
51
- end
52
-
53
- def self.thread
54
- @thread
55
- end
56
- end
57
- end
58
- end