Skip to content

Commit

Permalink
Completion by line accept display fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
maozhen520 committed Oct 16, 2024
1 parent dfec860 commit 2ec876c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ private DevPilotCompletion createPreview() {

public void dispose() {
editor.putUserData(INLINE_COMPLETION_PREVIEW, null);
completions.forEach(DevPilotCompletion::clear);
}

public void applyPreview(@Nullable Caret caret) {
Expand Down Expand Up @@ -196,7 +195,7 @@ private void applyPreviewInternal(@NotNull Integer cursorOffset, Project project
getAutoImportHandler(editor, fileAfterCompletion, startOffset, endOffset).invoke();
});

TelemetryUtils.completionAccept(completion.id, file);
TelemetryUtils.completionAccept(completion.id, file, completion.getUnacceptedLines());
}

public void applyPreviewByLine(@Nullable Caret caret) {
Expand Down Expand Up @@ -248,7 +247,7 @@ private void applyPreviewInternalByLine(Project project, PsiFile file) {
ApplicationManager.getApplication().executeOnPooledThread(() -> {
getAutoImportHandler(editor, fileAfterCompletion, startOffset, endOffset).invoke();
});
TelemetryUtils.completionAccept(completion.id, file);
TelemetryUtils.completionAccept(completion.id, file, line);
}

public void continuePreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public String getUnacceptedLines() {
result.add(lineState.line);
}
}
return "\n" + String.join("\n", result);
return "\n" + String.join("\n", result); // must add "\n", otherwise block preview will occur change line issue.
}

public void init(List<LineState> lineStates) {
Expand Down Expand Up @@ -218,6 +218,10 @@ public LineStateItems.LineState getNextUnacceptLineState() {
return lineStateItems.getLineStates().get(lineStateItems.index);
}

public String getUnacceptedLines() {
return this.lineStateItems.getUnacceptedLines().substring(1); // skip first \n to avoid extra lines count in accept telemetry
}

public void acceptLine(int offset) {
lineStateItems.acceptLine(this.lineStateItems.index++, offset);
}
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/com/zhongan/devpilot/util/TelemetryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void chatAccept(String id, String acceptLines, String language, Ch
sendMessage(url, requestJson);
}

public static void completionAccept(String id, PsiFile file) {
public static void completionAccept(String id, PsiFile file, String acceptLines) {
if (!isTelemetryTurnOn()) {
return;
}
Expand All @@ -87,10 +87,10 @@ public static void completionAccept(String id, PsiFile file) {
language = lang.getLanguageName();
}

completionAccept(id, language);
completionAccept(id, language, acceptLines);
}

public static void completionAccept(String id, String language) {
public static void completionAccept(String id, String language, String acceptLines) {
if (!isTelemetryTurnOn()) {
return;
}
Expand All @@ -100,7 +100,7 @@ public static void completionAccept(String id, String language) {
language = "text";
}

var completionAcceptRequest = new CompletionAcceptRequest(language.toLowerCase(Locale.ROOT));
var completionAcceptRequest = new CompletionAcceptRequest(language.toLowerCase(Locale.ROOT), acceptLines);
var requestJson = JsonUtils.toJson(completionAcceptRequest);

if (requestJson == null) {
Expand Down Expand Up @@ -201,8 +201,11 @@ public void setActionType(String actionType) {
static class CompletionAcceptRequest {
private String language;

CompletionAcceptRequest(String language) {
private String acceptLines;

CompletionAcceptRequest(String language, String acceptLines) {
this.language = language;
this.acceptLines = acceptLines;
}

public String getLanguage() {
Expand All @@ -212,5 +215,14 @@ public String getLanguage() {
public void setLanguage(String language) {
this.language = language;
}

public String getAcceptLines() {
return acceptLines;
}

public void setAcceptLines(String acceptLines) {
this.acceptLines = acceptLines;
}

}
}

0 comments on commit 2ec876c

Please sign in to comment.