Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inline hover splitting every comma into newlines #241761

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading