Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

NLP integration #60

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
18 changes: 15 additions & 3 deletions src/features/vsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -19,17 +20,19 @@ 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<ChildProcess> {
return execFile("nlpapi");
}

private async doVale(textDocument: vscode.TextDocument) {
const configuration = vscode.workspace.getConfiguration();
if (!utils.isElligibleDocument(textDocument)) {
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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -317,5 +328,6 @@ export default class ValeServerProvider implements vscode.CodeActionProvider {
this.alertMap = {};

this.logger.dispose();
this.nlpServer.kill();
}
}