Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit f47f54c

Browse files
committed
Converting checking to use multi-integer-range with a task-based checking.
* Updated unit tests to verify functionality of multiple plugin responses. * Taught system checking how to identify correct as well as incorrect. * Updated documentation to reflect plugin logic.
1 parent dff766e commit f47f54c

16 files changed

+414
-186
lines changed

PLUGINS.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ A common parameter type is `checkArgs`, this is a hash with the following signat
3030

3131
args = {
3232
projectPath: "/absolute/path/to/project/root,
33-
relativePath: "relative/path/from/projet/root"
33+
relativePath: "relative/path/from/project/root"
3434
}
3535

3636
Below the required methods for the checker instance.
@@ -44,13 +44,13 @@ Below the required methods for the checker instance.
4444
* If this returns true, then the plugin will considered for processing.
4545
* providesSpelling(checkArgs): boolean
4646
* If this returns true, then the plugin will be included when looking for incorrect and correct words via the `check` function.
47-
* checkArray(checkArgs, words: string[]): boolean?[]
48-
* This takes an array of words in a given line. This will be called once for every line inside the buffer. It also also not include words already requested earlier in the buffer.
49-
* The output is an array of the same length as words which has three values, one for each word given:
50-
* `null`: The checker provides no opinion on correctness.
51-
* `false`: The word is specifically false.
52-
* `true`: The word is correctly spelled.
53-
* True always takes precedence, then false. If every checker provides `null`, then the word is considered spelled correctly.
47+
* check(checkArgs, text: string): [results]
48+
* This takes the entire text buffer and will be called once per buffer.
49+
* The output is an array with three parameters, all optional: `{ invertIncorrectAsCorrect: true, incorrect: [ranges], correct: [ranges] }`
50+
* The ranges are a zero-based index of a start and stop character (`[1, 23]`).
51+
* `invertIncorrectAsCorrect` means take the incorrect range and assume everything not in this list is correct.
52+
* Correct words always take precedence, even if another checker indicates a word is incorrect.
53+
* If a word or character is neither correct or incorrect, it is considered correct.
5454
* providesSuggestions(checkArgs): boolean
5555
* If this returns true, then the plugin will be included when querying for suggested words via the `suggest` function.
5656
* suggest(checkArgs, word: string): [suggestion: string]

