Skip to content

Commit a9d0852

Browse files
committed
Highlight runtime errors, select correct file
1 parent f640da8 commit a9d0852

File tree

3 files changed

+63
-31
lines changed

3 files changed

+63
-31
lines changed

client/modules/IDE/components/Editor.jsx

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -246,30 +246,54 @@ class Editor extends React.Component {
246246
);
247247
}
248248

249-
if (this.props.runtimeErrorWarningVisible) {
250-
this.props.consoleEvents.forEach((consoleEvent) => {
251-
if (consoleEvent.method === 'error') {
252-
if (
253-
consoleEvent.data &&
254-
consoleEvent.data[0] &&
255-
consoleEvent.data[0].indexOf &&
256-
consoleEvent.data[0].indexOf(')') > -1
257-
) {
258-
const sourceAndLoc = consoleEvent.data[0]
259-
.split('\n')[1]
260-
.split('(')[1]
261-
.split(')')[0];
262-
const [source, line, column] = sourceAndLoc.split(':');
263-
const lineNumber = parseInt(line, 10) - 1;
264-
this._cm.addLineClass(
265-
lineNumber,
266-
'background',
267-
'line-runtime-error'
268-
);
249+
if (this.props.consoleEvents.length !== prevProps.consoleEvents.length) {
250+
if (this.props.runtimeErrorWarningVisible) {
251+
// todo here, need to select the right file
252+
253+
this.props.consoleEvents.forEach((consoleEvent) => {
254+
if (consoleEvent.method === 'error') {
255+
if (consoleEvent.data && consoleEvent.data[0]) {
256+
let sourceAndLoc;
257+
if (
258+
consoleEvent.data[0].indexOf &&
259+
consoleEvent.data[0].indexOf(')') > -1
260+
) {
261+
sourceAndLoc = consoleEvent.data[0] // eslint-disable-line
262+
.split('\n')[1]
263+
.split('(')[1]
264+
.split(')')[0];
265+
} else {
266+
sourceAndLoc = consoleEvent.data[0] // eslint-disable-line
267+
.split('\n')[1]
268+
.split('at ')[1];
269+
}
270+
const [source, line] = sourceAndLoc.split(':');
271+
272+
// get the file that this message is coming from, and then select it
273+
const sourceArray = source.split('/');
274+
const fileName = sourceArray.slice(-1)[0];
275+
const filePath = sourceArray.slice(0, -1).join('/');
276+
const fileWithError = this.props.files.find(
277+
(f) => f.name === fileName && f.filePath === filePath
278+
);
279+
this.props.setSelectedFile(fileWithError.id);
280+
const lineNumber = parseInt(line, 10) - 1;
281+
this._cm.addLineClass(
282+
lineNumber,
283+
'background',
284+
'line-runtime-error'
285+
);
286+
}
269287
}
288+
});
289+
} else {
290+
for (let i = 0; i < this._cm.lineCount(); i += 1) {
291+
this._cm.removeLineClass(i, 'background', 'line-runtime-error');
270292
}
271-
});
272-
} else {
293+
}
294+
}
295+
296+
if (this.props.file.id !== prevProps.file.id) {
273297
for (let i = 0; i < this._cm.lineCount(); i += 1) {
274298
this._cm.removeLineClass(i, 'background', 'line-runtime-error');
275299
}
@@ -467,7 +491,8 @@ Editor.propTypes = {
467491
hideRuntimeErrorWarning: PropTypes.func.isRequired,
468492
runtimeErrorWarningVisible: PropTypes.bool.isRequired,
469493
provideController: PropTypes.func.isRequired,
470-
t: PropTypes.func.isRequired
494+
t: PropTypes.func.isRequired,
495+
setSelectedFile: PropTypes.func.isRequired
471496
};
472497

473498
function mapStateToProps(state) {

client/modules/IDE/reducers/files.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ function renameFile(state, action) {
147147
function setFilePath(files, fileId, path) {
148148
const file = files.find((f) => f.id === fileId);
149149
file.filePath = path;
150-
const newPath = `${path}${path.length > 0 ? '/' : ''}${file.name}`;
150+
// const newPath = `${path}${path.length > 0 ? '/' : ''}${file.name}`;
151+
const newPath = `${path}/${file.name}`;
151152
if (file.children.length === 0) return;
152153
file.children.forEach((childFileId) => {
153154
setFilePath(files, childFileId, newPath);
@@ -192,11 +193,15 @@ const files = (state, action) => {
192193
return initialState();
193194
case ActionTypes.CREATE_FILE: {
194195
const parentFile = state.find((file) => file.id === action.parentId);
196+
// const filePath =
197+
// parentFile.name === 'root'
198+
// ? ''
199+
// : `${parentFile.filePath}${parentFile.filePath.length > 0 ? '/' : ''}
200+
// ${parentFile.name}`;
195201
const filePath =
196202
parentFile.name === 'root'
197203
? ''
198-
: `${parentFile.filePath}${parentFile.filePath.length > 0 ? '/' : ''}
199-
${parentFile.name}`;
204+
: `${parentFile.filePath}/${parentFile.name}`;
200205
const newState = [
201206
...updateParent(state, action),
202207
{
@@ -220,8 +225,9 @@ const files = (state, action) => {
220225
case ActionTypes.UPDATE_FILE_NAME: {
221226
const newState = renameFile(state, action);
222227
const updatedFile = newState.find((file) => file.id === action.id);
223-
const childPath = `${updatedFile.filePath}
224-
${updatedFile.filePath.length > 0 ? '/' : ''}${updatedFile.name}`;
228+
// const childPath = `${updatedFile.filePath}
229+
// ${updatedFile.filePath.length > 0 ? '/' : ''}${updatedFile.name}`;
230+
const childPath = `${updatedFile.filePath}/${updatedFile.name}`;
225231
updatedFile.children.forEach((childId) => {
226232
setFilePath(newState, action.id, childPath);
227233
});

client/modules/Preview/EmbedFrame.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ function resolveScripts(sketchDoc, files) {
133133
const blobUrl = createBlobUrl(resolvedFile);
134134
script.setAttribute('src', blobUrl);
135135
const blobPath = blobUrl.split('/').pop();
136-
objectUrls[blobUrl] = `${resolvedFile.filePath}${
137-
resolvedFile.filePath.length > 0 ? '/' : ''
138-
}${resolvedFile.name}`;
136+
// objectUrls[blobUrl] = `${resolvedFile.filePath}${
137+
// resolvedFile.filePath.length > 0 ? '/' : ''
138+
// }${resolvedFile.name}`;
139+
objectUrls[blobUrl] = `${resolvedFile.filePath}/${resolvedFile.name}`;
139140
objectPaths[blobPath] = resolvedFile.name;
140141
// script.setAttribute('data-tag', `${startTag}${resolvedFile.name}`);
141142
// script.removeAttribute('src');

0 commit comments

Comments
 (0)