highlight: do not add html classes to unresolved local variables
authorJean Privat <jean@pryen.org>
Tue, 3 Jun 2014 13:47:59 +0000 (09:47 -0400)
committerJean Privat <jean@pryen.org>
Tue, 3 Jun 2014 13:47:59 +0000 (09:47 -0400)
Eg. this avoid highlighting to only highlight the fist occurrence of `x`
in the following AST if no semantic analysis is run

~~~
var x = 5
print x
~~~

Now, either none, or both `x` are identified as variables according to how
mush semantic analysis is performed.

Signed-off-by: Jean Privat <jean@pryen.org>

src/highlight.nit

index c9dec07..cd400bd 100644 (file)
@@ -666,9 +666,9 @@ end
 redef class AVarFormExpr
        redef fun decorate_tag(v, res, token)
        do
-               res.add_class("nc_v")
                var variable = self.variable
                if variable == null then return null
+               res.add_class("nc_v")
                return variable.infobox(v)
        end
 end
@@ -676,9 +676,9 @@ end
 redef class AVardeclExpr
        redef fun decorate_tag(v, res, token)
        do
-               res.add_class("nc_v")
                var variable = self.variable
                if variable == null then return null
+               res.add_class("nc_v")
                return variable.infobox(v)
        end
 end
@@ -687,9 +687,9 @@ redef class AForExpr
        redef fun decorate_tag(v, res, token)
        do
                if not token isa TId then return null
-               res.add_class("nc_v")
                var vs = variables
                if vs == null then return null
+               res.add_class("nc_v")
                var idx = n_ids.index_of(token)
                var variable = vs[idx]
                return variable.infobox(v)
@@ -699,11 +699,11 @@ end
 redef class AParam
        redef fun decorate_tag(v, res, token)
        do
-               res.add_class("nc_v")
                var mp = mparameter
                if mp == null then return null
                var variable = self.variable
                if variable == null then return null
+               res.add_class("nc_v")
                return variable.infobox(v)
        end
 end