Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the spell checking language accroding the value of the magic comm… #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/linter-provider.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ module.exports = class LinterProvider
console.log data


magicCommentLanguageSetting = (content) ->
magicCommentPattern = ///
\%\s*!TeX\s* # Starting with %!TeX
spellcheck\s*=\s*
([\w-]+) # capture language setting
///ig # ignore Case

match = magicCommentPattern.exec content
if match
lang = match[1].replace /_/, '-'
else
'auto'




lint: (TextEditor) ->
new Promise (Resolve) ->
received = ""
Expand All @@ -40,8 +56,11 @@ module.exports = class LinterProvider
lthostname = 'languagetool.org'
ltport = 443

language = magicCommentLanguageSetting editorContent
console.log language

post_data_dict = {
'language': 'auto'
'language': language
'text': editorContent
'motherTongue': atom.config.get 'linter-languagetool.motherTongue'
}
Expand Down
21 changes: 21 additions & 0 deletions spec/linter-languagetool-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,25 @@ describe('The languagetool-linter for AtomLinter', () => {
});
});
});

it('checks an mixed language example text taken from the languagetool homepage with TeX magic comment to define the language', () => {
waitsForPromise(() => {
return atom.workspace.open(__dirname + '/test_files/languagetool-mc-test.txt').then(editor => {
return lint(editor).then(messages => {
expect(messages.length).toEqual(22);

expect(messages[21].severity).toBeDefined();
expect(messages[21].severity).toEqual('error');
expect(messages[21].excerpt).toBeDefined();
expect(messages[21].excerpt).toEqual('Rechtschreibfehler');
expect(messages[21].location.file).toBeDefined();
expect(messages[21].location.file).toMatch(/.+languagetool-mc-test\.txt$/);
expect(messages[21].location.position).toBeDefined();
expect(messages[21].location.position.length).toEqual(2);
expect(messages[21].location.position).toEqual([[6, 0], [6, 6]]);
});
});
});
});

});
7 changes: 7 additions & 0 deletions spec/test_files/languagetool-mc-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
% !TeX spellcheck = de_DE

Paste your own text here and click the 'Check Text' button.
Click the colored phrases for details on potential errors.


Füghen Sie hier Ihren Text ein.