package org.eclipse.jface.text.provisional.codelens.internal;

import org.eclipse.jface.text.provisional.viewzones.IViewZoneRenderer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;

public class CodeLensViewZoneRenderer implements IViewZoneRenderer<CodeLensViewZone> {

	private static final CodeLensViewZoneRenderer INSTANCE = new CodeLensViewZoneRenderer();

	public static CodeLensViewZoneRenderer getInstance() {
		return INSTANCE;
	}

	@Override
	public void draw(CodeLensViewZone viewZone, int paintX, int paintY, GC gc, StyledText styledText) {
		Rectangle client = styledText.getClientArea();
		gc.setBackground(styledText.getDisplay().getSystemColor(SWT.COLOR_WHITE));
		styledText.drawBackground(gc, paintX, paintY, client.width, viewZone.getHeightInPx());
		gc.setForeground(styledText.getDisplay().getSystemColor(SWT.COLOR_GRAY));

		String text = viewZone.getText();
		if (text != null) {
			Font font = new Font(styledText.getDisplay(), "Arial", 9, SWT.ITALIC);
			gc.setFont(font);
			gc.drawText(text, paintX, paintY + 4);
		}
	}

}
@@ -278,16 +278,56 @@
 cs.GC;%0D%0A
+import org.eclipse.swt.graphics.Point;%0D%0A
 import o
@@ -1103,157 +1103,734 @@
 l) %7B
-%0D%0A%09%09%09Font font = new Font(styledText.getDisplay(), %22Arial%22, 9, SWT.ITALIC);%0D%0A%09%09%09gc.setFont(font);%0D%0A%09%09%09gc.drawText(text, paintX, paintY + 4);%0D%0A%09%09%7D%0D%0A%09%7D
+%09%09%09%09%09%09%0D%0A%09%09%09int leading = getLeadingSpaces(styledText.getLine(viewZone.getAfterLineNumber()));%0D%0A%09%09%09if (leading %3E 0) %7B%0D%0A%09%09%09%09Point topLeft = styledText.getLocationAtOffset(viewZone.getOffsetAtLine() + leading);%0D%0A%09%09%09%09paintX+=topLeft.x;%0D%0A%09%09%09%7D%0D%0A%09%09%09Font font = new Font(styledText.getDisplay(), %22Arial%22, 9, SWT.ITALIC);%0D%0A%09%09%09gc.setFont(font);%0D%0A%09%09%09gc.drawText(text, paintX, paintY + 4);%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%09%0D%0A%09private static int getLeadingSpaces(String line)%0D%0A%09%7B%0D%0A%09    int counter = 0;%0D%0A%0D%0A%09    char%5B%5D chars = line.toCharArray();%0D%0A%09    for (char c : chars)%0D%0A%09    %7B%0D%0A%09        if (c == '%5Ct')%0D%0A%09            counter ++;%0D%0A%09        else if (c == ' ')%0D%0A%09            counter++;%0D%0A%09        else%0D%0A%09            break;%0D%0A%09    %7D%0D%0A%0D%0A%09    return counter;%0D%0A%09%7D%0D%0A%0D%0A
 %0D%0A%0D%0A

Align CodeLens with line spaces.