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.
Updated plugin-based implementation from provided feedback.
- Switched to a task-based system. - Reworked the plugins so they return full paths to a `require`able instance. - Modified the activation/deactivation to create a single background task for all checking. - Initial request for corrections will have a delay while an in-process manager is created. - Added flow control via `send` and `emit` to communicate configuration changes with the task process. - Changed to a word-based searching implementation. - Added a simplified tokenizer that includes some accented characters. - An internal cache is used for a single round of check to reduce overhead. - Removed the use of integer ranges and simplified processing logic. - Removed a number of `console.log` calls used for debugging. - Updated documentation. - Split out plugin creation into a separate document with a reference in the `README.md`.
- Loading branch information
Showing
11 changed files
with
409 additions
and
239 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,65 @@ | ||
# Plugins | ||
|
||
The `spell-check` allows for additional dictionaries to be used at the same time using Atom's `providedServices` element in the `package.json` file. | ||
|
||
"providedServices": { | ||
"spell-check": { | ||
"versions": { | ||
"1.0.0": "nameOfFunctionToProvideSpellCheck" | ||
} | ||
} | ||
} | ||
|
||
The `nameOfFunctionToProvideSpellCheck` function may return either a single `require`able path or an array of them. This must be an absolute path to a class that provides a checker instance (below). | ||
|
||
provideSpellCheck: -> | ||
require.resolve './project-checker.coffee' | ||
|
||
The path given must resolve to a singleton instance of a class. | ||
|
||
class ProjectChecker | ||
# Magical code | ||
checker = new ProjectChecker() | ||
module.exports = checker | ||
|
||
See the `spell-check-project` for an example implementation. | ||
|
||
# Checker | ||
|
||
A common parameter type is `checkArgs`, this is a hash with the following signature. | ||
|
||
args = { | ||
projectPath: "/absolute/path/to/project/root, | ||
relativePath: "relative/path/from/projet/root" | ||
} | ||
|
||
Below the required methods for the checker instance. | ||
|
||
* getId(): string | ||
* This returns the canonical identifier for this plugin. Typically, this will be the package name with an optional suffix for options, such as `spell-check-project` or `spell-check:en-US`. This identifier will be used for some control plugins (such as `spell-check-project`) to enable or disable the plugin. | ||
* This will also used to pass information from the Atom process into the background task once that is implemented. | ||
* getPriority(): number | ||
* Determines how significant the plugin is for information with lower numbers being more important. Typically, user-entered data (such as the config `knownWords` configuration or a project's dictionary) will be lower than system data (priority 100). | ||
* isEnabled(): boolean | ||
* If this returns true, then the plugin will considered for processing. | ||
* providesSpelling(checkArgs): boolean | ||
* If this returns true, then the plugin will be included when looking for incorrect and correct words via the `check` function. | ||
* checkArray(checkArgs, words: string[]): boolean?[] | ||
* 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. | ||
* The output is an array of the same length as words which has three values, one for each word given: | ||
* `null`: The checker provides no opinion on correctness. | ||
* `false`: The word is specifically false. | ||
* `true`: The word is correctly spelled. | ||
* True always takes precedence, then false. If every checker provides `null`, then the word is considered spelled correctly. | ||
* providesSuggestions(checkArgs): boolean | ||
* If this returns true, then the plugin will be included when querying for suggested words via the `suggest` function. | ||
* suggest(checkArgs, word: string): [suggestion: string] | ||
* Returns a list of suggestions for a given word ordered so the most important is at the beginning of the list. | ||
* providesAdding(checkArgs): boolean | ||
* If this returns true, then the dictionary allows a word to be added to the dictionary. | ||
* getAddingTargets(checkArgs): [target] | ||
* Gets a list of targets to show to the user. | ||
* The `target` object has a minimum signature of `{ label: stringToShowTheUser }`. For example, `{ label: "Ignore word (case-sensitive)" }`. | ||
* This is a list to allow plugins to have multiple options, such as adding it as a case-sensitive or insensitive, temporary verses configuration, etc. | ||
* add(buffer, target, word) | ||
* Adds a word to the dictionary, using the target for identifying which one is used. |
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
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,17 +1,34 @@ | ||
# 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 | ||
# This is the task local handler for the manager so we can reuse the manager | ||
# throughout the life of the task. | ||
SpellCheckerManager = require './spell-check-manager.coffee' | ||
instance = SpellCheckerManager | ||
instance.isTask = true | ||
|
||
# Because of the heavy use of configuration options for the packages and our | ||
# inability to listen/access config settings from this process, we need to get | ||
# the settings in a roundabout manner via sending messages through the process. | ||
# This has an additional complexity because other packages may need to send | ||
# messages through the main `spell-check` task so they can update *their* | ||
# checkers inside the task process. | ||
# | ||
# Below the dispatcher for all messages from the server. The type argument is | ||
# require, how it is handled is based on the type. | ||
process.on "message", (message) -> | ||
switch | ||
when message.type is "global" then loadGlobalSettings message.global | ||
when message.type is "checker" then instance.addCheckerPath message.checkerPath | ||
# Quietly ignore unknown message types. | ||
|
||
misspellings = instance.check data.args, data.text | ||
{id: data.args.id, misspellings} | ||
# This handles updating the global configuration settings for | ||
# `spell-check` along with the built-in checkers (locale and knownWords). | ||
loadGlobalSettings = (data) -> | ||
instance.setGlobalArgs data | ||
|
||
# This is the function that is called by the views whenever data changes. It | ||
# returns with the misspellings along with an identifier that will let the task | ||
# wrapper route it to the appropriate view. | ||
backgroundCheck = (data) -> | ||
misspellings = instance.check data, data.text | ||
{id: data.id, misspellings: misspellings.misspellings} | ||
|
||
module.exports = backgroundCheck |
Oops, something went wrong.