pragmagic/vscode-nim

strformat not highlighted correct in some cases

Opened this issue · 3 comments

The syntax improvements introduced by #105 (comment) don't display correct in the following two cases with "incorrect coloring" :

import strformat

var a = fmt"{""}"          # incorrect code; correct coloring 
var b = fmt"{"a"}"         # incorrect code; incorrect coloring
var c = fmt"{'a'}"         # correct code; correct coloring
var d = fmt"""{"""a"""}""" # incorrect code; incorrect coloring

syntax

For me it seemed like I could use "..." inside the strformat because the coloring implied it also the compiler error wasn't clear, then I saw that the color highlight needs changes for this case.

Another one is:

echo fmt"{{}}"

And also with round brackets for the call it isnt highlighted correct (see tests in strformat.nim)

I found, that fmt used with triple double quotes can break coloring in following lines.
Examples where fmt breaks coloring:

fmt_nok

when fmt is removed, coloring back to the norm:

fmt_ok

hit this again:

  block: # nim --eval
    let opt = "--hints:off"
    check fmt"""{nim} {opt} --eval:"echo defined(nimscript)"""".execCmdEx == ("true\n", 0)
    check fmt"""{nim} r {opt} --eval:"echo defined(c)"""".execCmdEx == ("true\n", 0)
    check fmt"""{nim} r -b:js {opt} --eval:"echo defined(js)"""".execCmdEx == ("true\n", 0)

  block: # `hintProcessing` dots should not interfere with `static: echo` + friends
    let cmd = fmt"""{nim} r {defaultHintsOff} --hint:processing -f --eval:"static: echo 1+1""""
    let (outp, exitCode) = execCmdEx(cmd, options = {poStdErrToStdOut})
    template check3(cond) = doAssert cond, $(outp,)
    doAssert exitCode == 0
    let lines = outp.splitLines
    check3 lines.len == 3
    when not defined(windows): # xxx: on windows, dots not properly handled, gives: `....2\n\n`
      check3 lines[0].isDots
      check3 lines[1] == "2"
      check3 lines[2] == ""
    else:
      check3 "2" in outp

=>
https://files.gitter.im/5fb473f1d73408ce4ff44cee/mPUt/image.png

it works fine in sublime text (which uses https://github.com/Varriount/NimLime for syntax definitions, just like github via github linguist)

EDIT

looks like the culprit is that syntax definition doesn't understand when there are more than 3 consecutive " (which are allowed); the highliting is correct with:

    let cmd = fmt"""{nim} r {defaultHintsOff} --hint:processing -f --eval:"static: echo 1+1""""
=>
    let cmd = fmt"""{nim} r {defaultHintsOff} --hint:processing -f --eval:"static: echo 1+1" """