streetsidesoftware / vscode-spell-checker

A simple source code spell checker for code
https://streetsidesoftware.github.io/vscode-spell-checker/
Other
1.4k stars 126 forks source link

whitelist python modules, not just keywords #203

Open j9ac9k opened 6 years ago

j9ac9k commented 6 years ago

cSpell flags itertools, functools and ctypes as being misspelled when the python dictionary is activated (and virtually any other module I try and import that is not in the en_us dictionary).

from itertools import combinations
from functools import reduce
from ctypes import *

I have verified the python dictionary is enabled.

I would suggest adding not just the python keywords, but the names of modules at least within the standard library to be whitelisted.

Love the plugin, thanks for the awesome work.

Jason3S commented 6 years ago

Thank you. This is also an issue with Go and C++.

A half fix would be to ignore imports:

"cSpell.languageSettings": [
      {
          // use with Python files
          "languageId": "python",
          // Exclude code.
          "ignoreRegExpList": [
              "/^\\s*from.*import/gm"
          ]
      }
  ]
j9ac9k commented 6 years ago

adding built in modules to the dictionary file won't help with non-standard modules (which ignoring the import line would).

I'm new to VSCode so I have no idea what the difficulty here would be, but is there a way to look into the words from intellisense and whitelist them?

Jason3S commented 6 years ago

Sadly, extensions do not have access to the intellisense results or even the code formatting results. Both of these could have been used to exclude imported modules.

I am busy with an alternate method. That is to have the spell checker understand language grammars and exclude things based upon the grammar instead of just checking all words.

But that is a rather extensive change and it will take some time before it is production ready.

j9ac9k commented 6 years ago

Sounds good, if there is anything I can do to help, let me know.

On Sun, Apr 1, 2018, 2:00 AM Jason Dent notifications@github.com wrote:

Sadly, extensions do not have access to the intellisense results or even the code formatting results. Both of these could have been used to exclude imported modules.

I am busy with an alternate method. That is to have the spell checker understand language grammars and exclude things based upon the grammar instead of just checking all words.

But that is a rather extensive change and it will take some time before it is production ready.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Jason-Rev/vscode-spell-checker/issues/203#issuecomment-377773039, or mute the thread https://github.com/notifications/unsubscribe-auth/AAnc_mcRUZG6eBO7RX9E-kqT98gZ55Ckks5tkJcagaJpZM4TA9kE .

fordp2002 commented 6 years ago

Can I just add a comment here my python code (:

from struct import unpack
...
default = unpack('<BBHBBBB', data)[2]

Spell checking that first parameter of unpack makes no sense, I would be happy to add a manual rule to stop this being checked, but adding the string to the dictionary makes no sense.

rsyring commented 5 years ago

Can this issue be closed in favor of #273?

j9ac9k commented 5 years ago

I'm good with that

Jason3S commented 5 years ago

Can I just add a comment here my python code (:

from struct import unpack
...
default = unpack('<BBHBBBB', data)[2]

@fordp2002 you can tell the spell checker to ignore that string:

# cspell:ignore BBHBBBB
default = unpack('<BBHBBBB', data)[2]

See: In Document Settings Ignore Words

fordp2002 commented 5 years ago

I may have hundreds of unpack calls all of which should be ignored I would not litter my code with extra lines just to stop the spell checker logging errors.

Jason3S commented 5 years ago

@fordp2002 You could try using: ignoreRegExp

# cSpell:ignoreRegExp /\bunpack\(.*/
scruel commented 1 year ago

Same issue, for third-party libraries, we won't modify them usually, so it's meaningless for checking words in them, but spell checker will still check them (like softmax, optim). Regular expression won't fulfill our requirements, because we may give alias to imported libraries.

morgvanny commented 12 months ago

Sadly, extensions do not have access to the intellisense results or even the code formatting results. Both of these could have been used to exclude imported modules.

I am busy with an alternate method. That is to have the spell checker understand language grammars and exclude things based upon the grammar instead of just checking all words.

But that is a rather extensive change and it will take some time before it is production ready.

Is this still the case now with the Language Server Protocol? I don't have experience with making extensions so I could be totally misunderstanding, but I think that's meant to make it much easier for extensions to access things like intellisense results (or maybe the underlying information that intellisense results are derived from, I'm not sure). I could explore this more and see if I can help, but please let me know if I'm off base, or if you can already see a clear path to a solution on this.

TechnoFairyGirl commented 4 months ago

Would it be possible to understand the language syntax well enough to exclude cases like the following?

The above examples are Python-centric, but the concept applies to other languages as well.