@@ -65,33 +65,44 @@ function parseClojure(content: string): vscode.NotebookCellData[] {
65
65
const commentRange = afterForm . rangeForCurrentForm ( 0 ) ;
66
66
const commentStartCursor = cursor . doc . getTokenCursor ( commentRange [ 0 ] ) ;
67
67
const commentCells = [ ] ;
68
- let count = 0 ;
68
+ let previouseEnd = start ;
69
69
70
70
commentStartCursor . downList ( ) ;
71
71
commentStartCursor . forwardSexp ( ) ;
72
72
73
73
while ( commentStartCursor . forwardSexp ( ) ) {
74
+ const range = commentStartCursor . rangeForDefun ( commentStartCursor . offsetStart ) ;
75
+ let leading = '' ;
76
+
77
+ leading = content . substring ( previouseEnd , range [ 0 ] ) ;
78
+ previouseEnd = range [ 1 ] ;
79
+
74
80
commentCells . push ( {
75
- value : substring (
76
- content ,
77
- commentStartCursor . rangeForDefun ( commentStartCursor . offsetStart )
78
- ) ,
81
+ value : substring ( content , range ) ,
79
82
kind : vscode . NotebookCellKind . Code ,
80
83
languageId : 'clojure' ,
81
84
metadata : {
82
- richComment : { index : count } ,
85
+ leading : leading ,
86
+ range,
87
+ richComment : true ,
88
+ trailing : '' ,
83
89
} ,
84
90
} ) ;
85
- count ++ ;
86
91
}
87
- commentCells . forEach ( ( x ) => ( x . metadata . richComment . count = count ) ) ;
92
+
93
+ _ . last ( commentCells ) . metadata . trailing = content . substring ( previouseEnd , end ) ;
88
94
89
95
return commentCells ;
90
96
}
97
+
91
98
return {
92
99
value : content . substring ( start , end ) ,
93
100
kind : vscode . NotebookCellKind . Code ,
94
101
languageId : 'clojure' ,
102
+ metadata : {
103
+ leading : '' ,
104
+ trailing : '' ,
105
+ } ,
95
106
} ;
96
107
} ) ;
97
108
@@ -101,17 +112,13 @@ function parseClojure(content: string): vscode.NotebookCellData[] {
101
112
function writeCellsToClojure ( cells : vscode . NotebookCellData [ ] ) {
102
113
return cells . reduce ( ( acc , x ) => {
103
114
if ( x . kind === vscode . NotebookCellKind . Code ) {
104
- let result : string = x . value ;
105
- if ( x . metadata ?. richComment ) {
106
- if ( x . metadata . richComment . index === 0 ) {
107
- result = '\n(comment\n' . concat ( result ) ;
108
- }
109
-
110
- if ( x . metadata . richComment . index === x . metadata . richComment . count - 1 ) {
111
- result = result . concat ( ')' ) ;
112
- } else {
113
- result = result . concat ( '\n' ) ;
114
- }
115
+ let result = '' ;
116
+
117
+ // created inside the notebook
118
+ if ( undefined === x . metadata . leading ) {
119
+ result = '\n\n' + x . value ;
120
+ } else {
121
+ result = x . metadata . leading + x . value + x . metadata . trailing ;
115
122
}
116
123
117
124
return acc . concat ( result ) ;
0 commit comments