From 62bd2e52572fd1d0cfd698798fcddd15b1ea6da4 Mon Sep 17 00:00:00 2001 From: Thomas Krause Date: Sun, 2 Apr 2023 21:15:58 +0200 Subject: [PATCH] feat: add languagetool.org premium API support (using form data for the credentials) (#561) Co-authored-by: Johan Girod Co-authored-by: David L. Day <1132144+davidlday@users.noreply.github.com> --- package.json | 10 ++++++++++ src/ConfigurationManager.ts | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/package.json b/package.json index 8bfc0d1f..ccd07bfa 100644 --- a/package.json +++ b/package.json @@ -188,6 +188,16 @@ "default": "http://localhost:8081", "description": "URL of your LanguageTool server. Defaults to localhost on port 8081." }, + "languageToolLinter.external.username": { + "type": "string", + "default": "", + "description": "Set to get Premium API access if you use the languagetool.org api instance: your username/email as used to log in at languagetool.org." + }, + "languageToolLinter.external.apiKey": { + "type": "string", + "default": "", + "description": "Set to get Premium API access if you use the languagetool.org api instance: your API key." + }, "languageToolLinter.managed.classPath": { "type": "string", "default": "", diff --git a/src/ConfigurationManager.ts b/src/ConfigurationManager.ts index 92395254..b6fd1568 100644 --- a/src/ConfigurationManager.ts +++ b/src/ConfigurationManager.ts @@ -18,6 +18,7 @@ import execa from "execa"; import * as glob from "glob"; import * as path from "path"; import * as portfinder from "portfinder"; +import { URL } from "url"; import { commands, ConfigurationChangeEvent, @@ -391,6 +392,16 @@ export class ConfigurationManager implements Disposable { Constants.EXTENSION_OUTPUT_CHANNEL.appendLine(ltKey + ": " + value); } }); + // Only add user name and API key to options if set and we are using the + // external API + if (this.getServiceType() === Constants.SERVICE_TYPE_EXTERNAL) { + const username = this.get("external.username"); + const apiKey = this.get("external.apiKey"); + if (username && apiKey) { + parameters.set("username", username); + parameters.set("apiKey", apiKey); + } + } // Make sure disabled rules and disabled categories do not contain spaces const CONFIG_DISABLED_RULES = "languageTool.disabledRules"; const CONFIG_DISABLED_CATEGORIES = "languageTool.disabledCategories";