From 08c728db70fd2e191fedd2b87e6c012eb60dce59 Mon Sep 17 00:00:00 2001 From: Justin Mecham Date: Mon, 21 Oct 2019 07:17:15 -0400 Subject: [PATCH] Changed interaction with RuboCop to be pipe/stream based. --- Scripts/issuesProvider.js | 25 ++++++++++++++++++------- Tests/test.rb | 4 ++++ 2 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 Tests/test.rb diff --git a/Scripts/issuesProvider.js b/Scripts/issuesProvider.js index 633789b..fb4cb96 100644 --- a/Scripts/issuesProvider.js +++ b/Scripts/issuesProvider.js @@ -25,8 +25,9 @@ class RuboCopIssuesProvider { console.log(`[addTextEditor] Adding ${document.path} (Syntax: ${document.syntax})`); const relativePath = nova.workspace.relativizePath(document.path); - this.processFile(relativePath); + this.processFile(relativePath, editor); + editor.onDidSave(this.updateFile.bind(this)); editor.onDidStopChanging(this.updateFile.bind(this)); editor.onDidDestroy(this.removeTextEditor.bind(this)); @@ -53,14 +54,16 @@ class RuboCopIssuesProvider { } updateFile(editor) { - const relativePath = nova.workspace.relativizePath(editor.document.path); - this.processFile(relativePath); + const relativePath = nova.workspace.relativizePath(editor.document.path); + this.processFile(relativePath, editor); } - - processFile(path) { + + // TODO: Extract this into its own class + processFile(path, editor) { const options = { - args: ["rubocop", "-fj", path], - cwd: nova.workspace.path + args: ["rubocop", "-o /tmp/foo", "--format=json", "--stdin", path], + cwd: nova.workspace.path, + stdio: "pipe", }; const process = new Process("/usr/bin/env", options); @@ -72,6 +75,14 @@ class RuboCopIssuesProvider { }); process.start(); + + const writableStream = process.stdio[0]; + const defaultWriter = writableStream.getWriter(); + + defaultWriter.ready.then(() => { + defaultWriter.write(editor.document.getTextInRange(new Range(0, editor.document.length))); + defaultWriter.close(); + }); } processResult(result) { diff --git a/Tests/test.rb b/Tests/test.rb new file mode 100644 index 0000000..002b285 --- /dev/null +++ b/Tests/test.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class Test +end