README.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
# Spell Check Package [![Build Status](https://travis-ci.org/atom/spell-check.svg?branch=master)](https://travis-ci.org/atom/spell-check)
1+
# Spell Check package
2+
[![OS X Build Status](https://travis-ci.org/atom/spell-check.svg?branch=master)](https://travis-ci.org/atom/spell-check) [![Windows Build Status](https://ci.appveyor.com/api/projects/status/1620a5reqw6kdolv/branch/master?svg=true)](https://ci.appveyor.com/project/Atom/spell-check/branch/master) [![Dependency Status](https://david-dm.org/atom/spell-check.svg)](https://david-dm.org/atom/spell-check)
3+
4+
**This is a test package. Disable the built-in `spell-check` module before using it.**
25

36
Highlights misspelling in Atom and shows possible corrections.
47

5-
Use `cmd+shift+:` to bring up the list of corrections when your cursor is on a
6-
misspelled word.
8+
Use <kbd>cmd-shift-:</kbd> to bring up the list of corrections when your cursor is on a misspelled word.
79

810
By default spell check is enabled for the following files:
911

@@ -12,17 +14,10 @@ By default spell check is enabled for the following files:
1214
* Git Commit Message
1315
* AsciiDoc
1416

15-
You can override this from the _Spell Check_ settings in the Settings view
16-
(<kbd>cmd+,</kbd>). The Grammars config option is a list of scopes for which the package
17-
will check for spelling errors.
18-
19-
To enable _Spell Check_ for your current file type: put your cursor in the file,
20-
open the [Command Palette](https://github.com/atom/command-palette)
21-
(<kbd>cmd+shift+p</kbd>), and run the `Editor: Log Cursor Scope` command. This
22-
will trigger a notification which will contain a list of scopes. The first scope
23-
that's listed is the one you should add to the list of scopes in the settings
24-
for the _Spell Check_ package. Here are some examples: `source.coffee`,
25-
`text.plain`, `text.html.basic`.
17+
You can override this from the _Spell Check_ settings in the Settings View (<kbd>cmd-,</kbd>). The Grammars config option is a list of scopes for which the package will check for spelling errors.
18+
19+
To enable _Spell Check_ for your current file type: put your cursor in the file, open the [Command Palette](https://github.com/atom/command-palette)
20+
(<kbd>cmd-shift-p</kbd>), and run the `Editor: Log Cursor Scope` command. This will trigger a notification which will contain a list of scopes. The first scope that's listed is the one you should add to the list of scopes in the settings for the _Spell Check_ package. Here are some examples: `source.coffee`, `text.plain`, `text.html.basic`.
2621

2722
## Changing the dictionary
2823

appveyor.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: "{build}"
2+
3+
platform: x64
4+
5+
branches:
6+
only:
7+
- master
8+
9+
clone_depth: 10
10+
11+
skip_tags: true
12+
13+
environment:
14+
APM_TEST_PACKAGES:
15+
16+
matrix:
17+
- ATOM_CHANNEL: stable
18+
- ATOM_CHANNEL: beta
19+
20+
install:
21+
- ps: Install-Product node 4
22+
23+
build_script:
24+
- ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/atom/ci/master/build-package.ps1'))
25+
26+
test: off
27+
deploy: off

lib/known-words-checker.coffee

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class KnownWordsChecker
1919
getId: -> "spell-check:known-words"
2020
getName: -> "Known Words"
2121
getPriority: -> 10
22-
isEnabled: -> true
22+
isEnabled: -> @spelling.sensitive or @spelling.insensitive
23+
2324
getStatus: -> "Working correctly."
2425
providesSpelling: (args) -> true
2526
providesSuggestions: (args) -> true
@@ -33,16 +34,6 @@ class KnownWordsChecker
3334
ranges.push {start: token.start, end: token.end}
3435
{correct: ranges}
3536

36-
checkArray: (args, words) ->
37-
results = []
38-
for word, index in words
39-
result = @check args, word
40-
if result.correct.length is 0
41-
results.push null
42-
else
43-
results.push true
44-
results
45-
4637
suggest: (args, word) ->
4738
@spelling.suggest word
4839

lib/main.coffee

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ module.exports =
1212

1313
# Set up our callback to track when settings changed.
1414
that = this
15-
@task.on "spell-check:settings-changed", (ignore) ->
16-
console.log("updating views because of change", that)
15+
@task.on "spell-check:settings-changed", () ->
1716
that.updateViews()
1817

1918
# Since the spell-checking is done on another process, we gather up all the
@@ -30,19 +29,19 @@ module.exports =
3029
@sendGlobalArgs()
3130

3231
atom.config.onDidChange 'spell-check.locales', ({newValue, oldValue}) ->
33-
that.globalArgs.locales = atom.config.get('spell-check.locales')
32+
that.globalArgs.locales = newValue
3433
that.sendGlobalArgs()
3534
atom.config.onDidChange 'spell-check.localePaths', ({newValue, oldValue}) ->
36-
that.globalArgs.localePaths = atom.config.get('spell-check.localePaths')
35+
that.globalArgs.localePaths = newValue
3736
that.sendGlobalArgs()
3837
atom.config.onDidChange 'spell-check.useLocales', ({newValue, oldValue}) ->
39-
that.globalArgs.useLocales = atom.config.get('spell-check.useLocales')
38+
that.globalArgs.useLocales = newValue
4039
that.sendGlobalArgs()
4140
atom.config.onDidChange 'spell-check.knownWords', ({newValue, oldValue}) ->
42-
that.globalArgs.knownWords = atom.config.get('spell-check.knownWords')
41+
that.globalArgs.knownWords = newValue
4342
that.sendGlobalArgs()
4443
atom.config.onDidChange 'spell-check.addKnownWords', ({newValue, oldValue}) ->
45-
that.globalArgs.addKnownWords = atom.config.get('spell-check.addKnownWords')
44+
that.globalArgs.addKnownWords = newValue
4645
that.sendGlobalArgs()
4746

4847
# Hook up the UI and processing.
@@ -56,13 +55,14 @@ module.exports =
5655
# background checking and a cached view of the in-process manager for
5756
# getting corrections. We used a function to a function because scope
5857
# wasn't working properly.
59-
spellCheckView = new SpellCheckView(editor, @task, (ignore) => @getInstance @globalArgs)
58+
spellCheckView = new SpellCheckView(editor, @task, () => @getInstance @globalArgs)
6059

6160
# save the {editor} into a map
6261
editorId = editor.id
6362
spellCheckViews[editorId] = {}
6463
spellCheckViews[editorId]['view'] = spellCheckView
6564
spellCheckViews[editorId]['active'] = true
65+
spellCheckViews[editorId]['editor'] = editor
6666
@viewsByEditor.set editor, spellCheckView
6767

6868
deactivate: ->
@@ -74,6 +74,12 @@ module.exports =
7474
@commandSubscription.dispose()
7575
@commandSubscription = null
7676

77+
# Clear out the known views.
78+
for editorId of spellCheckViews
79+
view = spellCheckViews[editorId]
80+
view['editor'].destroy()
81+
spellCheckViews = {}
82+
7783
# While we have WeakMap.clear, it isn't a function available in ES6. So, we
7884
# just replace the WeakMap entirely and let the system release the objects.
7985
@viewsByEditor = new WeakMap

lib/spell-check-handler.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ instance.isTask = true
1313
#
1414
# Below the dispatcher for all messages from the server. The type argument is
1515
# require, how it is handled is based on the type.
16-
process.on "message", (message) ->
16+
process.on "message", (message) =>
1717
switch
1818
when message.type is "global" then loadGlobalSettings message.global
1919
when message.type is "checker" then instance.addCheckerPath message.checkerPath

0 commit comments

Comments
 (0)