Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for spell checking code cells? #39

Open
stefaneidelloth opened this issue Oct 26, 2020 · 5 comments
Open

Support for spell checking code cells? #39

stefaneidelloth opened this issue Oct 26, 2020 · 5 comments

Comments

@stefaneidelloth
Copy link

In addition to markdown cells, I would also like to see spell checking for code cells
to find typos in variable and function names.

@krassowski
Copy link
Collaborator

I previously suggested this in #12. It is still possible to have it in this extension - one could have a list of CodeMirror token types which would be matched against. Comments are easy, variables and functions are tricky because you need to parse CamelCase, snake_case etc and do it wisely - there is no unambiguous way to parse CamelCase when it includes abbreviations etc..

@mlucool
Copy link

mlucool commented Dec 1, 2021

Hi @krassowski is it easy to add spell checks for comments here? Or is this something that should be brought up in LSP per your comment in #12 (comment)?

@krassowski
Copy link
Collaborator

So my thinking has evolved over time on this one. Three possible solutions:

  1. A quick one would be writing a custom diagnostics extension for any specific programming language; for Python you could extend pylsp with your custom plugin right now; this is easy way forward but not desirable/maintainable in the long term:
    • one would need to implement it not only for each programming language, but also for each server as there is no universal extension API that language servers support (after all they are often written in different languages)
    • to expand it to other languages, that plugin would needs to become aware of dictionaries which would duplicate the effort we already invested in this one
    • finally it would likely be pretty limited in its capabilities (simple spell check)
  2. Using a custom grammar LSP language server in addition to the programming-language server specific one; this is very powerful and there are language servers available for both LanguageTool and Grammarly; both require:
    • user to create an account and provide credentials, or
    • in case of LanguageTool (alternatively) to download few hundreds MBs + Java to install it locally, and
    • the LSP extension to support multiple servers per document (not implemented in LSP extension as for today but it is something which is high on the priority lists and should be fairly straightforward)
  3. Adding a basic code spell check in this extension; it would allow us to have a single ignore lists (for project-specific terms), and consistent behaviour (suggestions, highlighting themes, dictionaries etc). I already had a go at this one before, and from my memory:
    • it gets slightly tricky when multiple actors attempt overriding CodeMirror highlighting modes at once (which is how the spellcheck is currently implemented for Markdown); in code cells the highlighting mode is dynamically modified in response to kernel messages and by the LSP extension; adding spellchecker on top of that is an extra layer of complexity which is not fun
    • we could actually rewrite it to use the TextMarkers approach (which is what we use in LSP extension) and separating out the analysis part; this would be much more sensible than modifying the highlighting mode, and would also make it easier to port this extension to CodeMirror 5 in the future (which makes text markers even nicer).

I think that all solutions are good for specific scenarios. I will likely pursue (2) and (3) at some point (help appreciated); I do not plan to work on (1) but I think it could be sensible for someone interested in a short-term solution to explore that one.

@krassowski
Copy link
Collaborator

The CodeMirror integration had to be rewritten to support Lab 4.0 (#128) and it was actually trivial to add spellchecking for comments and strings after the rewrite, so that is now available.

@lucas-bremond
Copy link

lucas-bremond commented Jul 4, 2024

Thanks @krassowski!

Can the code cell checking behavior be disabled via a setting?

I am also facing this issue: #141, and despite using the following settings:

{
  "checkComments": false,
  "checkStrings": false
}

my code cells are being highlighted. Ideally, I'd only like the Markdown cells to be sanitized.

I am using JupyterLab 4.0.10 and Spellchecker 0.8.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants