Skip to content

Commit 0277b8c

Browse files
authored
Merge pull request #279 from carlosms/uast2-viewer
Update uast-viewer and bblfsh/client-go to work with gitbase 0.18
2 parents cb170cd + d74c362 commit 0277b8c

55 files changed

Lines changed: 1172 additions & 3435 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
- docker exec -it bblfshd bblfshctl driver install --force javascript docker://bblfsh/javascript-driver:latest
4949
- mkdir $HOME/repos
5050
- git clone https://github.com/src-d/gitbase-web.git $HOME/repos/gitbase-web
51-
- docker run -d --name gitbase -p "3367:3306" -e "BBLFSH_ENDPOINT=bblfshd:9432" --volume $HOME/repos:/opt/repos --link bblfshd srcd/gitbase
51+
- docker run -d --name gitbase -p "3367:3306" -e "BBLFSH_ENDPOINT=bblfshd:9432" --volume $HOME/repos:/opt/repos --link bblfshd srcd/gitbase:v0.18.0-beta.1
5252
- sleep 15
5353
- GITBASEPG_DB_CONNECTION='root@tcp(localhost:3367)/none' GITBASEPG_INTEGRATION_TESTS=true make test
5454
- script:

Gopkg.lock

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
unused-packages = true
77
non-go = true
88

9-
[[prune.project]]
10-
name = "gopkg.in/bblfsh/client-go.v2"
11-
non-go = false
12-
139
[[constraint]]
1410
name = "github.com/go-chi/chi"
1511
version = "3.3.2"
@@ -39,12 +35,16 @@
3935
version = "1.2.2"
4036

4137
[[constraint]]
38+
name = "gopkg.in/bblfsh/client-go.v3"
39+
version = "3.1.0"
40+
41+
[[override]]
4242
name = "gopkg.in/bblfsh/sdk.v1"
4343
version = "1.16.0"
4444

4545
[[constraint]]
46-
name = "gopkg.in/bblfsh/client-go.v2"
47-
version = "2.8.4"
46+
name = "gopkg.in/bblfsh/sdk.v2"
47+
version = "2.3.0"
4848

4949
[[constraint]]
5050
name = "gopkg.in/DATA-DOG/go-sqlmock.v1"

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ services:
1111
depends_on:
1212
- gitbase
1313
gitbase:
14-
image: "srcd/gitbase:v0.17.1"
14+
image: "srcd/gitbase:v0.18.0-beta.1"
1515
environment:
1616
BBLFSH_ENDPOINT: bblfsh:9432
1717
GITBASE_UNSTABLE_SQUASH_ENABLE: "true"
1818
volumes:
1919
- ${GITBASEPG_REPOS_FOLDER}:/opt/repos
2020
bblfsh:
21-
image: "bblfsh/bblfshd:v2.9.0-drivers"
21+
image: "bblfsh/bblfshd:v2.9.2-drivers"
2222
privileged: true

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"react-split-pane": "^0.1.77",
1818
"react-switch": "^3.0.4",
1919
"react-table": "^6.8.2",
20-
"uast-viewer": "^0.0.8"
20+
"uast-viewer": "^0.2.0"
2121
},
2222
"scripts": {
2323
"start": "react-app-rewired start",

frontend/src/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function parseCode(language, content, filter, customServerUrl) {
145145
serverUrl: customServerUrl
146146
}
147147
}).then(res => {
148-
if (res.data.status !== 0) {
148+
if (res.status !== 200) {
149149
throw normalizeErrors(res.data.errors);
150150
}
151151
return res.data.uast;

frontend/src/components/UASTViewer.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
3-
import { transformer } from 'uast-viewer';
3+
import { expandRootIds, uastV2 } from 'uast-viewer';
44
import UASTViewerPane from './UASTViewerPane';
55
import api from '../api';
66
import CloseIcon from '../icons/close-query-tab.svg';
77

8+
// Same values as the ones applied by withUASTEditor in CodeViewer.js
9+
// https://github.com/bblfsh/uast-viewer/blob/v0.2.0/src/withUASTEditor.js#L208
10+
const ROOT_IDS = [1];
11+
const LEVELS_EXPAND = 2;
12+
813
class UASTViewer extends Component {
914
constructor(props) {
1015
super(props);
1116

1217
this.state = {
1318
loading: false,
14-
uast: transformer({
15-
InternalType: 'Search results',
16-
Children: props.uast
17-
}),
19+
uast: this.transform(props.uast),
1820
showLocations: false,
1921
filter: '',
2022
error: null
@@ -40,12 +42,24 @@ class UASTViewer extends Component {
4042
api
4143
.filterUAST(this.props.protobufs, this.state.filter)
4244
.then(uast => {
43-
this.setState({ uast: transformer(uast) });
45+
this.setState({ uast: this.transform(uast) });
4446
})
4547
.catch(err => this.setState({ uast: null, error: err }))
4648
.then(() => this.setState({ loading: false }));
4749
}
4850

51+
// Applies the uast-viewer object shape transformer, and expands the first
52+
// 2 levels
53+
transform(uast) {
54+
const flatUAST = uastV2.transformer(uast);
55+
return expandRootIds(
56+
flatUAST,
57+
ROOT_IDS,
58+
LEVELS_EXPAND,
59+
uastV2.getChildrenIds
60+
);
61+
}
62+
4963
removeError() {
5064
this.setState({ error: null });
5165
}

frontend/src/components/UASTViewerPane.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Button } from 'react-bootstrap';
55
import './UASTViewerPane.less';
66

77
const ROOT_ID = 1;
8-
const SEARCH_RESULTS_TYPE = 'Search results';
98

109
function getSearchResults(uast) {
1110
if (!uast) {
@@ -17,8 +16,8 @@ function getSearchResults(uast) {
1716
return null;
1817
}
1918

20-
if (rootNode.InternalType === SEARCH_RESULTS_TYPE) {
21-
return rootNode.Children;
19+
if (Array.isArray(rootNode.n)) {
20+
return rootNode.n.map(c => c.id);
2221
}
2322

2423
return null;

frontend/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8059,10 +8059,10 @@ ua-parser-js@^0.7.18:
80598059
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.18.tgz#a7bfd92f56edfb117083b69e31d2aa8882d4b1ed"
80608060
integrity sha512-LtzwHlVHwFGTptfNSgezHp7WUlwiqb0gA9AALRbKaERfxwJoiX0A73QbTToxteIAuIaFshhgIZfqK8s7clqgnA==
80618061

8062-
uast-viewer@^0.0.8:
8063-
version "0.0.8"
8064-
resolved "https://registry.yarnpkg.com/uast-viewer/-/uast-viewer-0.0.8.tgz#e0e4c5bcad6bf3d62dcc48800a4350d800a01987"
8065-
integrity sha1-4OTFvK1r89YtzEiACkNQ2ACgGYc=
8062+
uast-viewer@^0.2.0:
8063+
version "0.2.0"
8064+
resolved "https://registry.yarnpkg.com/uast-viewer/-/uast-viewer-0.2.0.tgz#081cc7f2f67bf5db03dc53cd8a451f491c49e699"
8065+
integrity sha512-BTYLYY6xSu0ITjC4lO2Kb14Nw4oYKh7i3mChf4HygNJRTJ93FHaYTmyqS38cA3+1FsGnEyKSz+BwATGONLJPDQ==
80668066

80678067
uglify-js@3.4.x, uglify-js@^3.0.13:
80688068
version "3.4.3"

server/handler/export.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ func Export(db service.SQLDB) http.HandlerFunc {
7676
// to parse as UAST first
7777
sqlVal, _ := val.(*sql.NullString)
7878
if sqlVal.Valid {
79-
nodes, err := service.UnmarshalUAST([]byte(sqlVal.String))
79+
nodes, err := service.UnmarshalNodes([]byte(sqlVal.String))
8080

8181
if err == nil && nodes != nil {
82-
b, err := json.Marshal(nodes)
82+
b, err := json.MarshalIndent(nodes, "", " ")
8383
if err != nil {
8484
return err
8585
}
@@ -89,21 +89,6 @@ func Export(db service.SQLDB) http.HandlerFunc {
8989
}
9090
}
9191
case *[]byte:
92-
// DatabaseTypeName JSON is used for arrays of uast nodes and
93-
// arrays of strings, but we don't know the exact type.
94-
// We try with arry of uast nodes first and any JSON later
95-
96-
// This is deprecated, only used by gitbase <= v0.16.0.
97-
nodes, err := service.UnmarshalUASTOld(val)
98-
if err == nil {
99-
b, err := json.Marshal(nodes)
100-
if err != nil {
101-
return err
102-
}
103-
record[i] = string(b)
104-
continue
105-
}
106-
10792
record[i] = string(*v)
10893
}
10994
}

0 commit comments

Comments
 (0)