This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed spell-checking to be plugin-based.
* Changed the package to allow for external packages to provide additional checking. (Closes #74) - Disabled the task-based handling because of passing plugins. - Two default plugins are included: system-based dictionaries and "known words". - Suggestions and "add to dictionary" are also provided via interfaces. (Closes #10) - Modified various calls so they are aware of the where the buffer is located. * Modified system to allow for multiple plugins/checkers to identify correctness. - Incorrect words must be incorrect for all checkers. - Any checker that treats a word as valid is considered valid for the buffer. * Extracted system-based dictionary support into separate checker. - System dictionaries can now check across multiple system locales. - Locale selection can be changed via package settings. (Closes #21) - Multiple locales can be selected. (Closes #11) - External search paths can be used for Linux and OS X. - Default language is based on the process environment, with a fallback to the browser, before finally using `en-US` as a fallback. * Extracted hard-coded approved list into a separate checker. - User can add additional "known words" via settings. - Added an option to add more known words via the suggestion dialog. * Updated ignore files and added EditorConfig settings for development. * Various coffee-centric formatting.
- Loading branch information
Showing
15 changed files
with
783 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
max_line_length = 80 | ||
tab_width = 2 | ||
trim_trailing_whitespace = true | ||
|
||
[*.{js,ts,coffee}] | ||
quote_type = single |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
*~ | ||
npm-debug.log | ||
node_modules | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
class KnownWordsChecker | ||
enableAdd: false | ||
spelling: null | ||
checker: null | ||
|
||
constructor: (knownWords) -> | ||
# Set up the spelling manager we'll be using. | ||
spellingManager = require "spelling-manager" | ||
@spelling = new spellingManager.TokenSpellingManager | ||
@checker = new spellingManager.BufferSpellingChecker @spelling | ||
|
||
# Set our known words. | ||
@setKnownWords knownWords | ||
|
||
deactivate: -> | ||
console.log(@getid() + "deactivating") | ||
|
||
getId: -> "spell-check:known-words" | ||
getName: -> "Known Words" | ||
getPriority: -> 10 | ||
isEnabled: -> true | ||
getStatus: -> "Working correctly." | ||
providesSpelling: (args) -> true | ||
providesSuggestions: (args) -> true | ||
providesAdding: (args) -> @enableAdd | ||
|
||
check: (args, text) -> | ||
ranges = [] | ||
checked = @checker.check text | ||
for token in checked | ||
if token.status is 1 | ||
ranges.push {start: token.start, end: token.end} | ||
{correct: ranges} | ||
|
||
suggest: (args, word) -> | ||
@spelling.suggest word | ||
|
||
getAddingTargets: (args) -> | ||
if @enableAdd | ||
[{sensitive: false, label: "Add to " + @getName()}] | ||
else | ||
[] | ||
|
||
add: (args, target) -> | ||
c = atom.config.get 'spell-check.knownWords' | ||
c.push target.word | ||
atom.config.set 'spell-check.knownWords', c | ||
|
||
setAddKnownWords: (newValue) -> | ||
@enableAdd = newValue | ||
|
||
setKnownWords: (knownWords) -> | ||
# Clear out the old list. | ||
@spelling.sensitive = {} | ||
@spelling.insensitive = {} | ||
|
||
# Add the new ones into the list. | ||
if knownWords | ||
for ignore in knownWords | ||
@spelling.add ignore | ||
|
||
module.exports = KnownWordsChecker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,17 @@ | ||
SpellChecker = require 'spellchecker' | ||
# Background task for checking the text of a buffer and returning the | ||
# spelling. Since this can be an expensive operation, it is intended to be run | ||
# in the background with the results returned asynchronously. | ||
backgroundCheck = (data) -> | ||
# Load a manager in memory and let it initialize. | ||
SpellCheckerManager = require './spell-check-manager.coffee' | ||
instance = SpellCheckerManager | ||
instance.locales = data.args.locales | ||
instance.localePaths = data.args.localePaths | ||
instance.useLocales = data.args.useLocales | ||
instance.knownWords = data.args.knownWords | ||
instance.addKnownWords = data.args.addKnownWords | ||
|
||
module.exports = ({id, text}) -> | ||
SpellChecker.add("GitHub") | ||
SpellChecker.add("github") | ||
misspellings = instance.check data.args, data.text | ||
{id: data.args.id, misspellings} | ||
|
||
misspelledCharacterRanges = SpellChecker.checkSpelling(text) | ||
|
||
row = 0 | ||
rangeIndex = 0 | ||
characterIndex = 0 | ||
misspellings = [] | ||
while characterIndex < text.length and rangeIndex < misspelledCharacterRanges.length | ||
lineBreakIndex = text.indexOf('\n', characterIndex) | ||
if lineBreakIndex is -1 | ||
lineBreakIndex = Infinity | ||
|
||
loop | ||
range = misspelledCharacterRanges[rangeIndex] | ||
if range and range.start < lineBreakIndex | ||
misspellings.push([ | ||
[row, range.start - characterIndex], | ||
[row, range.end - characterIndex] | ||
]) | ||
rangeIndex++ | ||
else | ||
break | ||
|
||
characterIndex = lineBreakIndex + 1 | ||
row++ | ||
|
||
{id, misspellings} | ||
module.exports = backgroundCheck |
Oops, something went wrong.