Skip to content

Commit

Permalink
"fr" language support (incl. single quotes) + faster spellcheck <= re…
Browse files Browse the repository at this point in the history
…placed hunspell-spellcheck submodule with spellchecker npm module
  • Loading branch information
adrienjoly committed Feb 1, 2017
1 parent 6239911 commit 66b18ef
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

1 change: 0 additions & 1 deletion lib/hunspell-spellchecker
Submodule hunspell-spellchecker deleted from 8342d1
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
"keybindings": []
},
"scripts": {
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
"preinstall": "git submodule update --init --recursive # installs lib/hunspell-spellchecker",
"test": "npm rebuild && node test.js",
"build-for-vscode": "./node_modules/.bin/electron-rebuild -v 1.4.6",
"vscode:prepublish": "npm run build-for-vscode && node ./node_modules/vscode/bin/compile",
"compile": "npm run build-for-vscode && node ./node_modules/vscode/bin/compile -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"electron-rebuild": "^1.5.7",
"typescript": "^1.8.10",
"vscode": "^0.11.0"
},
Expand All @@ -43,11 +45,12 @@
"mkdirp": "^0.5.1",
"npm": "^4.0.2",
"path": "^0.12.7",
"spellchecker": "^3.3.1",
"typescript": "^1.8.10"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/swyphcosmo/vscode-spellchecker.git"
}
}
}
16 changes: 5 additions & 11 deletions src/features/SpellCheckerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'path';
import * as fs from 'fs';
import * as vscode from 'vscode';
let mkdirp = require( 'mkdirp' );
let sc = require( '../../../lib/hunspell-spellchecker/lib/index.js' );
let sc = require( 'spellchecker' );
let jsonMinify = require( 'jsonminify' );

// Toggle debug output
Expand Down Expand Up @@ -33,7 +33,7 @@ export default class SpellCheckerProvider implements vscode.CodeActionProvider
private DICT = undefined;
private settings: SpellSettings;
private static CONFIGFILE: string = '';
private SpellChecker = new sc();
private SpellChecker = sc;
private extensionRoot: string;
private lastcheck: number = -1;
private timer = null;
Expand Down Expand Up @@ -350,7 +350,7 @@ export default class SpellCheckerProvider implements vscode.CodeActionProvider
token = token.replace( //, '\'' );
}

if( !this.SpellChecker.check( token ) )
if( this.SpellChecker.isMisspelled( token ) )
{
if( DEBUG )
console.log( 'Error: \'' + token + '\', line ' + String( linenumber + 1 ) + ', col ' + String( colnumber + 1 ) );
Expand All @@ -373,7 +373,7 @@ export default class SpellCheckerProvider implements vscode.CodeActionProvider

if( token.length < 50 && containsNumber == null )
{
let suggestions = this.SpellChecker.suggest( token );
let suggestions = this.SpellChecker.getCorrectionsForMisspelling( token );
for( let s of suggestions )
{
message += s + ', ';
Expand Down Expand Up @@ -618,13 +618,7 @@ export default class SpellCheckerProvider implements vscode.CodeActionProvider
{
// console.log( path.join( extensionRoot, 'languages', settings.language + '.aff' ) )
this.settings.language = language;
this.DICT = this.SpellChecker.parse(
{
aff: fs.readFileSync( path.join( this.extensionRoot, 'languages', this.settings.language + '.aff' ) ),
dic: fs.readFileSync( path.join( this.extensionRoot, 'languages', this.settings.language + '.dic' ) )
});

this.SpellChecker.use( this.DICT );
this.SpellChecker.setDictionary(language);
}

public getDocumentTypes(): string[]
Expand Down
23 changes: 23 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var SpellChecker = require('spellchecker');

//console.log('dictionaries:', SpellChecker.getAvailableDictionaries());

var dics = [ 'en', 'fr' ];
var words = [ 'j\'aime', 'statement' ];

const checkWord = word => {
var miss = SpellChecker.isMisspelled(word);
var corr = SpellChecker.getCorrectionsForMisspelling(word);
console.log('word: "' + word + '" is',
miss ? 'misspelled => suggestions:' : 'correct :-)',
miss ? corr.join(' / ') : '');
};

const testWithDic = dic => {
console.log(' === dictionary:', dic, '\n');
SpellChecker.setDictionary(dic);
words.forEach(checkWord);
console.log();
};

dics.forEach(testWithDic);

0 comments on commit 66b18ef

Please sign in to comment.