tpope / vim-rails

rails.vim: Ruby on Rails power tools
http://www.vim.org/scripts/script.php?script_id=1567
4.11k stars 384 forks source link

Colorizing escape sequences showing in Rails log for railslogModel #481

Closed stuartpalmer closed 7 years ago

stuartpalmer commented 7 years ago

Commit e567014 appears to have broken concealing the leading escape characters in Rails logs for railslogModel. What used to show as:

  AdminUser Load (0.3ms)  SELECT  "admin_users".* FROM "admin_users" WHERE "admin_users"."full_name" = $1 LIMIT $2  [["full_name", "System"], ["LIMIT", 1]]

now shows as:

  ^[[1m^[[36mAdminUser Load (0.3ms)  SELECT  "admin_users".* FROM "admin_users" WHERE "admin_users"."full_name" = $1 LIMIT $2  [["full_name", "System"], ["LIMIT", 1]]

I would attempt a fix but I'm not comfortable enough with the syntax to understand the intent of the changes. These appear to be the relevant changes:

-  syn match   railslogRender      '\%(^\s*\%(\e\[[0-9;]*m\)\=\)\@<=\%(Started\|Processing\|Rendering\|Rendered\|Redirected\|Completed\)\>'
-  syn match   railslogComment     '^\s*# .*'
-  syn match   railslogModel       '\%(^\s*\%(\e\[[0-9;]*m\)*\)\@<=\u\%(\w\|:\)* \%(Load\%( Including Associations\| IDs For Limited Eager Loading\)\=\|Columns\|Exists\|Count\|Create\|Update\|Destroy\|Delete all\)\>' skipwhite nextgroup=railslogModelNum,railslogEscapeMN
-  syn match   railslogModel       '\%(^\s*\%(\e\[[0-9;]*m\)*\)\@<=\%(SQL\|CACHE\)\>' skipwhite nextgroup=railslogModelNum,railslogEscapeMN
+  syn cluster railslogLine        contains=railslogRender,railslogModel,railslogDeprecation
+  syn match   railslogLineStart   '\%(^\s*\%(\e\[[0-9;]*m\)\=\)\@<=' nextgroup=@railslogLineStart
+  syn match   railslogQfFileName  "^[^|]*|\@=" nextgroup=railslogQfSeparator
+  syn match   railslogQfSeparator "|" nextgroup=railslogQfLineNr contained
+  syn match   railslogQfLineNr    "[^|]*" contained contains=railslogQfError
+  syn match   railslogQfError     "error" contained
+  syn match   railslogRender      '\%(\%(^\||\)\s*\%(\e\[[0-9;]*m\)\=\)\@<=\%(Started\|Processing\|Rendering\|Rendered\|Redirected\|Completed\)\>'
+  syn match   railslogComment     '\%(^\||\)\@<=\s*# .*'
+  syn match   railslogModel       '\%(\%(^\||\)\s*\%(\e\[[0-9;]*m\)*\)\@<=\u\%(\w\|:\)* \%(Load\%( Including Associations\| IDs For Limited Eager Loading\)\=\|Columns\|Exists\|Count\|Create\|Update\|Destroy\|Delete all\)\>' skipwhite nextgroup=railslogModelNum,railslogEscapeMN
+  syn match   railslogModel       '\%(\%(^\||\)\s*\%(\e\[[0-9;]*m\)*\)\@<=\%(SQL\|CACHE\)\>' skipwhite nextgroup=railslogModelNum,railslogEscapeMN
tpope commented 7 years ago

I wrote it just 17 days ago but even I'm not sure what I was going for with the whole railslogLine bit. Hopefully fixed.

P.S. Did you try :Clogfile? I'm trying to move away from bare log file editing, which is why I missed the breakage.

stuartpalmer commented 7 years ago

Thanks for the quick fix! Yeah, your future self and all that...

I did try :Clogfile and it works nicely. I was working on a custom log formatter which is why I was directly editing.