Skip to content

Commit 50948cc

Browse files
Reduce excessive whitespace in large Javadoc hover documentation
1 parent c4a1cd6 commit 50948cc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/extension.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,19 @@ const REPLACE_JDT_LINKS_PATTERN: RegExp = /(\[(?:[^\]])+\]\()(jdt:\/\/(?:(?:(?:\
120120
* @returns the documentation with fixed links
121121
*/
122122
export function fixJdtLinksInDocumentation(oldDocumentation: MarkdownString): MarkdownString {
123-
const newContent: string = oldDocumentation.value.replace(REPLACE_JDT_LINKS_PATTERN, (_substring, group1, group2) => {
123+
let content: string = oldDocumentation.value.replace(REPLACE_JDT_LINKS_PATTERN, (_substring, group1, group2) => {
124124
const uri = `command:${Commands.OPEN_FILE}?${encodeURI(JSON.stringify([encodeURIComponent(group2)]))}`;
125125
return `${group1}${uri})`;
126126
});
127-
const mdString = new MarkdownString(newContent);
127+
128+
// Normalize excessive whitespace in large Javadoc content to help
129+
// large hovers render more completely within VS Code's limits.
130+
content = content
131+
.replace(/[ \t]{2,}/g, ' ') // Collapse multiple spaces/tabs to a single space
132+
.replace(/\n{3,}/g, '\n\n') // Collapse 3 or more newlines to exactly 2
133+
.trim();
134+
135+
const mdString = new MarkdownString(content);
128136
mdString.isTrusted = true;
129137
return mdString;
130138
}

0 commit comments

Comments
 (0)