Class: Ruber::SyntaxChecker::Extension

Inherits:
Qt::Object
  • Object
show all
Includes:
Extension
Defined in:
plugins/syntax_checker/syntax_checker.rb,
plugins/syntax_checker/syntax_checker.rb,
plugins/syntax_checker/syntax_checker.rb

Constant Summary

SyntaxErrorMark =
KTextEditor::MarkInterface.markType09
DEFAULT_CHECK_OPTIONS =
{:format => true, :update => true}

Instance Attribute Summary (collapse)

Attributes included from Extension

plugin

Instance Method Summary (collapse)

Methods included from Extension

#query_close, #save_settings, #shutdown

Signal Summary

API for feature syntax_checker

Constructor Details

- (Extension) initialize(prj)

A new instance of Extension



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'plugins/syntax_checker/syntax_checker.rb', line 232

def initialize prj
  super
  @status = :unknown
  @errors = nil
  @doc = prj.document
  @project = prj
  connect @doc, SIGNAL('document_url_changed(QObject*)'), self, SLOT(:create_syntax_checker)
  connect @doc, SIGNAL('document_saved_or_uploaded(QObject*, bool)'), self,
      SLOT(:auto_check)
  connect @doc, SIGNAL('text_changed(QObject*)'), self, SLOT(:start_waiting)
  create_syntax_checker
  connect @doc, SIGNAL(:activated), self, SLOT(:document_activated)
  connect @doc, SIGNAL(:deactivated), self, SLOT(:delete_timer)
  connect Ruber[:syntax_checker], SIGNAL(:settings_changed), self, SLOT(:load_settings)
  connect Ruber[:syntax_checker], SIGNAL(:syntax_checker_added), self, SLOT(:create_syntax_checker_if_needed)
  connect Ruber[:syntax_checker], SIGNAL(:syntax_checker_removed), self, SLOT(:create_syntax_checker)
  load_settings
  document_activated false if @doc.active?
end

Instance Attribute Details

- (Object) errors (readonly)

Returns the value of attribute errors



226
227
228
# File 'plugins/syntax_checker/syntax_checker.rb', line 226

def errors
  @errors
end

- (Object) status (readonly)

Returns the value of attribute status



228
229
230
# File 'plugins/syntax_checker/syntax_checker.rb', line 228

def status
  @status
end

Instance Method Details

- (Object) auto_check (private)



284
285
286
# File 'plugins/syntax_checker/syntax_checker.rb', line 284

def auto_check
  check_syntax if @project[:syntax_checker, :auto_check]
end

Slot Signature:

auto_check()

- (Object) check_syntax(options = DEFAULT_CHECK_OPTIONS)



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'plugins/syntax_checker/syntax_checker.rb', line 248

def check_syntax options = DEFAULT_CHECK_OPTIONS
  options = DEFAULT_CHECK_OPTIONS.merge options
  if @checker
    begin
      errors = @checker.check_syntax @doc.text, options[:format]
      res = {:errors => errors, :result => errors ? :incorrect : :correct}
    rescue SyntaxNotChecked 
      res = {:result => :unknown, :errors => nil}
    end
  else res = {:result => :unknown, :errors => nil}
  end
  if options[:format] and options[:update]
    @errors = errors
    @status = res[:result]
    if errors
  #Uncomment the following lines when KTextEditor::MarkInterface#marks works
  #           iface = @doc.interface('mark_interface')
  #           errors.each do |e|
  #             iface.add_mark e.line, SyntaxErrorMark if e.line
  #           end
    end
    emit syntax_checked(@doc) if options[:format]
  end
  res
end

Slot Signature:

check_syntax()

- (Object) create_syntax_checker (private)



278
279
280
281
282
# File 'plugins/syntax_checker/syntax_checker.rb', line 278

def create_syntax_checker
  checker_cls = Ruber[:syntax_checker].syntax_checker_for @doc
  @checker = checker_cls ? checker_cls.new(@doc) : nil
  auto_check
end

Slot Signature:

create_syntax_checker()

- (Object) create_syntax_checker_if_needed (private)



287
288
289
290
291
# File 'plugins/syntax_checker/syntax_checker.rb', line 287

def create_syntax_checker_if_needed
  unless @checker
    create_syntax_checker
  end
end

Slot Signature:

create_syntax_checker_if_needed()

- (Object) delete_timer (private)



297
298
299
300
301
# File 'plugins/syntax_checker/syntax_checker.rb', line 297

def delete_timer
  @timer.stop
  @timer.delete_later
  @timer = nil
end

Slot Signature:

delete_timer()

- (Object) document_activated(check_syntax = true) (private)



289
290
291
292
293
294
# File 'plugins/syntax_checker/syntax_checker.rb', line 289

def document_activated check_syntax = true
  @timer = Qt::Timer.new self
  @timer.singleShot = true
  connect @timer, SIGNAL(:timeout), self, SLOT(:auto_check)
  auto_check if check_syntax
end

Slot Signature:

document_activated()

- (Object) load_settings (private)



304
305
306
# File 'plugins/syntax_checker/syntax_checker.rb', line 304

def load_settings
  @time_interval = Ruber[:config][:syntax_checker, :time_interval]
end

Slot Signature:

load_settings()

- (Object) remove_from_project



271
272
273
274
# File 'plugins/syntax_checker/syntax_checker.rb', line 271

def remove_from_project
  super
  @timer.stop if @timer
end

- (Object) start_waiting (private)



309
310
311
# File 'plugins/syntax_checker/syntax_checker.rb', line 309

def start_waiting
  @timer.start 1_000 * @time_interval if @time_interval > 0 and @doc.active?
end

Slot Signature:

start_waiting()

Signal Details

- syntax_checked(QObject* arg1)