forked from microsoft/copilot-for-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockGhostText.java
More file actions
54 lines (48 loc) · 1.81 KB
/
Copy pathBlockGhostText.java
File metadata and controls
54 lines (48 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package com.microsoft.copilot.eclipse.ui.completion;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.IDocument;
import org.eclipse.lsp4e.LSPEclipseUtils;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import com.microsoft.copilot.eclipse.core.CopilotCore;
import com.microsoft.copilot.eclipse.core.format.FormatOptionProvider;
import com.microsoft.copilot.eclipse.ui.utils.CompletionUtils;
/**
* A ghost text placed below the last line of the document. For normal block ghost text, we use code mining API to
* display the ghost text.
*/
public class BlockGhostText extends GhostText {
/**
* Creates a new EolGhostText.
*/
public BlockGhostText(String text, int modelOffset, IDocument document) {
super(text, modelOffset, GhostTextType.BLOCK_LINE);
IFile file = LSPEclipseUtils.getFile(document);
if (file == null) {
return;
}
FormatOptionProvider formatOptionProvider = CopilotCore.getPlugin().getFormatOptionProvider();
if (formatOptionProvider == null) {
return;
}
boolean useSpace = formatOptionProvider.useSpace(file);
if (useSpace) {
return;
}
int tabSize = formatOptionProvider.getTabSize(file);
String replacedText = CompletionUtils.replaceTabsWithSpaces(this.text, tabSize);
this.text = replacedText;
}
@Override
public void draw(StyledText styledText, int widgetOffset, GC gc) {
if (StringUtils.isNotBlank(this.text)) {
Rectangle bounds = styledText.getTextBounds(widgetOffset, widgetOffset);
int y = bounds.y + styledText.getLineHeight();
gc.drawText(this.text, styledText.getLeftMargin(), y, true);
}
}
}