@@ -96,6 +96,10 @@ export class CommentService {
9696 const startLine = range . start . line
9797 const endLine = range . end . line
9898
99+ if ( this . selectionIsInsideMultilineERBTag ( document , startLine , endLine ) ) {
100+ return this . toggleRubyLineComments ( document , startLine , endLine )
101+ }
102+
99103 const firstLineText = document . getText ( Range . create ( startLine , 0 , startLine + 1 , 0 ) ) . replace ( / \n $ / , "" )
100104 const lastLineText = document . getText ( Range . create ( endLine , 0 , endLine + 1 , 0 ) ) . replace ( / \n $ / , "" )
101105 const isWrapped = firstLineText . trim ( ) === "<% if false %>" && lastLineText . trim ( ) === "<% end %>"
@@ -187,6 +191,46 @@ export class CommentService {
187191 return false
188192 }
189193
194+ private selectionIsInsideMultilineERBTag ( document : TextDocument , startLine : number , endLine : number ) : boolean {
195+ let hasRubyLine = false
196+
197+ for ( let line = startLine ; line <= endLine ; line ++ ) {
198+ const lineText = document . getText ( Range . create ( line , 0 , line + 1 , 0 ) ) . replace ( / \n $ / , "" )
199+
200+ if ( lineText . trim ( ) === "" ) continue
201+ if ( ! this . lineIsInsideMultilineERBTag ( document , line ) ) return false
202+
203+ hasRubyLine = true
204+ }
205+
206+ return hasRubyLine
207+ }
208+
209+ private toggleRubyLineComments ( document : TextDocument , startLine : number , endLine : number ) : TextEdit [ ] {
210+ const lineTexts : { line : number , text : string } [ ] = [ ]
211+
212+ for ( let line = startLine ; line <= endLine ; line ++ ) {
213+ const text = document . getText ( Range . create ( line , 0 , line + 1 , 0 ) ) . replace ( / \n $ / , "" )
214+
215+ if ( text . trim ( ) !== "" ) {
216+ lineTexts . push ( { line, text } )
217+ }
218+ }
219+
220+ const allCommented = lineTexts . every ( ( { text } ) => text . trimStart ( ) . startsWith ( "#" ) )
221+
222+ return lineTexts . map ( ( { line, text } ) => {
223+ if ( allCommented ) {
224+ return this . uncommentRubyLine ( text , line ) !
225+ }
226+
227+ const indent = this . getIndentation ( text )
228+ const content = text . trimStart ( )
229+
230+ return TextEdit . replace ( Range . create ( line , 0 , line , text . length ) , `${ indent } # ${ content } ` )
231+ } ) . filter ( edit => edit !== null )
232+ }
233+
190234 private uncommentLine ( info : LineInfo , lineText : string , collector : LineContextCollector ) : TextEdit | null {
191235 const lineRange = Range . create ( info . line , 0 , info . line , lineText . length )
192236 const indent = this . getIndentation ( lineText )
0 commit comments