Browse Source

WIP on diffs

dev/git-series/gccdum
Matt Godbolt 6 years ago
parent
commit
eb74776003
  1. 16
      .idea/libraries/Cargo__rustfilt_.xml
  2. 10
      static/compiler.js
  3. 7
      static/components.js
  4. 170
      static/diff.js
  5. 9
      static/editor.js
  6. 10
      static/hub.js
  7. 28
      static/index.html

16
.idea/libraries/Cargo__rustfilt_.xml

@ -1,19 +1,19 @@
<component name="libraryTable">
<library name="Cargo &lt;rustfilt&gt;">
<CLASSES>
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-0.1.80" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-demangle-0.1.3" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-0.2.2" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/utf8-ranges-0.1.3" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/thread-id-2.0.0" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-demangle-0.1.3" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/aho-corasick-0.5.3" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/thread_local-0.2.7" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.18" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/winapi-0.2.8" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/winapi-build-0.1.1" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/thread-id-2.0.0" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-syntax-0.3.9" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/memchr-0.1.11" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-0.1.80" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/winapi-build-0.1.1" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/kernel32-sys-0.2.2" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.18" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/thread_local-0.2.7" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-0.2.2" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/memchr-0.1.11" />
</CLASSES>
<JAVADOC />
<SOURCES />

10
static/compiler.js

