Skip to content

Commit 3fca33d

Browse files
committed
Release 1.9.3
Fixes: - Fixed wrapping code with inline comments removing comment markers (#72) - Fixed Python docstring wrapping with content on opener line (#65) - Added support for Rust parent line comments //! (#52) - Restored optional column width override setting (#68) Thanks to @edgarsi, @mshroyer, and @Grimeh for contributions!
1 parent 2df8f85 commit 3fca33d

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = "com.andrewbrookins.idea.wrap"
8-
version = "1.9.2"
8+
version = "1.9.3"
99

1010
repositories {
1111
mavenCentral()

src/main/java/com/andrewbrookins/idea/wrap/CodeWrapper.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,28 @@ class CodeWrapper(
183183
return result
184184
}
185185

186+
/**
187+
* Check if a line is "code with inline comment" - i.e., has non-whitespace
188+
* content BEFORE a C-style or shell-style inline comment marker.
189+
* For example:
190+
* - "int x = 0; // comment" -> true (has code before //)
191+
* - "// pure comment" -> false (comment marker at start)
192+
* - "plain text" -> false (no comment marker)
193+
*
194+
* This specifically looks for // or # comment markers, not docstrings or
195+
* other markers like * or . which appear in regular text.
196+
*/
197+
private fun isCodeWithInlineComment(line: String): Boolean {
198+
// Only look for // or # style inline comments (not * or . which appear in text)
199+
val codeInlineCommentRegex = "//+!?|#+".toRegex()
200+
val inlineMatch = codeInlineCommentRegex.find(line) ?: return false
201+
202+
// Check if there's non-whitespace content before the comment marker
203+
val beforeComment = line.substring(0, inlineMatch.range.first)
204+
return beforeComment.isNotBlank()
205+
}
206+
207+
186208
/**
187209
* Reformat the single paragraph in `text` to lines of the chosen width,
188210
* and return an array of these lines.
@@ -196,6 +218,15 @@ class CodeWrapper(
196218
* @return array of lines
197219
*/
198220
private fun breakToLinesOfChosenWidth(text: String): MutableList<String> {
221+
val firstLine = text.split("[\\r\\n]+".toRegex()).firstOrNull() ?: text
222+
223+
// If the first line is code with an inline comment (e.g., "int x = 0; // comment"),
224+
// don't wrap - just return the original lines unchanged to avoid corrupting
225+
// code or losing comment markers from subsequent pure-comment lines.
226+
if (isCodeWithInlineComment(firstLine)) {
227+
return text.split("[\\r\\n]+".toRegex()).toMutableList()
228+
}
229+
199230
val firstLineIndent = splitOnIndent(text).indent
200231
val firstLineIsCommentOpener = firstLineIndent.matches("\\s*/\\*+\\s*".toRegex())
201232
val lines: Array<String>

src/main/resources/META-INF/plugin.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin>
22
<id>com.andrewbrookins.wrap_to_column</id>
33
<name>Wrap to Column</name>
4-
<version>1.9.2</version>
4+
<version>1.9.3</version>
55
<vendor email="a@andrewbrookins.com" url="http://andrewbrookins.com">Andrew Brookins</vendor>
66

77
<description><![CDATA[
@@ -33,6 +33,14 @@
3333
]]></description>
3434

3535
<change-notes><![CDATA[
36+
<b>1.9.3</b>
37+
<ul>
38+
<li>Fixed a bug where wrapping code with inline comments would remove comment markers from continuation lines. (Issue #72, thanks @edgarsi!)</li>
39+
<li>Fixed Python docstring wrapping when content is on the same line as the opening quotes. (Issue #65, thanks @edgarsi!)</li>
40+
<li>Added support for wrapping Rust parent line comments (<code>//!</code>). (Issue #52, thanks @mshroyer!)</li>
41+
<li>Restored optional column width override setting. (Issue #68, thanks @Grimeh!)</li>
42+
</ul>
43+
3644
<b>1.9.2</b>
3745
<ul>
3846
<li>

src/test/java/com/andrewbrookins/idea/wrap/CodeWrapperTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,21 @@ class CodeWrapperTests {
417417
//! This is the documentation for my foo module. It has some pretty long lines,
418418
//! which I consider a feature and not a bug.
419419
"""
420+
),
421+
// Issue #72: Code with inline comment should not be wrapped
422+
WrapTestCase(
423+
description = "Issue #72: Code with inline comment is not wrapped (preserves lines)",
424+
rawInput = """
425+
int aa = 0; // test line 1 test line 1 test line 1 test line 1 test line 1 test line 1
426+
// test line2 test line2 test line2 test line2
427+
// test line3
428+
""",
429+
rawExpectedOutput = """
430+
int aa = 0; // test line 1 test line 1 test line 1 test line 1 test line 1 test line 1
431+
// test line2 test line2 test line2 test line2
432+
// test line3
433+
""",
434+
width = 100
420435
)
421436
)
422437

0 commit comments

Comments
 (0)