-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UAST viewer #12
UAST viewer #12
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, tests are not passing
.env.local
Outdated
@@ -0,0 +1 @@ | |||
REACT_EDITOR=code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that should not be committed
src/App.js
Outdated
@@ -8,6 +8,22 @@ import Editor from './components/Editor'; | |||
import UASTViewer from './components/UASTViewer'; | |||
import languages from './languages'; | |||
|
|||
import {code_py} from './examples/example.py.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces after {
and before }
in imports.
No snake case for variables
src/App.js
Outdated
@@ -60,6 +80,11 @@ export default class App extends Component { | |||
this.setState({ selectedLanguage }); | |||
} | |||
|
|||
onExampleChanged(e) { | |||
const selectedExample = e.target.value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why add another variable declaration when selectedExample
is almost as long as e.target.value
?
src/components/UASTViewer.js
Outdated
@@ -1,18 +1,35 @@ | |||
import React, { Component } from 'react'; | |||
import styled from 'styled-components'; | |||
import Node from './uast/Node'; | |||
import {eventHandler} from './uast/EventHandler'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
@@ -0,0 +1,7 @@ | |||
public class HelloWorld |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either we have it in js or as a file, why both?
@@ -0,0 +1,2 @@ | |||
import sys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
src/components/UASTViewer.js
Outdated
` | ||
|
||
export default class UASTViewer extends Component { | ||
constructor(props) { | ||
super(props); | ||
eventHandler.onNodeSelected = this.props.onNodeSelected; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd move all the logic in eventhandler into the UASTViewer, it really makes no sense to have it outside when it's clearly the responsibility of this component.
If I'm understanding this well, EventHandler is just a singleton class that is used as a hack to not having to pass onNodeSelected
down to all children, amirite? I'd rather have this done the right way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracting non-core and non-main functionalities to external services/components/whatever helps to understand and test code; I can push everything in the very same file, but I think it does not help at all to improve the quality of the app
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a singleton class that exists only to not pass around the onNodeSelected
as prop does not help the quality (imho) or make the code easier to understand. And it does complicate testing a lot. Whereas passing the onNodeSelected
as prop you can pass a jest.fn()
to the component instead of having to set the callback on the singleton.
Also, selecting the nodes seems pretty core functionality of the component to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not a singleton but a class instantiated only once.
I prefer much more anything closer to throwing events, than passing callback deeper and deeper everywhere, but I can refactor this piece for sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whose default export is the instance. That is, a singleton.
But that's not how things are done the react way. Parents pass callbacks down as props, children call them.
src/components/uast/EventHandler.js
Outdated
@@ -0,0 +1,37 @@ | |||
class EventHandler { | |||
constructor() { | |||
console.error("CREATED EventHandler") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover<
src/components/uast/EventHandler.js
Outdated
} | ||
|
||
changedCursor(position) { | ||
console.log(position); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the missing part, where I'm currently working
src/components/uast/EventHandler.js
Outdated
}; | ||
} | ||
|
||
return function (e){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space between )
and {
Btw, you see the body with a serif font? Oh, and the uast viewer (as far as I can see in the screenshot) seems really cool, awesome job! 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome job.
src/components/Editor.js
Outdated
return this.document.markText(from, to, { | ||
css: 'background: yellow', | ||
}); | ||
selectCode(from, to) {debugger; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/debugger//
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, debugger is a leftover
src/components/Editor.js
Outdated
css: 'background: yellow', | ||
}); | ||
} else if (from) { | ||
return this.document.setBookmark(from, {widget: this.bookmark}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space after {
and before }
src/components/uast/EventHandler.js
Outdated
} | ||
|
||
selectedNodeTrigger(node) { | ||
const nodeSelectedCallback = this.nodeSelectedCallback; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const { nodeSelectedCallback } = this;
src/components/uast/EventHandler.js
Outdated
to = { | ||
line: node.EndPosition.Line - 1, | ||
ch: node.EndPosition.Col - 1 | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code repetition in from
and to
setting.
src/components/uast/Node.js
Outdated
return ( | ||
name ? | ||
<StyledPropertyName>{name}</StyledPropertyName> : | ||
null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are going to use multiline ternary operators, at least let's write them everytime the same way:
cond
? if_true
: if_false
src/components/uast/Node.js
Outdated
) | ||
} | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract to function.
coordinatesForPosition(position) {
if (!position) { return []; }
const values = ['Offset', 'Line', 'Col'];
return values
.filter(x => typeof position[x] !== 'undefined')
.map((x, i) => <Property key={i} name={name.toLowerCase()} value={position[name]} />);
}
src/components/uast/Node.js
Outdated
{ coordinates } | ||
</CollapsibleItem> | ||
); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No else in these cases. Just return.
src/components/uast/Node.js
Outdated
} | ||
} | ||
|
||
function Roles({roles}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Destructuring braces.
src/components/uast/Node.js
Outdated
} | ||
|
||
render() { | ||
const {name, label, children, onFocusNode} = this.props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Destructuring spaces.
src/index.js
Outdated
@@ -5,6 +5,7 @@ import { injectGlobal } from 'styled-components'; | |||
import App from './App'; | |||
import registerServiceWorker from './registerServiceWorker'; | |||
import './vendor.css'; | |||
import {font} from './styling/variables'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space after and before { }
All your comments were considered in the last commit, that includes the listener for cursor changes |
Signed-off-by: David Pordomingo <David.Pordomingo.F@gmail.com>
Remember to fix the tests. |
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
issue: https://github.com/src-d/backlog/issues/816
The examples are fetched from files, and uast from static json built from a fixed version of the UAST, returned by bblfsh python-client.
Pending:
Nodes having
start_position
andend_position
Nodes having only
start_position
(noend_position
)