Skip to content
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

Merged
merged 4 commits into from
Jul 3, 2017
Merged

UAST viewer #12

merged 4 commits into from
Jul 3, 2017

Conversation

dpordomingo
Copy link
Member

@dpordomingo dpordomingo commented Jun 30, 2017

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:

  • tests

Nodes having start_position and end_position
astviewerpy

Nodes having only start_position (no end_position)
astviewerjava

@dpordomingo dpordomingo changed the title Astviewer UAST viewer Jun 30, 2017
Copy link
Contributor

@erizocosmico erizocosmico left a 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
Copy link
Contributor

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';
Copy link
Contributor

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;
Copy link
Contributor

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?

@@ -1,18 +1,35 @@
import React, { Component } from 'react';
import styled from 'styled-components';
import Node from './uast/Node';
import {eventHandler} from './uast/EventHandler';
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

`

export default class UASTViewer extends Component {
constructor(props) {
super(props);
eventHandler.onNodeSelected = this.props.onNodeSelected;
Copy link
Contributor

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.

Copy link
Member Author

@dpordomingo dpordomingo Jun 30, 2017

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

Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

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.

@@ -0,0 +1,37 @@
class EventHandler {
constructor() {
console.error("CREATED EventHandler")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover<

}

changedCursor(position) {
console.log(position);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover

Copy link
Member Author

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

};
}

return function (e){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between ) and {

@erizocosmico
Copy link
Contributor

erizocosmico commented Jun 30, 2017

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! 👍

Copy link
Contributor

@Serabe Serabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job.

return this.document.markText(from, to, {
css: 'background: yellow',
});
selectCode(from, to) {debugger;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/debugger//

Copy link
Contributor

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

css: 'background: yellow',
});
} else if (from) {
return this.document.setBookmark(from, {widget: this.bookmark});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after { and before }

}

selectedNodeTrigger(node) {
const nodeSelectedCallback = this.nodeSelectedCallback;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { nodeSelectedCallback } = this;

to = {
line: node.EndPosition.Line - 1,
ch: node.EndPosition.Col - 1
};
Copy link
Contributor

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.

return (
name ?
<StyledPropertyName>{name}</StyledPropertyName> :
null
Copy link
Contributor

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

)
}
});
}
Copy link
Contributor

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]} />);
}

{ coordinates }
</CollapsibleItem>
);
} else {
Copy link
Contributor

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.

}
}

function Roles({roles}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Destructuring braces.

}

render() {
const {name, label, children, onFocusNode} = this.props;
Copy link
Contributor

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after and before { }

@dpordomingo
Copy link
Member Author

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>
@erizocosmico
Copy link
Contributor

Remember to fix the tests.

Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
@Serabe Serabe merged commit 69a8704 into bblfsh:master Jul 3, 2017
@dpordomingo dpordomingo deleted the astviewer branch November 10, 2017 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants