bartosz-antosik / vscode-spellright

Multilingual, Offline and Lightweight Spellchecker for Visual Studio Code
Other
360 stars 37 forks source link

Clarify format of ignoreRegExpsByClass (strange quoting needed) #259

Open crystalfp opened 5 years ago

crystalfp commented 5 years ago

In markdown I want to ignore links text for spelling. I added regexp to select [text text](, but I have problems with the [ quoting. So, this is the entry that works:

 "spellright.ignoreRegExpsByClass": {
        "markdown": ["/{#[^}]+}/g", "/\[.+?]\\(/g"]
    },

and this is an example (SpellRight flags "montessori" as incorrect because should have the starting letter uppercased):

URL: [www.uppa.it/educazione/montessori/la-scuola-montessori](https://www.uppa.it/educazione/montessori/la-scuola-montessori/)

If I don't quote the first [ it ignores nothing (obviously correct). If I start with \\[ as the following \\( SpellRight doesn't ignore the string inside square brackets. It works if I put a single backslash \[, but the settings.json editor complains that there is an invalid escape character in the string.

So, why cannot I use the double slash? Thanks for looking! mario

crystalfp commented 5 years ago

Forgot to add that the issue is not firmly reproducible. Sometimes after VSC restart it works with one backslash, sometimes with two.

bartosz-antosik commented 5 years ago

Hi! Could you maybe provide some more information demonstrating the problem with working/not working configuration? It sounds quite strange. Sounds like an interference with other extension or something.

I could guess that although one backslash is incorrect for JSON quoting (which is the reason for this stupid quoting anyway) but it passes to the regexp filter and then is interpretted correctly. Why you cannot use two, really, no idea. If you could maybe try with only Spell Right activated could shed some more light on this.

It does work correctly with two backslashes for me:

Image 1

Image 2

Image 3

Image 4

crystalfp commented 5 years ago

For a short time I deluded myself that quoting the second square bracket fixes the problem: "/\\[.+?\\]\\(/g". Then as soon as I restarted VSC this regexp failed to ignore URLs text again

Also disabled all extensions. No change. Tried "/\\[[^\\]]+\\]\\(/g" no change. This time seems that a single initial backslash makes no difference. Also putting in first position in the array changes nothing.

Tried less elegant "/\[.+?\)/g" no change, again with all extensions disabled.

Here are two other problematic lines (shows as error 'homefolder' and 'wp'):

- Giulia Mura, Davide Diamantini, *Studenti e Rete, la cassetta degli attrezzi per insegnanti e genitori,* AICA --- Associazione Italiana per l’Informatica e il Calcolo Automatico (2016) (scaricabile da: [www.cassettadegliattrezzi.aicanet.it/homefolder/studenti-e-rete-per-il-sito.pdf](http://www.cassettadegliattrezzi.aicanet.it/homefolder/studenti-e-rete-per-il-sito.pdf)).
- “The Technology Screen: A Compilation by Three Authors”
([www.oakhavenmontessori.net/wp-content/uploads/2011/06/The-Technology-Screen.pdf](http://www.oakhavenmontessori.net/wp-content/uploads/2011/06/The-Technology-Screen.pdf)).

Thanks for your patience! mario

bartosz-antosik commented 5 years ago

I will try to investigate. What version of VSCode you use? Insiders per chance?

crystalfp commented 5 years ago

No, the normal 1.32.3 on Windows 10 x64.

depascalis commented 5 years ago

I'm having similar issues with quotes.

"/@import\\s+\\\".+\\\"/g" Works on @import "path/file.xx"

"/@import\\s+\\\'.+\\\'/g" and "/@import\\s+\\'.+\\'/g" Doesn't work on @import 'path/file.xx'

VSCode 1.32.3

edit: removed ; from matching string

crystalfp commented 5 years ago

Good example! I'm only a little confused by the backslashes. In strict Node.js the two regex are (I added the non-greedy match flag '?'):

r1 = /@import\s+".+?"/g;
r2 = /@import\s+'.+?'/g;

And they match:

s1 = '@import "path/file.xx";';
s2 = "@import 'path/file.xx';";

So putting inside ignoreRegExpsByClass the two regex means something like:

['/@import\\s+".+?"/g', " /@import\\s+'.+?'/g"]

Could you test this? Thanks!

depascalis commented 5 years ago

@crystalfp I'm also a bit confused by the backslashes and initially used two of them as in your example. I then took an expression found in the docs and changed it to fit scss imports, but with mixed results.

From the docs:

"spellright.ignoreRegExpsByClass": {
    "cpp": [ "/#include\\s+\\\".+\\\"/g" ]
}

I can't get it to work in ignoreRegExpsByClass so I put the expression below in ignoreRegExps instead which matches both strings. Though, I still need to use three backslashes for double quotes, and I don't understand why.

"spellright.ignoreRegExps": [
    "/@import\\s+(\\\"|\\').+(\\\"|\\')/g"
]

In strict JS the above is kind of the same as the search pattern @import\s+(\"|\').+(\"|\'). (Tested on www.regex101.com with JS).

I can't get your examples to work as I get json linting errors. I shuffled around the quotes a bit without any luck so please double check your search examples.

Final note: In my first reply I wrote that the search pattern matched the strings including the ; at the end, which it doesn't