Class: Ruber::SyntaxChecker::SyntaxCheckerPlugin
Overview
Plugin object for the sytax_checker
feature
Defined Under Namespace
Classes: ErrorDescription
Constant Summary
- COLORS =
Colors used to display the different states of the document
{ :correct => Qt::Color.new(Qt.green), :error => Qt::Color.new(Qt.red), :unknown => Qt::Color.new(Qt.gray) }
Constants inherited from Plugin
Instance Attribute Summary
Attributes included from PluginLike
Instance Method Summary (collapse)
-
- (String) format_error_message(error)
Generates an error message from an error object.
-
- (SyntaxCheckerPlugin) initialize(psf)
constructor
Creates an instance of the plugin.
-
- (nil) load_settings
Loads the settings.
-
- (SyntaxCheckerPlugin) mark_document_as(status, errors = [])
Tells the plugin to display the result of the syntax check for the current document.
-
- (SyntaxCheckerPlugin) register_syntax_checker(cls, mimetypes, patterns = [])
Registers a new syntax checker.
-
- (Boolean) remove_syntax_checker(cls)
Removes a registered syntax checker.
-
- (SyntaxCheckerPlugin) shutdown
Prepares the plugin for application shutdown.
-
- (SyntaxCheckerPlugin) start_timer
Starts the timer for the automatic check.
-
- (SyntaxCheckerPlugin) stop_timer
Stops the timer for the automatic check.
-
- (Object?) syntax_checker_for(doc)
Instantiates an appropriate syntax checker for a document.
-
- (SyntaxCheckerPlugin) unload
Prepares the plugin to be unloaded.
Methods inherited from Plugin
Methods included from PluginLike
#add_extensions_to_project, #add_options_to_project, #add_widgets_to_project, #create_tool_widget, #delayed_initialize, #initialize_plugin, #plugin_name, #query_close, #register_options, #register_with_project, #remove_extensions_from_project, #remove_from_project, #remove_options_from_project, #remove_widgets_from_project, #restore_session, #save_settings, #session_data, #setup_action, #setup_actions, #update_project
Signal Summary
-
- timeout
Signal emitted when it’s time to perform an automatic syntax check.
API for class SyntaxChecker::SyntaxCheckerPlugin
Methods API
Constructor Details
- (SyntaxCheckerPlugin) initialize(psf)
Creates an instance of the plugin
It also registers the two built-in syntax checkers
plugin
108 109 110 111 112 113 114 115 116 117 |
# File 'plugins/syntax_checker/syntax_checker.rb', line 108 def initialize psf super @availlable_syntax_checkers = {} register_syntax_checker RubySyntaxChecker, 'application/x-ruby', %w[*.rb rakefile Rakefile] register_syntax_checker YamlSyntaxChecker, [], %w[*.yml *.yaml] @led = SyntaxResultWidget.new Ruber[:main_window].. @led mark_document_as :unknown end |
Instance Method Details
- (String) format_error_message(error)
Generates an error message from an error object
The returned string contains the error message together with information about the line and the column (if known) where the error happened
where the error happened, formatted in a standard way
238 239 240 241 242 243 |
# File 'plugins/syntax_checker/syntax_checker.rb', line 238 def error res = "Line #{error.line}" res += " Col #{error.column}" if error.column res += ": #{error.}" res end |
- (nil) load_settings
Loads the settings
If automatic checking has been enabled, a timer is created; if it has been disabled, the timer is destroyed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'plugins/syntax_checker/syntax_checker.rb', line 276 def load_settings auto_check = Ruber[:config][:syntax_checker, :automatic_check] if auto_check and !@timer @timer = Qt::Timer.new self @timer.interval = 1000 connect @timer, SIGNAL(:timeout), self, SIGNAL(:timeout) @timer.start if Ruber[:main_window].current_document elsif !auto_check @timer.disconnect self @timer.dispose @timer = nil end nil end |
- (SyntaxCheckerPlugin) mark_document_as(status, errors = [])
Tells the plugin to display the result of the syntax check for the current document
:error
or :unknown
(if no syntax checker was availlable for the document)
instances of class ErrorDescription describing each of the
syntax error which where found in the document. This argument is only used if
status is :error
145 146 147 148 149 150 151 152 153 154 |
# File 'plugins/syntax_checker/syntax_checker.rb', line 145 def mark_document_as status, errors = [] msg = case status when :correct then 'Syntax OK' when :unknown then 'Document type unknown' when :error then errors.map{|e| e}.join "\n" end @led.tool_tip = msg @led.color = COLORS[status] self end |
- (SyntaxCheckerPlugin) register_syntax_checker(cls, mimetypes, patterns = [])
Registers a new syntax checker.
A syntax checker is an object which analyzes the contents of a document and tells whether its syntax is correct or not. To register it with the plugin, you need to pass the object’s class, toghether with the mimetypes and file patterns it should be used to check syntax for, to this method. When a new document with the appropriate mimetype or file name is created, a new instances of the syntax checker class will be created.
The syntax checker class must have the following characteristics:
- its constructor should take the document as only parameter
- it should have a
check
method which takes a string (corresponding to the text of the document) and performs the syntax check on it. It must return a string with all the information needed to retrieve the information about the single errors. - it should have a
convert_check_result
method, which takes the string returned by thecheck
method and converts it to an array of ErrorDescription objects, with each object containing the information about a single error. If the document doesn’t contain any syntax error, this method should return an empty array.
for. It has the format described in Document#file_type_match? for. It has the format described in Document#file_type_match?
187 188 189 190 191 192 |
# File 'plugins/syntax_checker/syntax_checker.rb', line 187 def register_syntax_checker cls, mimetypes, patterns = [] if @availlable_syntax_checkers.include? cls raise ArgumentError, "class #{cls} has already been registered as syntax checker" else @availlable_syntax_checkers[cls] = [mimetypes, patterns] end end |
- (Boolean) remove_syntax_checker(cls)
Removes a registered syntax checker.
Nothing is done if the syntax checker hadn’t been registered.
registered
203 204 205 206 |
# File 'plugins/syntax_checker/syntax_checker.rb', line 203 def remove_syntax_checker cls res = @availlable_syntax_checkers.delete cls res.to_bool end |
- (SyntaxCheckerPlugin) shutdown
Prepares the plugin for application shutdown
212 213 214 215 |
# File 'plugins/syntax_checker/syntax_checker.rb', line 212 def shutdown @timer.stop self end |
- (SyntaxCheckerPlugin) start_timer
Starts the timer for the automatic check
250 251 252 253 254 255 256 |
# File 'plugins/syntax_checker/syntax_checker.rb', line 250 def start_timer if @timer @timer.stop @timer.start end self end |
- (SyntaxCheckerPlugin) stop_timer
Stops the timer for the automatic check
263 264 265 266 |
# File 'plugins/syntax_checker/syntax_checker.rb', line 263 def stop_timer @timer.stop if @timer self end |
- (Object?) syntax_checker_for(doc)
Instantiates an appropriate syntax checker for a document
associated with a file or no syntax checker has been registered for doc’s extension or mimetype
127 128 129 130 131 132 |
# File 'plugins/syntax_checker/syntax_checker.rb', line 127 def syntax_checker_for doc checker_cls = @availlable_syntax_checkers.find! do |cls, data| doc.file_type_match?(*data) ? cls : nil end checker_cls ? checker_cls.new(doc) : nil end |
- (SyntaxCheckerPlugin) unload
Prepares the plugin to be unloaded
222 223 224 225 226 |
# File 'plugins/syntax_checker/syntax_checker.rb', line 222 def unload Ruber[:main_window].. @led super self end |
Signal Details
- timeout
Signal emitted when it’s time to perform an automatic syntax check