diff --git a/src/main/java/com/zhongan/devpilot/completions/inline/CompletionPreview.java b/src/main/java/com/zhongan/devpilot/completions/inline/CompletionPreview.java index a4144d6..0a70cf1 100644 --- a/src/main/java/com/zhongan/devpilot/completions/inline/CompletionPreview.java +++ b/src/main/java/com/zhongan/devpilot/completions/inline/CompletionPreview.java @@ -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) { @@ -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) { @@ -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() { diff --git a/src/main/java/com/zhongan/devpilot/completions/prediction/DevPilotCompletion.java b/src/main/java/com/zhongan/devpilot/completions/prediction/DevPilotCompletion.java index 9b9f386..b866431 100644 --- a/src/main/java/com/zhongan/devpilot/completions/prediction/DevPilotCompletion.java +++ b/src/main/java/com/zhongan/devpilot/completions/prediction/DevPilotCompletion.java @@ -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 lineStates) { @@ -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); } diff --git a/src/main/java/com/zhongan/devpilot/util/TelemetryUtils.java b/src/main/java/com/zhongan/devpilot/util/TelemetryUtils.java index 511c2a1..c5a7878 100644 --- a/src/main/java/com/zhongan/devpilot/util/TelemetryUtils.java +++ b/src/main/java/com/zhongan/devpilot/util/TelemetryUtils.java @@ -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; } @@ -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; } @@ -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) { @@ -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() { @@ -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; + } + } }