Skip to content

Commit

Permalink
Changed interaction with RuboCop to be pipe/stream based.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmecham committed Oct 21, 2019
1 parent 1fb7032 commit 08c728d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
25 changes: 18 additions & 7 deletions Scripts/issuesProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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);
Expand All @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions Tests/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Test
end

0 comments on commit 08c728d

Please sign in to comment.