Skip to content

Commit

Permalink
Fix inline hover splitting every comma into newlines (#241761)
Browse files Browse the repository at this point in the history
fix hover splitting every comma into newlines
  • Loading branch information
Yoyokrazy authored Feb 24, 2025
1 parent 8d7910b commit 21418a5
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,44 @@ class InlineSegment {
}

export function formatHoverContent(contentText: string): MarkdownString {
if (contentText.includes('\n') || contentText.includes('\r')) {
// Split by commas in case of multiple variables
const pairs = contentText.split(/,\s*/);
if (contentText.includes(',') && contentText.includes('=')) {
// Custom split: for each equals sign after the first, backtrack to the nearest comma
const customSplit = (text: string): string[] => {
const splits: number[] = [];
let equalsFound = 0;
let start = 0;
for (let i = 0; i < text.length; i++) {
if (text[i] === '=') {
if (equalsFound === 0) {
equalsFound++;
continue;
}
const commaIndex = text.lastIndexOf(',', i);
if (commaIndex !== -1 && commaIndex >= start) {
splits.push(commaIndex);
start = commaIndex + 1;
}
equalsFound++;
}
}
const result: string[] = [];
let s = 0;
for (const index of splits) {
result.push(text.substring(s, index).trim());
s = index + 1;
}
if (s < text.length) {
result.push(text.substring(s).trim());
}
return result;
};

const pairs = customSplit(contentText);
const formattedPairs = pairs.map(pair => {
const equalsIndex = pair.indexOf('=');
if (equalsIndex !== -1) {
const indent = ' '.repeat(equalsIndex + 2);
const [firstLine, ...restLines] = pair.trim().split(/\r?\n/);
const [firstLine, ...restLines] = pair.split(/\r?\n/);
return [firstLine, ...restLines.map(line => indent + line)].join('\n');
}
return pair;
Expand Down

0 comments on commit 21418a5

Please sign in to comment.