Making a build/run extension

44 views
Skip to first unread message

Jsor

unread,
Jan 27, 2015, 2:15:19 AM1/27/15
to zed-...@googlegroups.com
I understand that the Chrome-based option doesn't really let you do this because it'd have to be able to execute arbitrary code, which would violate the browser environment safety. However, I'm running the standalone. Things like cmake etc would be cool, but with how finnicky they can be I'm mostly interested in running build or test for Go and Rust. Most editors I just switch to the command line, but with Zed I really like having it fullscreen, so it would be nice to do be able to get compile errors/unit test failures automatically shown in a split and edit/recompile within the editor.

With Rust, I tried adding a Tools:Cargo Build command, but it doesn't seem to do anything (and if it does, there's no feedback).

To my user.config I added:

    modes: {
        rust: {
            commands: {
                "Tools:Cargo Build": {
                    scriptUrl: "/cargobuild.js"
                }
            }
        }
    },

For my javascript (warning: I do not know javascript, I mostly grabbed this from Stack Overflow, sorry if it's terrible)

var exec = require('child_process').exec, child;

child = exec('cargo build',
    function (error, stdout, stderr) {
        console.log('stdout: ' + stdout);
        console.log('stderr: ' + stderr);
        if (error !== null) {
            console.log('exec error: ' + error)
        }
    });

One of the main issues here is I don't know if Zed's scripts set some sort of project root variable, because it would be necessary to run these commands (in Rust at least) from the project root. Go is a bit more complex because you need to run from arbitrary folders. Zed also appears to not display anything from console outputs, not even in zed::log.

Is there any way to use plugins to integrate arbitrary build/test tools into Zed (with the caveat that I'm running the standalone version)?

Zef Hemel

unread,
Jan 27, 2015, 3:57:03 AM1/27/15
to Jsor, zed-...@googlegroups.com
Hi,

You cannot call arbitrary node.js modules from a Zed extension. So what you're trying won't work. I'm currently considering a new version/variant of the zedrem tool, part of that consideration is supporting some way to run command line tools. Because I do see what you're trying to do as a returning limitation.

Until then (and no promises), there's really no way to run command line tools. If you really wanted, you could build in support for this yourself. Personally I don't want to do this, because 85% of users uses the Chrome version and it won't work for them, so we need a solution that works for everybody. Again, I'm still thinking how to solve this.

A whole different approach is to use web services for this. That is: create a RESTful web service hosted somewhere that when a source file is posted to it, returns a list of errors (e.g. by running a linter or compiler on the command line on the server) and let those errors be presented in the editor. This would, obviously, be limited just to linters. You wouldn't use this to do real compilations.

-- Zef

--
You received this message because you are subscribed to the Google Groups "Zed user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zed-user+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages