Open istvans opened 7 years ago
It is possible to check only comments and strings:
Here is an example cspell.json
file. It can be added into the .vscode directory within your project.
// cSpell Settings
{
// Version of the setting file. Always 0.1
"version": "0.1",
// language - current active spelling language
"language": "en",
// words - list of words to be always considered correct
"words": [
"deprioritize"
],
// flagWords - list of words to be always considered incorrect
"flagWords": [],
"dictionaryDefinitions": [
// re-define the cpp dictionary to prevent it from loading (this is up to you)
{"name": "cpp", "file": ""}
],
// Settings per language
"languageSettings": [
{
// use with cpp or c files
"languageId": "cpp,c",
// turn off compound words, because it is only checking strings.
"allowCompoundWords": false,
// Only check comments and strings
"includeRegExpList": [
"CStyleComment",
"string"
],
// Exclude includes, because they are also strings.
"ignoreRegExpList": [
"/#include.*/"
]
}
]
}
or you can add the following to your VS Code settings.json
:
"cSpell.dictionaryDefinitions": [
// re-define the cpp dictionary to prevent it from loading (this is up to you)
{"name": "cpp", "file": ""}
],
"cSpell.languageSettings": [
{
// use with cpp or c files
"languageId": "cpp,c",
// turn off compound words, because it is only checking strings.
"allowCompoundWords": false,
// Only check comments and strings
"includeRegExpList": [
"CStyleComment",
"string"
],
// Exclude includes, because they are also strings.
"ignoreRegExpList": [
"/#include.*/"
]
}
]
I am working on adding some UI to make this a bit easier.
@istvans: I hope @Jason3S wont mind if I mention here that there is another extension (developed by me) for VSCode which does exactly what you proposed: Spell Right. It does have a syntactic parsers for groups of similar documents (textual documents, programming languages, XML style documents etc.) which allows to spell only strings and comments of programming languages (e.g. C, C++, Python and few dozens of other). It can also be mitigated to spell any combination of body (in textual documents) and/or comments and/or strings (e.g. If someone prefers not to have comments in LaTeX or HTML spelled).
So, in principle, it follows your wish - a code is not spelled, only the comments/strings are.
I think this behavior should be enabled by default - dont check variables - just comments and string literals.
I can understand that there are situations where checking only strings and comments is desirable.
@cancerberoSgx which programming language are you using and what language (English, Spanish, Russian, French, etc) do you write your code in?
I write code in English, but lots of times I write and read variables with abbreviations, numbers, internal names, etc
+1 for making this enabled by default for all languages.
I am using golang and in English. Especially in golang there are a lot of abbreviations for var names so it makes the extention hard to use.
Any progress on this? I've had to add so many words to the folder dictionaries that it's becoming kind of annoying.
@Jason3S Is there any progress on this feature - it'll be really helpful?
Was this ever implemented?
@Gabriel-p,
What do you want to achieve?
@Jason3S I wanted to restrict spelling to comments. I found a way using I believe a method you recommended in one of the issues here:
"cSpell.languageSettings": [
// This one works with python
{
"languageId": "python",
"includeRegExpList": [
"/#.*/",
"/('''|\"\"\")[^\\1]+?\\1/g"
]
}
],
Please try:
"cSpell.languageSettings": [
// This one works with python
{
"languageId": "python",
"includeRegExpList": [
"strings",
"comments"
]
}
],
That block does not work. It still checks non-comment lines
These are my settings: for python, C++ and C I have spell check only for comments and strings and for .json files only comments spell check (becaus e.g. for settings.json there are a lot of strings that raise plenty of messages in problems section.
{
"languageId": "python,cpp,c",
"includeRegExpList": [
// For Python
"comments",
"strings"
// For C++ and C
"CStyleComment",
"string"
]
},
{
"languageId": "jsonc", // (.json with comments) because most "commands" here are strings
"includeRegExpList": [
"CStyleComment",
]
}
],
Notice how you can have just one block for all you languages (add more seperated by a comma) and you just add the language-specific way of telling it to check for comments ans strings (only the json case has different block because we don't want it to check for strings there).
"The goal of this spell checker is to help with catching common spelling errors while keeping the number of false positives low." I think I'm not the only one who thinks a valid, compiling C++ code shouldn't have any underline in the editor, even if not all the method or variable names are from English. There should be an option in the VSCode user settings to restrict the scope to comments and string literals only. Just like how https://github.com/EWSoftware/VSSpellChecker does it perfectly for the big brother.