Skip to content

Commit 60ea58b

Browse files
committed
Show build errors
1 parent 209c21c commit 60ea58b

4 files changed

Lines changed: 92 additions & 44 deletions

File tree

src/App.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
@click="pageIndex=0"
1818
type="text">{{ $t( '代码' ) }}</el-button>
1919
<el-button
20+
style="display: none"
2021
@click="pageIndex=1"
2122
type="text">{{ $t( '编译' ) }}</el-button>
2223
<el-button
@@ -108,6 +109,13 @@ export default {
108109
this.logonName = data.username
109110
} )
110111
112+
connector.$on( 'api-build-coursework', (success, data) => {
113+
if (success) {
114+
this.pageIndex = 2
115+
this.buildData = data
116+
}
117+
} )
118+
111119
this.isAuthenticated = connector.isAuthenticated
112120
if (this.isAuthenticated)
113121
connector.getLogon()

src/components/BufferManager.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ export default {
127127
buf.coursework.state = 0
128128
}
129129
} )
130+
// if ( ! buf.session.getUndoManager().canUndo() )
131+
// buf.coursework.state = 0;
132+
// else
130133
connector.updateCourseworkContent( buf.coursework, buf.session.getValue() )
131134
}
132135
} )

src/components/CodeManager.vue

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,50 @@ export default {
402402
this.$refs.editor.handleCourseworkClose( coursework )
403403
}
404404
},
405+
resetBuildErrors: function ( buf, details ) {
406+
if ( ! buf ) {
407+
this.$message( {
408+
type: 'warning',
409+
message: details
410+
} )
411+
return
412+
}
413+
let ranges = []
414+
let i = details.indexOf( '[{' )
415+
let j = -1
416+
417+
while ( i !== -1 ) {
418+
if ( ! i || details[ i - 1 ] === '\n' ) {
419+
j = details.indexOf( '\n', i )
420+
if ( j === -1 && details.slice( -2 ) === '}]' ) {
421+
ranges = JSON.parse( details.slice( i ) )
422+
break
423+
}
424+
else if ( j > 2 && details.slice( j - 2, j ) === '}]' ) {
425+
ranges = JSON.parse( details.slice( i, j ) )
426+
this.$message( {
427+
type: 'warning',
428+
message: details.slice( j + 1 )
429+
} )
430+
break
431+
}
432+
}
433+
434+
i = details.indexOf( '[{', i + 2 )
435+
}
436+
437+
buf.session.setAnnotations( ranges.map( function( r ) {
438+
const loc = r.locations[0]
439+
return {
440+
row: loc.caret.line,
441+
column: loc.caret.column,
442+
text: r.message,
443+
type: r.kind === 'note' ? 'info' : r.kind
444+
}
445+
}))
446+
447+
this.$refs.editor.execCommand( 'goToNextError' )
448+
}
405449
406450
//
407451
// onCourseworkXXX
@@ -472,12 +516,18 @@ export default {
472516
}
473517
},
474518
handleCourseworkBuild: function ( coursework ) {
475-
if ( coursework && coursework.state === COMPILED )
476-
this.pageIndex = 2
477-
else if ( coursework ) {
478-
connector.$once( 'api-build-coursework', success => {
479-
if ( ! success )
480-
this.$message( _t( '编译出错了' ) )
519+
if ( coursework && coursework.state !== COMPILED ) {
520+
let buf = this.$refs.editor.getBuffer( coursework )
521+
if ( buf )
522+
buf.session.clearAnnotations()
523+
connector.$once( 'api-build-coursework', ( success, data ) => {
524+
if ( ! success ) {
525+
if ( ! data.detail )
526+
this.$message( _t( '编译出错了' ) )
527+
else {
528+
this.resetBuildErrors( buf, data.detail )
529+
}
530+
}
481531
} )
482532
connector.buildCoursework( coursework )
483533
}

src/connector.js

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import { _t } from './plugins/gettext.js'
77
const ACCESS_TOKEN_KEY = 'ACCESS_TOKEN'
88
const REFRESH_TOKEN_KEY = 'REFRESH_TOKEN'
99

10-
// const serverUrl = 'http://localhost:9092'
11-
// const clientId = '0gvr1GFNpCy9fSpxsKHPdUPUu7ZSCQS76zc8kAgl'
12-
// const clientSecret = 'dazoA4IhCGrWrkh2rA02FE1qm3AVWdAz9qKqSZDLAD22xWiVYsEeMtq2BmqVY748U8Qw9jecBo9BHYYG3nZDgOUUwaEFjjDir1VX25ejnCvEcwdzV3Wt2Rxcnt45lxaN'
10+
const serverUrl = 'http://localhost:9092/api/v1'
11+
const clientId = '0gvr1GFNpCy9fSpxsKHPdUPUu7ZSCQS76zc8kAgl'
12+
const clientSecret = 'dazoA4IhCGrWrkh2rA02FE1qm3AVWdAz9qKqSZDLAD22xWiVYsEeMtq2BmqVY748U8Qw9jecBo9BHYYG3nZDgOUUwaEFjjDir1VX25ejnCvEcwdzV3Wt2Rxcnt45lxaN'
1313

1414
// const serverUrl = 'https://codebang.dashingsoft.com'
1515
// const clientId = 'rgt9yKrM82ACFiKLW2aIwxYUCIUV8ggx2OH5hvu8'
1616
// const clientSecret = 'hiWi4Q8k4TR1aAF8PGtqjL7DiY15gBFXjYQ9UM5F3EV5mneJbo88LlXqst0PcfpYVhPQyKc1jjlICggI0otTjOv6zoP89Q0uBNoLsEqkRVmi2G4w5Snn9dBADHx7UxaT'
1717

18-
const serverUrl = 'https://cb.dashingsoft.com/api/v1'
19-
const clientId = 'PetTAmGzfinaiKDcr8wAfuq2IGqYv2TfWBHuou2F'
20-
const clientSecret = 'SLc0LAGCyPQ291V2f3XSpK1xyBde01SHy9hZ5l2FQbrEbd17J9ZSlT8VXDWpsHMre4JqA7F8Olr6SDOQuR5Ul8D7U5PaFopiARASA8vIudRBsh2RAWqfO6Iu14Dtc5bq'
18+
// const serverUrl = 'https://cb.dashingsoft.com/api/v1'
19+
// const clientId = 'PetTAmGzfinaiKDcr8wAfuq2IGqYv2TfWBHuou2F'
20+
// const clientSecret = 'SLc0LAGCyPQ291V2f3XSpK1xyBde01SHy9hZ5l2FQbrEbd17J9ZSlT8VXDWpsHMre4JqA7F8Olr6SDOQuR5Ul8D7U5PaFopiARASA8vIudRBsh2RAWqfO6Iu14Dtc5bq'
2121

2222
// Fix this issue:
2323
// Do not access Object.prototype method ‘hasOwnProperty’ from target object no-prototype-builtins
@@ -336,25 +336,26 @@ export default new Vue({
336336
this.sendRequest(api, make_multipart_data(args, files), 'api-update-coursework-content')
337337
},
338338
buildCoursework: function (coursework) {
339-
let timeout = 15000
339+
let timeout = 5000
340340
const loading = this.$loading( {
341341
lock: true,
342342
text: _t( '正在编译 ' ) + coursework.name + ' ...',
343343
spinner: 'el-icon-loading',
344344
background: 'rgba(0, 0, 0, 0.7)'
345345
} )
346346

347-
const retry = function ( coursework ) {
348-
this.$once( 'api-build', ( success, data ) => {
347+
const retry = function ( ) {
348+
349+
this.$once( 'api-build-result', ( success, data ) => {
349350

350351
let result = false
351352
if ( success ) {
352-
if ( data.state === 'SUCCESS' ) {
353+
if ( data.state === 2 ) {
353354
loading.close()
354355
coursework.state = COMPILED
355356
result = true
356357
}
357-
else if ( data.state === 'FAILURE' ) {
358+
else if ( data.state === -1 ) {
358359
loading.close()
359360
coursework.state = FAILURE
360361
}
@@ -363,52 +364,38 @@ export default new Vue({
363364
coursework.state = TIMEOUT
364365
}
365366
else {
366-
timeout -= 3000
367-
window.setTimeout( retry, 3000, coursework )
367+
timeout -= 1000
368+
window.setTimeout( retry, 1000 )
368369
result = null
369370
}
370371
}
371372
else
372373
loading.close()
373374

374375
if ( result !== null )
375-
this.$emit( 'api-build-coursework', result )
376+
this.$emit( 'api-build-coursework', result, data )
376377
} )
377378

378-
const api = '/courseworks/' + coursework.id + '/build/'
379-
this.sendRequest(api, { data: coursework }, 'api-build')
379+
const api = '/courseworks/' + coursework.id + '/result/'
380+
this.sendRequest(api, { data: coursework }, 'api-build-result')
380381

381382
}.bind( this )
382383

383-
this.$once( 'api-rebuild', ( success, data ) => {
384+
this.$once( 'api-build', ( success ) => {
384385

385-
let result = false
386386
if ( success ) {
387-
if ( data.state === 'SUCCESS' ) {
388-
loading.close()
389-
coursework.state = COMPILED
390-
result = true
391-
}
392-
else if ( data.state === 'FAILURE' ) {
393-
loading.close()
394-
coursework.state = FAILURE
395-
}
396-
else {
397-
retry( coursework )
398-
result = null
399-
}
387+
window.setTimeout( retry, 3000 )
400388
}
401-
else
389+
else {
402390
loading.close()
391+
this.$emit( 'api-build-coursework', false )
392+
}
403393

404-
if ( result !== null )
405-
this.$emit( 'api-build-coursework', result )
406-
407-
} ).bind( this )
394+
} )
408395

409396
coursework.state = BUILDING
410-
const api = '/courseworks/' + coursework.id + '/rebuild/'
411-
this.sendRequest(api, { data: coursework }, 'api-rebuild')
397+
const api = '/courseworks/' + coursework.id + '/build/'
398+
this.sendRequest(api, { data: coursework }, 'api-build')
412399
},
413400
taskCoursework: function (coursework) {
414401
const api = '/courseworks/' + coursework.id + '/result/'

0 commit comments

Comments
 (0)