[gnome-code-assistance] [backends/css] Report column



commit e15571725ac1c3a09887651f2d6ce220921bac7a
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Wed Nov 13 20:28:56 2013 +0100

    [backends/css] Report column

 backends/css/app.rb |   29 +++++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/backends/css/app.rb b/backends/css/app.rb
index 86747dc..3404fec 100644
--- a/backends/css/app.rb
+++ b/backends/css/app.rb
@@ -25,6 +25,31 @@ else
     require 'sass'
 end
 
+class CssParser < Sass::SCSS::CssParser
+    def self.expected(scanner, expected, line)
+        pos = scanner.pos
+        eos = scanner.eos?
+
+        if eos
+            pos -= 1
+            line -= 1
+
+            nlpos = scanner.string.rindex("\n", pos - 1)
+        else
+            nlpos = scanner.string.rindex("\n", pos)
+        end
+
+        begin
+            super(scanner, expected, line)
+        rescue Sass::SyntaxError => e
+            e.modify_backtrace({:column => pos - nlpos})
+            raise e
+        end
+    end
+
+    @sass_script_parser = Class.new(Sass::Script::CssParser)
+    @sass_script_parser.send(:include, Sass::SCSS::ScriptParser)
+end
 
 module Gnome::CodeAssistance
     module Css
@@ -37,7 +62,7 @@ module Gnome::CodeAssistance
                 f = File.new(doc.data_path, 'r')
 
                 begin
-                    parser = Sass::SCSS::CssParser.new(f.read(), doc.path)
+                    parser = CssParser.new(f.read(), doc.path)
                     parser.parse()
                 rescue Sass::SyntaxError => e
                     doc.diagnostics = [make_diagnostic(e)]
@@ -47,7 +72,7 @@ module Gnome::CodeAssistance
             end
 
             def make_diagnostic(e)
-                loc = SourceLocation.new(e.sass_line, 0)
+                loc = SourceLocation.new(e.sass_line, e.sass_backtrace.first[:column] || 0)
                 Diagnostic.new(Diagnostic::Severity::ERROR, [], [loc.to_range], e.to_s)
             end
         end


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]