-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #614 from pulsar-edit/bundle-spell-check
[core]: Bundle `spell-check`
- Loading branch information
Showing
39 changed files
with
3,230 additions
and
16 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
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,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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*~ | ||
npm-debug.log | ||
node_modules | ||
.DS_Store | ||
package-lock.json |
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,8 @@ | ||
.cache | ||
package.json | ||
package-lock.json | ||
public | ||
__generated__ | ||
gen | ||
apollo.config.js | ||
schema.json |
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,7 @@ | ||
{ | ||
"endOfLine": "lf", | ||
"semi": true, | ||
"singleQuote": true, | ||
"tabWidth": 4, | ||
"trailingComma": "es5" | ||
} |
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 @@ | ||
[See how you can contribute](https://github.com/pulsar-edit/.github/blob/main/CONTRIBUTING.md) |
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 @@ | ||
Here are additional details for debugging for working with the library. | ||
|
||
## Plugins | ||
|
||
_Spell Check_ allows for plugins to provide additional spell checking functionality. See the `PLUGINS.md` file in the repository on how to write a plugin. | ||
|
||
## Debugging | ||
|
||
Debugging messages for this library can be enabled by going into the developer console and running the following: | ||
|
||
``` | ||
localStorage.debug = 'spell-check:*' | ||
``` | ||
|
||
A reload of the window may be required. |
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,20 @@ | ||
Copyright (c) 2014 GitHub Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,69 @@ | ||
# 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' | ||
|
||
The path given must either resolve to a singleton instance of a class or a default export in a ES6 module. | ||
|
||
class ProjectChecker | ||
# Magical code | ||
checker = new ProjectChecker() | ||
module.exports = checker | ||
|
||
For a default using Typescript: | ||
|
||
export default class ProjectChecker {} | ||
|
||
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/project/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. | ||
* check(checkArgs, text: string): [results] | ||
* This takes the entire text buffer and will be called once per buffer. | ||
* The output is an array with three parameters, all optional: `{ invertIncorrectAsCorrect: true, incorrect: [ranges], correct: [ranges] }` | ||
* The ranges are a zero-based index of a start and stop character (`[1, 23]`). | ||
* `invertIncorrectAsCorrect` means take the incorrect range and assume everything not in this list is correct. | ||
* Correct words always take precedence, even if another checker indicates a word is incorrect. | ||
* If a word or character is neither correct or incorrect, it is considered correct. | ||
* 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# Spell Check package | ||
|
||
Highlights misspelling in Pulsar and shows possible corrections. | ||
|
||
Use <kbd>cmd-shift-:</kbd> for Mac or <kbd>ctrl-shift-:</kbd> for Windows or Linux to bring up the list of corrections when your cursor is on a misspelled word. | ||
|
||
By default spell check is enabled for the following files: | ||
|
||
* Plain Text | ||
* GitHub Markdown | ||
* Git Commit Message | ||
* AsciiDoc | ||
* reStructuredText | ||
|
||
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. | ||
|
||
To enable _Spell Check_ for your current file type: put your cursor in the file, open the [Command Palette](https://github.com/pulsar-edit/command-palette) | ||
(<kbd>cmd-shift-p</kbd> for Mac or <kbd>ctrl-shift-p</kbd> for Windows or Linux), 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`. | ||
|
||
## Changing the dictionary | ||
|
||
Except for Mac, Pulsar needs to know what language to use to perform spell-checking. To list these, set the "Locales" configuration option to the [IETF tag](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry) (en-US, fr-FR, etc). More than one language can be used, simply separate them by commas. | ||
|
||
If no locale is given, then Pulsar will attempt to infer the language based on environment variables and settings. | ||
|
||
If any value is given for the "Locales", then Pulsar will not automatically add the browser language. So, if your browser is United States English (`en-US`), leaving this blank will still do US English checking. However, if it the "Locales" is set to French (`fr-FR`), then the checker will only check French. If the "Locales" is set to `en-US, fr-FR`, then both languages will be checked. | ||
|
||
### Missing Languages | ||
|
||
This plugin uses the existing system dictionaries. If a locale is selected that is not installed, a warning will pop up when a document that would be spell-checked is loaded. To disable this, either remove the incorrect language from the "Locales" configuration or clear the check on "Use Locales" to disable it entirely. | ||
|
||
To get the search paths used to look for a dictionary, make sure the "Notices Mode" is set to "console" or "both", then reload Atom. The developer's console will have the directory list. | ||
|
||
## Mac | ||
|
||
On the Mac, checking "Use System" will use the operating system's spellchecking library. This uses all of the user's loaded dictionaries and doesn't require any customization within Pulsar. | ||
|
||
Checking "Use Locales" and providing locales would use Hunspell as additional dictionaries. Having "Use Locales" checked but no locales given will do nothing. | ||
|
||
## Windows 8 and Higher | ||
|
||
For Windows 8 and 10, this package uses the Windows spell checker, so you must install the language using the regional settings before the language can be chosen inside Pulsar. | ||
|
||
![Add the language from the Language and Regions settings panel](docs/windows-10-language-settings.png) | ||
|
||
If your Windows user does not have Administration privileges, you'll need to do an extra step once the language has been added to enable the spell checker. To do so, you need to install the "Basic typing" language option by following the next steps (you'll be asked for your administrator password): | ||
|
||
![Click on the "Options" button on the added language](docs/windows-10-language-settings-2.png) | ||
|
||
![Download the "Basic Typing" language option](docs/windows-10-language-settings-3.png) | ||
|
||
Once the additional language is added, Pulsar will need to be restarted and configured to use it. Add the IEFT tag into the "Locales" setting for the language to be set. | ||
|
||
If a Hunspell dictionary is found on a path (see below), it will be used in favor of the Windows API. | ||
|
||
## Linux | ||
|
||
For all Linux-based operating systems, "Use System" does nothing. It can remained checked but has no impact. "Use Locales" is required for spell-checking. | ||
|
||
### Debian, Ubuntu, and Mint | ||
|
||
On Ubuntu, installing "Language Support" may solve problems with the dictionaries. For other distributions (or if Language Support doesn't work), you may use `apt` to install the dictionaries. | ||
|
||
``` | ||
sudo apt-get install hunspell-en-gb | ||
sudo apt-get install myspell-en-gb | ||
``` | ||
|
||
On RedHat, the following should work for Italian: | ||
|
||
``` | ||
sudo dnf install hunspell | ||
sudo dnf install hunspell-it | ||
``` | ||
|
||
You can get a list of currently installed languages with: | ||
|
||
``` | ||
/usr/bin/hunspell -D | ||
``` | ||
|
||
Pulsar may require a restart to pick up newly installed dictionaries. | ||
|
||
### Arch Linux | ||
|
||
A language may be installed by running: | ||
|
||
``` | ||
pacman -S hunspell-en_GB | ||
``` | ||
|
||
For the time being, a soft link may be required if the dictionary provided is "large". | ||
|
||
``` | ||
cd /usr/share/hunspell | ||
sudo ln -s en_GB-large.dic en_GB.dic | ||
sudo ln -s en_GB-large.aff en_GB.aff | ||
``` | ||
|
||
## Hunspell Dictionaries | ||
|
||
For all platforms, a Hunspell-compatible dictionary is also supported. To use this, a `.dic` and `.aff` need to be located in one of the default search directories or in a directory entered into "Locale paths" (multiples may be entered with commas separating them). If the appropriate files are found for the locale and "Use Locales" is checked, then the dictionary will be used. | ||
|
||
For example, if the following is set, then `/usr/share/hunspell/en_US.dic` will be used: | ||
|
||
- Use Locales: checked | ||
- Locales: `en-US` | ||
- Locale Paths: `/usr/share/hunspell` | ||
|
||
If "Locales" is not provided, then the user's current language will be inferred from environmental settings. | ||
|
||
In addition to what is provided, the following paths are checked: | ||
|
||
- `/usr/share/hunspell` (Linux only) | ||
- `/usr/share/myspell` (Linux only) | ||
- `/usr/share/myspell/dicts` (Linux only) | ||
- `/` (Mac only) | ||
- `/System/Library/Spelling` (Mac only) | ||
- `C:\` (Windows only) | ||
|
||
Dictionaries can be downloaded from various sites (such as [wooorm's repository](https://github.com/wooorm/dictionaries) or [LibreOffice's](https://github.com/LibreOffice/dictionaries)), but the file has to be renamed `locale.dic` and `locale.aff`. | ||
|
||
*Example locations to download are not an endorsement.* |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,21 @@ | ||
'.platform-darwin atom-text-editor': | ||
'cmd-:': 'spell-check:correct-misspelling' | ||
|
||
'.platform-darwin .corrections atom-text-editor': | ||
'cmd-:': 'core:cancel' | ||
|
||
'.platform-win32 atom-text-editor': | ||
'ctrl-:': 'spell-check:correct-misspelling' | ||
|
||
'.platform-win32 .corrections atom-text-editor': | ||
'ctrl-:': 'core:cancel' | ||
|
||
'.platform-linux atom-text-editor': | ||
'ctrl-:': 'spell-check:correct-misspelling' | ||
|
||
'.platform-linux .corrections atom-text-editor': | ||
'ctrl-:': 'core:cancel' | ||
|
||
'.corrections atom-text-editor[mini]': | ||
'enter': 'core:confirm' | ||
'tab': 'core:confirm' |
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,25 @@ | ||
module.exports = { | ||
isLinux() { | ||
return /linux/.test(process.platform); | ||
}, | ||
isWindows() { | ||
return /win32/.test(process.platform); | ||
}, // TODO: Windows < 8 or >= 8 | ||
isDarwin() { | ||
return /darwin/.test(process.platform); | ||
}, | ||
preferHunspell() { | ||
return !!process.env.SPELLCHECKER_PREFER_HUNSPELL; | ||
}, | ||
|
||
isSystemSupported() { | ||
return this.isWindows() || this.isDarwin(); | ||
}, | ||
isLocaleSupported() { | ||
return true; | ||
}, | ||
|
||
useLocales() { | ||
return this.isLinux() || this.isWindows() || this.preferHunspell(); | ||
}, | ||
}; |
Oops, something went wrong.