vscode-spell-checker icon indicating copy to clipboard operation
vscode-spell-checker copied to clipboard

whitelist python modules, not just keywords

Open j9ac9k opened this issue 6 years ago • 13 comments

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.

j9ac9k avatar Mar 29 '18 20:03 j9ac9k

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"
          ]
      }
  ]

Jason3S avatar Mar 30 '18 09:03 Jason3S

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?

j9ac9k avatar Mar 30 '18 15:03 j9ac9k

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.

Jason3S avatar Apr 01 '18 09:04 Jason3S

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

On Sun, Apr 1, 2018, 2:00 AM Jason Dent [email protected] 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 .

j9ac9k avatar Apr 01 '18 15:04 j9ac9k

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.

fordp2002 avatar Aug 15 '18 13:08 fordp2002

Can this issue be closed in favor of #273?

rsyring avatar Apr 27 '19 21:04 rsyring

I'm good with that

j9ac9k avatar Apr 27 '19 23:04 j9ac9k

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

Jason3S avatar Apr 29 '19 16:04 Jason3S

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.

fordp2002 avatar Apr 29 '19 21:04 fordp2002

@fordp2002 You could try using: ignoreRegExp

# cSpell:ignoreRegExp /\bunpack\(.*/

Jason3S avatar May 02 '19 12:05 Jason3S

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.

scruel avatar Aug 07 '23 10:08 scruel

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.

morgvanny avatar Sep 19 '23 21:09 morgvanny

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

  • Members of imported modules. For example, if I import numpy as np then np.ndarray should be ignored.
  • Named parameters of functions meeting the above criteria. For example, if I call np.ndarray then dtype = ... should be ignored.

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

TechnoFairyGirl avatar May 02 '24 03:05 TechnoFairyGirl