From d41d3f81656c2ca27571a46366f01b5065a3746e Mon Sep 17 00:00:00 2001 From: Joseph Kato Date: Sun, 22 Aug 2021 12:02:51 -0700 Subject: [PATCH 1/2] Basic NLP integration --- src/features/vsProvider.ts | 18 +++++++++++++++--- src/features/vsUtils.ts | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/features/vsProvider.ts b/src/features/vsProvider.ts index 5f8e325..07a6aa0 100644 --- a/src/features/vsProvider.ts +++ b/src/features/vsProvider.ts @@ -4,6 +4,7 @@ import * as path from "path"; import * as fs from "fs"; import * as request from "request-promise-native"; import * as vscode from "vscode"; +import { execFile, ChildProcess } from "child_process"; import InitCommands from "./vsCommands"; import * as utils from "./vsUtils"; @@ -19,6 +20,11 @@ export default class ValeServerProvider implements vscode.CodeActionProvider { private static commandId: string = "ValeServerProvider.runCodeAction"; private command!: vscode.Disposable; private logger!: vscode.OutputChannel; + private nlpServer!: ChildProcess; + + private async startNLP(): Promise { + return execFile("nlpapi"); + } private async doVale(textDocument: vscode.TextDocument) { const configuration = vscode.workspace.getConfiguration(); @@ -26,10 +32,7 @@ export default class ValeServerProvider implements vscode.CodeActionProvider { return; } - // Reset out alert map and run-time log: this.alertMap = {}; - this.logger.clear(); - this.useCLI = configuration.get("vale.core.useCLI", false); if (!this.useCLI) { @@ -267,6 +270,14 @@ export default class ValeServerProvider implements vscode.CodeActionProvider { public async activate(subscriptions: vscode.Disposable[]) { this.logger = vscode.window.createOutputChannel("Vale"); + this.nlpServer = await this.startNLP(); + if (this.nlpServer.pid) { + this.logger.appendLine("Successfully started NLP server on port 8000!") + } else { + this.logger.appendLine("Failed to start NLP server on port 8000."); + this.logger.appendLine("You may need to run `pip3 install nlpapi`."); + } + const configuration = vscode.workspace.getConfiguration(); this.command = vscode.commands.registerCommand( ValeServerProvider.commandId, @@ -317,5 +328,6 @@ export default class ValeServerProvider implements vscode.CodeActionProvider { this.alertMap = {}; this.logger.dispose(); + this.nlpServer.kill(); } } diff --git a/src/features/vsUtils.ts b/src/features/vsUtils.ts index c139ad1..2e0ea5e 100644 --- a/src/features/vsUtils.ts +++ b/src/features/vsUtils.ts @@ -2,7 +2,7 @@ import * as path from "path"; import * as which from "which"; import * as fs from "fs"; import * as request from "request-promise-native"; -import { execFile } from "child_process"; +import { execFile, ChildProcess } from "child_process"; import * as vscode from "vscode"; From cb7ead6f1a4c2cd1f7c7928d1757d63581002011 Mon Sep 17 00:00:00 2001 From: Joseph Kato Date: Sun, 22 Aug 2021 12:04:01 -0700 Subject: [PATCH 2/2] Remove unsued import --- src/features/vsUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/vsUtils.ts b/src/features/vsUtils.ts index 2e0ea5e..c139ad1 100644 --- a/src/features/vsUtils.ts +++ b/src/features/vsUtils.ts @@ -2,7 +2,7 @@ import * as path from "path"; import * as which from "which"; import * as fs from "fs"; import * as request from "request-promise-native"; -import { execFile, ChildProcess } from "child_process"; +import { execFile } from "child_process"; import * as vscode from "vscode";