[spell-check] Allow the user to whitelist sections of a buffer… #1147
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…for spellchecking on a per-language basis.
Closes #1135.
The linked ticket weighs the pros and cons of various ways to implement this, so I'll let it do most of the talking.
You can specify values in
spell-check.grammars
that you couldn't before. Some examples:source.python comment
to spell-check Python files, but ignore everything except comments.source.python comment, source.python string
works similarly, but whitelists comments and strings within Python files.source comment
enables spell-checking for all source files, but only within comments.text
enables spell-checking for all text files: HTML (text.html.basic
), plaintext (text.plain
), and others.You'll notice that this PR touches the actual logic of matching grammars and determining which misspellings are excluded, but devotes most of itself to the task of actual scope matching.
Scope matching
Given a
ScopeDescriptor
, you'd think that it would be pretty easy to test whether it matches a given scope selector. That's what we need in this scenario; we can get the scope descriptor of a misspelling in the buffer, and we need to compare it to a selector that was specified in the package config.In fact,
ScopeDescriptor
doesn't implement any method like what I just described; near as I can tell, packages do different ad-hoc things in this scenario. It's ridiculous. TheScopeDescriptor
class has a singlegetScopesArray
method and is otherwise pretty useless.I figured I'd take time to write some scope helpers for the
spell-check
package as a test run for adding new APIs toScopeDescriptor
. At the very least there ought to be aScopeDescriptor::matches(selectorString)
function. It's also surprisingly common to see logic in the codebase that (e.g.) fails to recognize thatsource
should matchsource.js
. Atom already compromised part of the scope contract by assuming that the order of scope segments is arbitrary — that's why you might see.js.source
instead of.source.js
in yourconfig.cson
. That bell can't be unrung, but it would be great not to ring any other bells needlessly.One of those ad-hoc scope-matching strategies was being applied for the
spell-check.excludedScopes
setting, so I was able to eliminate some code by replacing it with this new strategy.There's another new ability here: you don't have to specify an exact top-level scope selector in the
grammars
setting! You can specifysource
(either on its own or as part of a selector likesource comment
) and have it matchsource.js
,source.python
,source.ts
, et cetera.Testing
New specs have been added and are passing for me locally. Existing specs also pass for me.
You should be able to test the functionality by changing your
spell-check
settings; add a value likesource comment
in the Grammars field. Verify that spell-checking is applied only to comments.