@ -118,6 +118,7 @@ define(function (require) {
this.eventHub.on('editorClose', this.onEditorClose, this);
this.eventHub.on('colours', this.onColours, this);
this.eventHub.on('resendCompilation', this.onResendCompilation, this);
this.eventHub.on('findCompilers', this.sendCompiler, this);
this.updateCompilerName();
this.updateButtons();
@ -159,8 +160,7 @@ define(function (require) {
// reload the page and the bottom-bar is off the bottom until you scroll a tiny bit.
Compiler.prototype.resize = function () {
var topBarHeight = this.domRoot.find(".top-bar").outerHeight(true);
var bottomBarHeight = this.domRoot.find(".bottom-bar").outerHeight(true);
this.outputEditor.setSize(this.domRoot.width(), this.domRoot.height() - topBarHeight - bottomBarHeight);
this.outputEditor.setSize(this.domRoot.width(), this.domRoot.height() - topBarHeight);
this.refresh();
};
@ -397,6 +397,7 @@ define(function (require) {
this.saveState();
this.compile();
this.updateButtons();
this.sendCompiler();
};
Compiler.prototype.onCompilerChange = function (value) {
@ -405,6 +406,11 @@ define(function (require) {
this.compile();
this.updateButtons();
this.updateCompilerName();
this.sendCompiler();
};
Compiler.prototype.sendCompiler = function () {
this.eventHub.emit('compiler', this.id, this.compiler, this.options);
};
Compiler.prototype.onEditorClose = function (editor) {

7
static/components.js

@ -68,6 +68,13 @@ define(function (require) {
componentName: 'output',
componentState: {compiler: compiler, editor: editor},
};
},
getDiff: function () {
return {
type: 'component',
componentName: 'diff',
componentState: {}
};
}
};

170
static/diff.js

@ -0,0 +1,170 @@
// Copyright (c) 2012-2017, Matt Godbolt
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
define(function (require) {
"use strict";
var CodeMirror = require('codemirror');
var FontScale = require('fontscale');
require('selectize');
function State(id) {
this.id = id;
this.compiler = null;
this.result = null;
}
State.prototype.update = function (id, compiler, result) {
if (this.id !== id) return false;
this.compiler = compiler;
this.result = result;
return true;
}
function Diff(hub, container, state) {
this.container = container;
this.lhs = new State(state.lhs);
this.rhs = new State(state.rhs);
this.eventHub = hub.createEventHub();
this.domRoot = container.getElement();
this.domRoot.html($('#diff').html());
this.compilers = {};
this.outputEditor = CodeMirror.fromTextArea(this.domRoot.find("textarea")[0], {
lineNumbers: true,
mode: "text/x-asm",
readOnly: true,
gutters: ['CodeMirror-linenumbers'],
lineWrapping: true
});
var selectize = this.domRoot.find(".compiler-picker").selectize({
sortField: 'name',
valueField: 'id',
labelField: 'name',
searchField: ['name'],
options: [],
items: []
}).on('change', function () {
console.log("yibble");
// TODO can't do this every time!!
// self.onCompilerChange($(this).val());
});
this.selectize = {lhs: selectize[0].selectize, rhs: selectize[1].selectize};
this.fontScale = new FontScale(this.domRoot, state);
this.fontScale.on('change', _.bind(this.updateState, this));
this.eventHub.on('compileResult', this.onCompileResult, this);
this.eventHub.on('compiler', this.onCompiler, this);
this.eventHub.on('compilerClose', this.onCompilerClose, this);
this.container.on('destroy', function () {
this.eventHub.unsubscribe();
}, this);
container.on('resize', this.resize, this);
container.on('shown', this.refresh, this);
this.eventHub.emit('resendCompilation', this.lhs);
this.eventHub.emit('resendCompilation', this.rhs);
this.eventHub.emit('findCompilers');
this.updateCompilerNames();
this.updateCompilers();
}
// TODO: de-dupe with compiler etc
Diff.prototype.refresh = function () {
this.outputEditor.refresh();
};
// TODO: need to call resize if either .top-bar or .bottom-bar resizes, which needs some work.
// Issue manifests if you make a window where one compiler is small enough that the buttons spill onto two lines:
// reload the page and the bottom-bar is off the bottom until you scroll a tiny bit.
Diff.prototype.resize = function () {
var topBarHeight = this.domRoot.find(".top-bar").outerHeight(true);
var bottomBarHeight = this.domRoot.find(".bottom-bar").outerHeight(true);
this.outputEditor.setSize(this.domRoot.width(), this.domRoot.height() - topBarHeight - bottomBarHeight);
this.refresh();
};
Diff.prototype.onCompileResult = function (id, compiler, result) {
var changed = this.lhs.update(id, compiler, result) || this.rhs.update(id, compiler, result);
if (changed) {
this.updateCompilerNames();
}
};
Diff.prototype.onCompiler = function (id, compiler, options) {
// TODO update lhs, rhs?
this.compilers[id] = {id: id, name: compiler.name + " " + options};
this.updateCompilers();
};
Diff.prototype.onCompilerClose = function (id) {
// TODO update lhs, rhs
delete this.compilers[id];
this.updateCompilers();
};
Diff.prototype.updateCompilerNames = function () {
var name = "Diff";
if (this.lhs.compiler && this.rhs.compiler)
name += " " + this.lhs.compiler.name + " vs " + this.rhs.compiler.name;
this.container.setTitle(name);
};
Diff.prototype.updateCompilersFor = function (selectize) {
selectize.clearOptions();
_.each(this.compilers, function (compiler) {
selectize.addOption(compiler);
}, this);
};
Diff.prototype.updateCompilers = function () {
this.updateCompilersFor(this.selectize.lhs);
this.updateCompilersFor(this.selectize.rhs);
};
Diff.prototype.updateState = function () {
var state = {
lhs: this.lhs.id,
rhs: this.rhs.id
};
this.fontScale.addState(state);
this.container.setState(state);
};
return {
Diff: Diff,
getComponent: function (lhs, rhs) {
return {
type: 'component',
componentName: 'diff',
componentState: {lhs: lhs, rhs: rhs},
};
}
};
});

9
static/editor.js

@ -162,6 +162,7 @@ define(function (require) {
this.eventHub.on('selectLine', this.onSelectLine, this);
var compilerConfig = Components.getCompiler(this.id);
var diffConfig = Components.getDiff();
this.container.layoutManager.createDragSource(
this.domRoot.find('.btn.add-compiler'), compilerConfig);
@ -171,6 +172,14 @@ define(function (require) {
insertPoint.addChild(compilerConfig);
}, this));
this.container.layoutManager.createDragSource(
this.domRoot.find('.btn.add-diff'), diffConfig);
this.domRoot.find('.btn.add-diff').click(_.bind(function () {
var insertPoint = hub.findParentRowOrColumn(this.container) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(diffConfig);
}, this));
Sharing.initShareButton(this.domRoot.find('.share'), container.layoutManager);
this.updateState();

10
static/hub.js

@ -32,6 +32,7 @@ define(function (require) {
var compiler = require('compiler');
var output = require('output');
var Components = require('components');
var diff = require('diff');
function Hub(layout, defaultSrc) {
this.layout = layout;
@ -51,6 +52,10 @@ define(function (require) {
function (container, state) {
return self.outputFactory(container, state);
});
layout.registerComponent(diff.getComponent().componentName,
function (container, state) {
return self.diffFactory(container, state);
});
var removeId = function (id) {
self.ids[id] = false;
};
@ -79,6 +84,9 @@ define(function (require) {
Hub.prototype.outputFactory = function (container, state) {
return new output.Output(this, container, state);
}
Hub.prototype.diffFactory = function (container, state) {
return new diff.Diff(this, container, state);
};
function WrappedEventHub(eventHub) {
@ -112,4 +120,4 @@ define(function (require) {
};
return Hub;
});
});

28
static/index.html

@ -91,6 +91,10 @@
class="btn btn-default btn-sm add-compiler">
<span class="glyphicon glyphicon-open"></span>
</button>
<button title="Add a diff view (click or drag)"
class="btn btn-default btn-sm add-diff">
<span class="glyphicon glyphicon-tree-deciduous"></span>
</button>
</div>
</div>
<textarea>// Type your code here, or load an example.</textarea>
@ -163,6 +167,30 @@
<pre class="content"></pre>
</div>
<div id="diff">
<table>
<tr>
<td>Lhs: <select class="compiler-picker lhs" placeholder="Select a compiler..."></select></td>
<td>Rhs: <select class="compiler-picker rhs" placeholder="Select a compiler..."></select></td>
</tr>
</table>
<div class="btn-group btn-group-sm">
<button title="Decrease font size"
class="btn btn-default btn-sm decrease-font-size">
<span class="glyphicon glyphicon-sm glyphicon-font"></span>
</button>
<button title="Reset font size"
class="btn btn-default btn-sm reset-font-size">
<span class="glyphicon glyphicon-sm glyphicon-font"></span>
</button>
<button title="Increase font size"
class="btn btn-default btn-sm increase-font-size">
<span class="glyphicon glyphicon-sm glyphicon-font"></span>
</button>
</div>
<textarea>[Waiting...]</textarea>
</div>
<div class="urls">
<div class="input-group urls-container">
<div class="input-group-btn">

Loading…
Cancel
Save