@aws/lsp-codewhisperer 0.0.83 → 0.0.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/out/language-server/agenticChat/agenticChatController.js +62 -9
- package/out/language-server/agenticChat/agenticChatController.js.map +1 -1
- package/out/language-server/agenticChat/agenticChatResultStream.d.ts +1 -0
- package/out/language-server/agenticChat/agenticChatResultStream.js +21 -0
- package/out/language-server/agenticChat/agenticChatResultStream.js.map +1 -1
- package/out/language-server/agenticChat/constants/constants.d.ts +23 -0
- package/out/language-server/agenticChat/constants/constants.js +32 -1
- package/out/language-server/agenticChat/constants/constants.js.map +1 -1
- package/out/language-server/agenticChat/constants/modelSelection.d.ts +2 -2
- package/out/language-server/agenticChat/constants/modelSelection.js +6 -5
- package/out/language-server/agenticChat/constants/modelSelection.js.map +1 -1
- package/out/language-server/agenticChat/context/agenticChatTriggerContext.d.ts +2 -1
- package/out/language-server/agenticChat/context/agenticChatTriggerContext.js +3 -1
- package/out/language-server/agenticChat/context/agenticChatTriggerContext.js.map +1 -1
- package/out/language-server/agenticChat/retry/delayInterceptor.d.ts +33 -0
- package/out/language-server/agenticChat/retry/delayInterceptor.js +79 -0
- package/out/language-server/agenticChat/retry/delayInterceptor.js.map +1 -0
- package/out/language-server/agenticChat/retry/errorTransformer.d.ts +15 -0
- package/out/language-server/agenticChat/retry/errorTransformer.js +152 -0
- package/out/language-server/agenticChat/retry/errorTransformer.js.map +1 -0
- package/out/language-server/agenticChat/retry/index.d.ts +3 -0
- package/out/language-server/agenticChat/retry/index.js +11 -0
- package/out/language-server/agenticChat/retry/index.js.map +1 -0
- package/out/language-server/agenticChat/retry/qRetryStrategy.d.ts +20 -0
- package/out/language-server/agenticChat/retry/qRetryStrategy.js +71 -0
- package/out/language-server/agenticChat/retry/qRetryStrategy.js.map +1 -0
- package/out/language-server/agenticChat/retry/retryClassifier.d.ts +32 -0
- package/out/language-server/agenticChat/retry/retryClassifier.js +122 -0
- package/out/language-server/agenticChat/retry/retryClassifier.js.map +1 -0
- package/out/language-server/agenticChat/tabBarController.d.ts +4 -0
- package/out/language-server/agenticChat/tabBarController.js +19 -2
- package/out/language-server/agenticChat/tabBarController.js.map +1 -1
- package/out/language-server/chat/chatController.js.map +1 -1
- package/out/language-server/chat/chatSessionService.d.ts +7 -0
- package/out/language-server/chat/chatSessionService.js +37 -80
- package/out/language-server/chat/chatSessionService.js.map +1 -1
- package/out/language-server/chat/constants.d.ts +1 -0
- package/out/language-server/chat/constants.js +2 -1
- package/out/language-server/chat/constants.js.map +1 -1
- package/out/language-server/chat/telemetry/chatTelemetryController.d.ts +1 -0
- package/out/language-server/chat/telemetry/chatTelemetryController.js +11 -0
- package/out/language-server/chat/telemetry/chatTelemetryController.js.map +1 -1
- package/out/language-server/inline-completion/codeWhispererServer.d.ts +0 -1
- package/out/language-server/inline-completion/codeWhispererServer.js +14 -478
- package/out/language-server/inline-completion/codeWhispererServer.js.map +1 -1
- package/out/language-server/inline-completion/{editCompletionHandler.d.ts → handler/editCompletionHandler.d.ts} +10 -10
- package/out/language-server/inline-completion/{editCompletionHandler.js → handler/editCompletionHandler.js} +17 -14
- package/out/language-server/inline-completion/handler/editCompletionHandler.js.map +1 -0
- package/out/language-server/inline-completion/handler/inlineCompletionHandler.d.ts +32 -0
- package/out/language-server/inline-completion/handler/inlineCompletionHandler.js +377 -0
- package/out/language-server/inline-completion/handler/inlineCompletionHandler.js.map +1 -0
- package/out/language-server/inline-completion/handler/sessionResultsHandler.d.ts +23 -0
- package/out/language-server/inline-completion/handler/sessionResultsHandler.js +119 -0
- package/out/language-server/inline-completion/handler/sessionResultsHandler.js.map +1 -0
- package/out/language-server/inline-completion/telemetry/telemetry.js.map +1 -1
- package/out/language-server/inline-completion/utils/diffUtils.d.ts +28 -11
- package/out/language-server/inline-completion/utils/diffUtils.js +269 -117
- package/out/language-server/inline-completion/utils/diffUtils.js.map +1 -1
- package/out/language-server/inline-completion/utils/mergeRightUtils.d.ts +1 -9
- package/out/language-server/inline-completion/utils/mergeRightUtils.js +5 -33
- package/out/language-server/inline-completion/utils/mergeRightUtils.js.map +1 -1
- package/out/language-server/inline-completion/utils/textDocumentUtils.d.ts +3 -0
- package/out/language-server/inline-completion/utils/textDocumentUtils.js +37 -0
- package/out/language-server/inline-completion/utils/textDocumentUtils.js.map +1 -0
- package/out/language-server/inline-completion/{trigger.d.ts → utils/triggerUtils.d.ts} +4 -4
- package/out/language-server/inline-completion/{trigger.js → utils/triggerUtils.js} +3 -3
- package/out/language-server/inline-completion/utils/triggerUtils.js.map +1 -0
- package/out/language-server/workspaceContext/workspaceFolderManager.js +3 -1
- package/out/language-server/workspaceContext/workspaceFolderManager.js.map +1 -1
- package/out/shared/codeWhispererService.js +19 -18
- package/out/shared/codeWhispererService.js.map +1 -1
- package/out/shared/streamingClientService.d.ts +6 -1
- package/out/shared/streamingClientService.js +33 -12
- package/out/shared/streamingClientService.js.map +1 -1
- package/out/shared/telemetry/telemetryService.js.map +1 -1
- package/out/shared/telemetry/types.d.ts +8 -0
- package/out/shared/telemetry/types.js +1 -0
- package/out/shared/telemetry/types.js.map +1 -1
- package/out/shared/utils.d.ts +9 -3
- package/out/shared/utils.js +15 -10
- package/out/shared/utils.js.map +1 -1
- package/package.json +2 -2
- package/out/language-server/inline-completion/editCompletionHandler.js.map +0 -1
- package/out/language-server/inline-completion/trigger.js.map +0 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SessionResultsHandler = void 0;
|
|
4
|
+
const codeWhispererService_1 = require("../../../shared/codeWhispererService");
|
|
5
|
+
const diffUtils_1 = require("../utils/diffUtils");
|
|
6
|
+
const utils_1 = require("../../../shared/utils");
|
|
7
|
+
const telemetry_1 = require("../telemetry/telemetry");
|
|
8
|
+
class SessionResultsHandler {
|
|
9
|
+
logging;
|
|
10
|
+
telemetry;
|
|
11
|
+
telemetryService;
|
|
12
|
+
completionSessionManager;
|
|
13
|
+
editSessionManager;
|
|
14
|
+
codePercentageTracker;
|
|
15
|
+
codeDiffTracker;
|
|
16
|
+
rejectedEditTracker;
|
|
17
|
+
streakTracker;
|
|
18
|
+
getEditsEnabled;
|
|
19
|
+
getTimeSinceLastUserModification;
|
|
20
|
+
constructor(logging, telemetry, telemetryService, completionSessionManager, editSessionManager, codePercentageTracker, codeDiffTracker, rejectedEditTracker, streakTracker, getEditsEnabled, getTimeSinceLastUserModification) {
|
|
21
|
+
this.logging = logging;
|
|
22
|
+
this.telemetry = telemetry;
|
|
23
|
+
this.telemetryService = telemetryService;
|
|
24
|
+
this.completionSessionManager = completionSessionManager;
|
|
25
|
+
this.editSessionManager = editSessionManager;
|
|
26
|
+
this.codePercentageTracker = codePercentageTracker;
|
|
27
|
+
this.codeDiffTracker = codeDiffTracker;
|
|
28
|
+
this.rejectedEditTracker = rejectedEditTracker;
|
|
29
|
+
this.streakTracker = streakTracker;
|
|
30
|
+
this.getEditsEnabled = getEditsEnabled;
|
|
31
|
+
this.getTimeSinceLastUserModification = getTimeSinceLastUserModification;
|
|
32
|
+
}
|
|
33
|
+
// Schedule tracker for UserModification Telemetry event
|
|
34
|
+
enqueueCodeDiffEntry(session, acceptedSuggestion, addedCharactersForEdit) {
|
|
35
|
+
const endPosition = (0, utils_1.getEndPositionForAcceptedSuggestion)(acceptedSuggestion.content, session.startPosition);
|
|
36
|
+
// use the addedCharactersForEdit if it is EDIT suggestion type
|
|
37
|
+
const originalString = addedCharactersForEdit ? addedCharactersForEdit : acceptedSuggestion.content;
|
|
38
|
+
this.codeDiffTracker.enqueue({
|
|
39
|
+
sessionId: session.codewhispererSessionId || '',
|
|
40
|
+
requestId: session.responseContext?.requestId || '',
|
|
41
|
+
fileUrl: session.document.uri,
|
|
42
|
+
languageId: session.language,
|
|
43
|
+
time: Date.now(),
|
|
44
|
+
originalString: originalString,
|
|
45
|
+
startPosition: session.startPosition,
|
|
46
|
+
endPosition: endPosition,
|
|
47
|
+
customizationArn: session.customizationArn,
|
|
48
|
+
completionType: (0, utils_1.getCompletionType)(acceptedSuggestion),
|
|
49
|
+
triggerType: session.triggerType,
|
|
50
|
+
credentialStartUrl: session.credentialStartUrl,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async handleSessionResults(params) {
|
|
54
|
+
const { sessionId, completionSessionResult, firstCompletionDisplayLatency, totalSessionDisplayTime, typeaheadLength, isInlineEdit, addedDiagnostics, removedDiagnostics, } = params;
|
|
55
|
+
const sessionManager = params.isInlineEdit ? this.editSessionManager : this.completionSessionManager;
|
|
56
|
+
const session = sessionManager.getSessionById(sessionId);
|
|
57
|
+
if (!session) {
|
|
58
|
+
this.logging.log(`ERROR: Session ID ${sessionId} was not found`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (session.state !== 'ACTIVE') {
|
|
62
|
+
this.logging.log(`ERROR: Trying to record trigger decision for not-active session ${sessionId} with wrong state ${session.state}`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const acceptedItemId = Object.keys(params.completionSessionResult).find(k => params.completionSessionResult[k].accepted);
|
|
66
|
+
const isAccepted = acceptedItemId ? true : false;
|
|
67
|
+
const acceptedSuggestion = session.suggestions.find(s => s.itemId === acceptedItemId);
|
|
68
|
+
let addedLengthForEdits = 0;
|
|
69
|
+
let deletedLengthForEdits = 0;
|
|
70
|
+
if (acceptedSuggestion) {
|
|
71
|
+
this.codePercentageTracker.countSuccess(session.language);
|
|
72
|
+
if (session.predictionType === codeWhispererService_1.SuggestionType.EDIT && acceptedSuggestion.content) {
|
|
73
|
+
// [acceptedSuggestion.insertText] will be undefined for NEP suggestion. Use [acceptedSuggestion.content] instead.
|
|
74
|
+
// Since [acceptedSuggestion.content] is in the form of a diff, transform the content into addedCharacters and deletedCharacters.
|
|
75
|
+
const { addedLines, deletedLines } = (0, diffUtils_1.getAddedAndDeletedLines)(acceptedSuggestion.content);
|
|
76
|
+
const charDiffResult = (0, diffUtils_1.getCharacterDifferences)(addedLines, deletedLines);
|
|
77
|
+
addedLengthForEdits = charDiffResult.charactersAdded;
|
|
78
|
+
deletedLengthForEdits = charDiffResult.charactersRemoved;
|
|
79
|
+
this.codePercentageTracker.countAcceptedTokensUsingCount(session.language, charDiffResult.charactersAdded);
|
|
80
|
+
this.codePercentageTracker.addTotalTokensForEdits(session.language, charDiffResult.charactersAdded);
|
|
81
|
+
this.enqueueCodeDiffEntry(session, acceptedSuggestion, addedLines.join('\n'));
|
|
82
|
+
}
|
|
83
|
+
else if (acceptedSuggestion.insertText) {
|
|
84
|
+
this.codePercentageTracker.countAcceptedTokens(session.language, acceptedSuggestion.insertText);
|
|
85
|
+
this.codePercentageTracker.countTotalTokens(session.language, acceptedSuggestion.insertText, true);
|
|
86
|
+
this.enqueueCodeDiffEntry(session, acceptedSuggestion);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Handle rejected edit predictions
|
|
90
|
+
if (isInlineEdit && !isAccepted) {
|
|
91
|
+
// Find all rejected suggestions in this session
|
|
92
|
+
const rejectedSuggestions = session.suggestions.filter(suggestion => {
|
|
93
|
+
const result = completionSessionResult[suggestion.itemId];
|
|
94
|
+
return result && result.seen && !result.accepted;
|
|
95
|
+
});
|
|
96
|
+
// Record each rejected edit
|
|
97
|
+
for (const rejectedSuggestion of rejectedSuggestions) {
|
|
98
|
+
if (rejectedSuggestion.content) {
|
|
99
|
+
this.rejectedEditTracker.recordRejectedEdit({
|
|
100
|
+
content: rejectedSuggestion.content,
|
|
101
|
+
timestamp: Date.now(),
|
|
102
|
+
documentUri: session.document.uri,
|
|
103
|
+
position: session.startPosition,
|
|
104
|
+
});
|
|
105
|
+
this.logging.debug(`[EDIT_PREDICTION] Recorded rejected edit: ${rejectedSuggestion.content.substring(0, 20)}...`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
session.setClientResultData(completionSessionResult, firstCompletionDisplayLatency, totalSessionDisplayTime, typeaheadLength);
|
|
110
|
+
if (firstCompletionDisplayLatency)
|
|
111
|
+
(0, telemetry_1.emitPerceivedLatencyTelemetry)(this.telemetry, session);
|
|
112
|
+
// Always emit user trigger decision at session close
|
|
113
|
+
sessionManager.closeSession(session);
|
|
114
|
+
const streakLength = this.getEditsEnabled() ? this.streakTracker.getAndUpdateStreakLength(isAccepted) : 0;
|
|
115
|
+
await (0, telemetry_1.emitUserTriggerDecisionTelemetry)(this.telemetry, this.telemetryService, session, this.getTimeSinceLastUserModification(), addedLengthForEdits, deletedLengthForEdits, addedDiagnostics, removedDiagnostics, streakLength, Object.keys(params.completionSessionResult)[0]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.SessionResultsHandler = SessionResultsHandler;
|
|
119
|
+
//# sourceMappingURL=sessionResultsHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionResultsHandler.js","sourceRoot":"","sources":["../../../../src/language-server/inline-completion/handler/sessionResultsHandler.ts"],"names":[],"mappings":";;;AAWA,+EAAiF;AACjF,kDAAqF;AACrF,iDAA8F;AAC9F,sDAAwG;AAExG,MAAa,qBAAqB;IAET;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAXrB,YACqB,OAAgB,EAChB,SAAoB,EACpB,gBAAkC,EAClC,wBAAwC,EACxC,kBAAkC,EAClC,qBAA4C,EAC5C,eAA+D,EAC/D,mBAAwC,EACxC,aAA4B,EAC5B,eAA8B,EAC9B,gCAA8C;QAV9C,YAAO,GAAP,OAAO,CAAS;QAChB,cAAS,GAAT,SAAS,CAAW;QACpB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,6BAAwB,GAAxB,wBAAwB,CAAgB;QACxC,uBAAkB,GAAlB,kBAAkB,CAAgB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,oBAAe,GAAf,eAAe,CAAgD;QAC/D,wBAAmB,GAAn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
|
-
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../../../src/language-server/inline-completion/telemetry/telemetry.ts"],"names":[],"mappings":";;;AA+GA,sFA4BC;AApID,iDAAqE;AAErE,+EAAqE;AAE9D,MAAM,8BAA8B,GAAG,CAC1C,SAAoB,EACpB,OAA6B,EAC7B,SAAiB,EACnB,EAAE;IACA,MAAM,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,SAAS,CAAA;IACzD,MAAM,IAAI,GAAwC;QAC9C,sBAAsB,EAAE,SAAS;QACjC,sBAAsB,EAAE,OAAO,CAAC,eAAe,EAAE,sBAAsB;QACvE,gCAAgC,EAAE,OAAO,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC;QAChE,2BAA2B,EACvB,OAAO,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAA,yBAAiB,EAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;QAC1F,wBAAwB,EAAE,OAAO,CAAC,WAAW;QAC7C,iCAAiC,EAAE,OAAO,CAAC,eAAe;QAC1D,QAAQ;QACR,uBAAuB,EAAE,OAAO,CAAC,aAAa,CAAC,IAAI;QACnD,yBAAyB,EAAE,OAAO,CAAC,aAAa,CAAC,SAAS;QAC1D,qBAAqB,EAAE,OAAO,CAAC,QAAQ;QACvC,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;QAC9C,uCAAuC,EAAE,OAAO,CAAC,oBAAoB,EAAE,gBAAgB;QACvF,qCAAqC,EAAE,OAAO,CAAC,oBAAoB,EAAE,KAAK;QAC1E,uCAAuC,EAAE,OAAO,CAAC,oBAAoB,EAAE,OAAO;QAC9E,sCAAsC,EAAE,OAAO,CAAC,oBAAoB,EAAE,cAAc;QACpF,6BAA6B,EAAE,OAAO,CAAC,gBAAgB;QACvD,MAAM,EAAE,WAAW;QACnB,wCAAwC,EAAE,OAAO,CAAC,6BAA6B;KAClF,CAAA;IACD,SAAS,CAAC,UAAU,CAAC;QACjB,IAAI,EAAE,iCAAiC;QACvC,MAAM,EAAE,WAAW;QACnB,IAAI,EAAE;YACF,GAAG,IAAI;YACP,wCAAwC,EAAE,OAAO,CAAC,6BAA6B;SAClF;KACJ,CAAC,CAAA;AACN,CAAC,CAAA;AAnCY,QAAA,8BAA8B,kCAmC1C;AAEM,MAAM,4BAA4B,GAAG,CACxC,SAAoB,EACpB,OAA6B,EAC7B,KAAuB,EACzB,EAAE;IACA,MAAM,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,SAAS,CAAA;IACzD,MAAM,sBAAsB,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../../../src/language-server/inline-completion/telemetry/telemetry.ts"],"names":[],"mappings":";;;AA+GA,sFA4BC;AApID,iDAAqE;AAErE,+EAAqE;AAE9D,MAAM,8BAA8B,GAAG,CAC1C,SAAoB,EACpB,OAA6B,EAC7B,SAAiB,EACnB,EAAE;IACA,MAAM,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,SAAS,CAAA;IACzD,MAAM,IAAI,GAAwC;QAC9C,sBAAsB,EAAE,SAAS;QACjC,sBAAsB,EAAE,OAAO,CAAC,eAAe,EAAE,sBAAsB;QACvE,gCAAgC,EAAE,OAAO,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC;QAChE,2BAA2B,EACvB,OAAO,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAA,yBAAiB,EAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;QAC1F,wBAAwB,EAAE,OAAO,CAAC,WAAW;QAC7C,iCAAiC,EAAE,OAAO,CAAC,eAAe;QAC1D,QAA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BAAuC,EACvC,YAAqB,EACrB,MAAe,EACjB,EAAE;IACA,yDAAyD;IACzD,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;QAC/B,OAAM;IACV,CAAC;IAED,wFAAwF;IACxF,0EAA0E;IAC1E,MAAM,mBAAmB,GACrB,OAAO,CAAC,cAAc,KAAK,qCAAc,CAAC,IAAI;QAC1C,CAAC,CAAC,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC;QACxC,CAAC,CAAC,OAAO,CAAC,gCAAgC,EAAE,CAAA;IAEpD,8EAA8E;IAC9E,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACvB,OAAM;IACV,CAAC;IAED,MAAM,IAAA,kDAA0C,EAC5C,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,6BAA6B,EAC7B,gCAAgC,EAChC,kCAAkC,EAClC,mBAAmB,EACnB,qBAAqB,EACrB,YAAY,CACf,CAAA;IAED,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAA;AACvC,CAAC,CAAA;AA1CY,QAAA,gCAAgC,oCA0C5C;AAEM,MAAM,0CAA0C,GAAG,CACtD,gBAAkC,EAClC,OAA6B,EAC7B,mBAAwC,EACxC,6BAAsC,EACtC,gCAAyC,EACzC,kCAA2C,EAC3C,mBAAqC,EACrC,qBAAuC,EACvC,YAAqB,EACvB,EAAE;IACA,OAAO,gBAAgB,CAAC,uBAAuB,CAC3C,OAAO,EACP,mBAAmB,EACnB,6BAA6B,EAC7B,gCAAgC,EAChC,kCAAkC,EAClC,mBAAmB,EACnB,qBAAqB,EACrB,YAAY,CACf,CAAA;AACL,CAAC,CAAA;AArBY,QAAA,0CAA0C,8CAqBtD"}
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
+
import { Hunk } from 'diff';
|
|
5
6
|
import { CodeWhispererSupplementalContext } from '../../../shared/models/model';
|
|
7
|
+
import { Position, TextDocument } from '@aws/language-server-runtimes/protocol';
|
|
8
|
+
import { SuggestionType } from '../../../shared/codeWhispererService';
|
|
6
9
|
/**
|
|
7
10
|
* Generates a unified diff format between old and new file contents
|
|
8
11
|
*
|
|
@@ -37,21 +40,10 @@ export interface FileSnapshotContent {
|
|
|
37
40
|
* @returns CodeWhispererSupplementalContext object containing diffs between snapshots and current content
|
|
38
41
|
*/
|
|
39
42
|
export declare function generateDiffContexts(filePath: string, currentContent: string, snapshotContents: FileSnapshotContent[], maxContexts: number): CodeWhispererSupplementalContext;
|
|
40
|
-
/** src: https://github.com/aws/aws-toolkit-vscode/blob/3921457b0a2094b831beea0d66cc2cbd2a833890/packages/amazonq/src/app/inline/EditRendering/diffUtils.ts#L18
|
|
41
|
-
* Apply a unified diff to original code to generate modified code
|
|
42
|
-
* @param originalCode The original code as a string
|
|
43
|
-
* @param unifiedDiff The unified diff content
|
|
44
|
-
* @returns The modified code after applying the diff
|
|
45
|
-
*/
|
|
46
|
-
export declare function applyUnifiedDiff(docText: string, unifiedDiff: string): string;
|
|
47
43
|
export declare function getAddedAndDeletedLines(unifiedDiff: string): {
|
|
48
44
|
addedLines: string[];
|
|
49
45
|
deletedLines: string[];
|
|
50
46
|
};
|
|
51
|
-
export declare function getAddedAndDeletedChars(unifiedDiff: string): {
|
|
52
|
-
addedCharacters: string;
|
|
53
|
-
deletedCharacters: string;
|
|
54
|
-
};
|
|
55
47
|
/**
|
|
56
48
|
* Calculate character differences between added and deleted text blocks using LCS
|
|
57
49
|
*/
|
|
@@ -63,3 +55,28 @@ export interface CharDiffResult {
|
|
|
63
55
|
* Calculate character differences between added and deleted blocks
|
|
64
56
|
*/
|
|
65
57
|
export declare function getCharacterDifferences(addedLines: string[], deletedLines: string[]): CharDiffResult;
|
|
58
|
+
export declare function processEditSuggestion(unifiedDiff: string, triggerPosition: Position, document: TextDocument, rightContext: string): {
|
|
59
|
+
suggestionContent: string;
|
|
60
|
+
type: SuggestionType;
|
|
61
|
+
};
|
|
62
|
+
interface UnifiedDiff {
|
|
63
|
+
linesWithoutHeaders: string[];
|
|
64
|
+
firstMinusIndex: number;
|
|
65
|
+
firstPlusIndex: number;
|
|
66
|
+
minusIndexes: number[];
|
|
67
|
+
plusIndexes: number[];
|
|
68
|
+
hunk: Hunk;
|
|
69
|
+
}
|
|
70
|
+
export declare function readUdiff(unifiedDiff: string): UnifiedDiff;
|
|
71
|
+
export declare function categorizeUnifieddiff(unifiedDiff: string, userTriggerAtLine?: number): 'addOnly' | 'deleteOnly' | 'edit';
|
|
72
|
+
export declare function extractAdditions(unifiedDiff: string): string;
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* example
|
|
76
|
+
* code = 'return'
|
|
77
|
+
* suggestion = 'return a + b;'
|
|
78
|
+
* output = ' a + b;'
|
|
79
|
+
*/
|
|
80
|
+
export declare function removeOverlapCodeFromSuggestion(code: string, suggestion: string): string;
|
|
81
|
+
export declare function longestCommonPrefix(str1: string, str2: string): string;
|
|
82
|
+
export {};
|
|
@@ -6,12 +6,19 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.generateUnifiedDiffWithTimestamps = generateUnifiedDiffWithTimestamps;
|
|
8
8
|
exports.generateDiffContexts = generateDiffContexts;
|
|
9
|
-
exports.applyUnifiedDiff = applyUnifiedDiff;
|
|
10
9
|
exports.getAddedAndDeletedLines = getAddedAndDeletedLines;
|
|
11
|
-
exports.getAddedAndDeletedChars = getAddedAndDeletedChars;
|
|
12
10
|
exports.getCharacterDifferences = getCharacterDifferences;
|
|
13
|
-
|
|
11
|
+
exports.processEditSuggestion = processEditSuggestion;
|
|
12
|
+
exports.readUdiff = readUdiff;
|
|
13
|
+
exports.categorizeUnifieddiff = categorizeUnifieddiff;
|
|
14
|
+
exports.extractAdditions = extractAdditions;
|
|
15
|
+
exports.removeOverlapCodeFromSuggestion = removeOverlapCodeFromSuggestion;
|
|
16
|
+
exports.longestCommonPrefix = longestCommonPrefix;
|
|
17
|
+
const diff_1 = require("diff");
|
|
14
18
|
const supplementalContextUtil_1 = require("../../../shared/supplementalContextUtil/supplementalContextUtil");
|
|
19
|
+
const protocol_1 = require("@aws/language-server-runtimes/protocol");
|
|
20
|
+
const codeWhispererService_1 = require("../../../shared/codeWhispererService");
|
|
21
|
+
const mergeRightUtils_1 = require("./mergeRightUtils");
|
|
15
22
|
/**
|
|
16
23
|
* Generates a unified diff format between old and new file contents
|
|
17
24
|
*
|
|
@@ -25,7 +32,7 @@ const supplementalContextUtil_1 = require("../../../shared/supplementalContextUt
|
|
|
25
32
|
* @returns Unified diff string
|
|
26
33
|
*/
|
|
27
34
|
function generateUnifiedDiffWithTimestamps(oldFilePath, newFilePath, oldContent, newContent, oldTimestamp, newTimestamp, contextSize = 3) {
|
|
28
|
-
const patchResult =
|
|
35
|
+
const patchResult = (0, diff_1.createTwoFilesPatch)(oldFilePath, newFilePath, oldContent, newContent, String(oldTimestamp), String(newTimestamp), { context: contextSize });
|
|
29
36
|
// Remove unused headers
|
|
30
37
|
const lines = patchResult.split('\n');
|
|
31
38
|
if (lines.length >= 2 && lines[0].startsWith('Index:')) {
|
|
@@ -88,79 +95,6 @@ function generateDiffContexts(filePath, currentContent, snapshotContents, maxCon
|
|
|
88
95
|
strategy: 'recentEdits',
|
|
89
96
|
};
|
|
90
97
|
}
|
|
91
|
-
/** src: https://github.com/aws/aws-toolkit-vscode/blob/3921457b0a2094b831beea0d66cc2cbd2a833890/packages/amazonq/src/app/inline/EditRendering/diffUtils.ts#L18
|
|
92
|
-
* Apply a unified diff to original code to generate modified code
|
|
93
|
-
* @param originalCode The original code as a string
|
|
94
|
-
* @param unifiedDiff The unified diff content
|
|
95
|
-
* @returns The modified code after applying the diff
|
|
96
|
-
*/
|
|
97
|
-
function applyUnifiedDiff(docText, unifiedDiff) {
|
|
98
|
-
try {
|
|
99
|
-
// First try the standard diff package
|
|
100
|
-
try {
|
|
101
|
-
const result = diff.applyPatch(docText, unifiedDiff);
|
|
102
|
-
if (result !== false) {
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (error) { }
|
|
107
|
-
// Parse the unified diff to extract the changes
|
|
108
|
-
const diffLines = unifiedDiff.split('\n');
|
|
109
|
-
let result = docText;
|
|
110
|
-
// Find all hunks in the diff
|
|
111
|
-
const hunkStarts = diffLines
|
|
112
|
-
.map((line, index) => (line.startsWith('@@ ') ? index : -1))
|
|
113
|
-
.filter(index => index !== -1);
|
|
114
|
-
// Process each hunk
|
|
115
|
-
for (const hunkStart of hunkStarts) {
|
|
116
|
-
// Parse the hunk header
|
|
117
|
-
const hunkHeader = diffLines[hunkStart];
|
|
118
|
-
const match = hunkHeader.match(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/);
|
|
119
|
-
if (!match) {
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
const oldStart = parseInt(match[1]);
|
|
123
|
-
const oldLines = parseInt(match[2]);
|
|
124
|
-
// Extract the content lines for this hunk
|
|
125
|
-
let i = hunkStart + 1;
|
|
126
|
-
const contentLines = [];
|
|
127
|
-
while (i < diffLines.length && !diffLines[i].startsWith('@@')) {
|
|
128
|
-
contentLines.push(diffLines[i]);
|
|
129
|
-
i++;
|
|
130
|
-
}
|
|
131
|
-
// Build the old and new text
|
|
132
|
-
let oldText = '';
|
|
133
|
-
let newText = '';
|
|
134
|
-
for (const line of contentLines) {
|
|
135
|
-
if (line.startsWith('-')) {
|
|
136
|
-
oldText += line.substring(1) + '\n';
|
|
137
|
-
}
|
|
138
|
-
else if (line.startsWith('+')) {
|
|
139
|
-
newText += line.substring(1) + '\n';
|
|
140
|
-
}
|
|
141
|
-
else if (line.startsWith(' ')) {
|
|
142
|
-
oldText += line.substring(1) + '\n';
|
|
143
|
-
newText += line.substring(1) + '\n';
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
// Remove trailing newline if it was added
|
|
147
|
-
oldText = oldText.replace(/\n$/, '');
|
|
148
|
-
newText = newText.replace(/\n$/, '');
|
|
149
|
-
// Find the text to replace in the document
|
|
150
|
-
const docLines = docText.split('\n');
|
|
151
|
-
const startLine = oldStart - 1; // Convert to 0-based
|
|
152
|
-
const endLine = startLine + oldLines;
|
|
153
|
-
// Extract the text that should be replaced
|
|
154
|
-
const textToReplace = docLines.slice(startLine, endLine).join('\n');
|
|
155
|
-
// Replace the text
|
|
156
|
-
result = result.replace(textToReplace, newText);
|
|
157
|
-
}
|
|
158
|
-
return result;
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
return docText; // Return original text if all methods fail
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
98
|
function getAddedAndDeletedLines(unifiedDiff) {
|
|
165
99
|
const lines = unifiedDiff.split('\n');
|
|
166
100
|
const addedLines = lines.filter(line => line.startsWith('+') && !line.startsWith('+++')).map(line => line.slice(1));
|
|
@@ -172,46 +106,6 @@ function getAddedAndDeletedLines(unifiedDiff) {
|
|
|
172
106
|
deletedLines,
|
|
173
107
|
};
|
|
174
108
|
}
|
|
175
|
-
// src https://github.com/aws/aws-toolkit-vscode/blob/3921457b0a2094b831beea0d66cc2cbd2a833890/packages/amazonq/src/app/inline/EditRendering/diffUtils.ts#L147
|
|
176
|
-
function getAddedAndDeletedChars(unifiedDiff) {
|
|
177
|
-
let addedCharacters = '';
|
|
178
|
-
let deletedCharacters = '';
|
|
179
|
-
const lines = unifiedDiff.split('\n');
|
|
180
|
-
for (let i = 0; i < lines.length; i++) {
|
|
181
|
-
const line = lines[i];
|
|
182
|
-
if (line.startsWith('+') && !line.startsWith('+++')) {
|
|
183
|
-
addedCharacters += line.slice(1);
|
|
184
|
-
}
|
|
185
|
-
else if (line.startsWith('-') && !line.startsWith('---')) {
|
|
186
|
-
const removedLine = line.slice(1);
|
|
187
|
-
// Check if this is a modified line rather than a pure deletion
|
|
188
|
-
const nextLine = lines[i + 1];
|
|
189
|
-
if (nextLine && nextLine.startsWith('+') && !nextLine.startsWith('+++')) {
|
|
190
|
-
// This is a modified line, not a pure deletion
|
|
191
|
-
// We've already counted the deletion, so we'll just increment i to skip the next line
|
|
192
|
-
// since we'll process the addition on the next iteration
|
|
193
|
-
const addedLine = nextLine.slice(1);
|
|
194
|
-
const changes = diff.diffChars(removedLine, addedLine);
|
|
195
|
-
for (const part of changes) {
|
|
196
|
-
if (part.removed) {
|
|
197
|
-
deletedCharacters += part.value;
|
|
198
|
-
}
|
|
199
|
-
else if (part.added) {
|
|
200
|
-
addedCharacters += part.value;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
i += 1;
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
deletedCharacters += removedLine;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return {
|
|
211
|
-
addedCharacters,
|
|
212
|
-
deletedCharacters,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
109
|
/**
|
|
216
110
|
* Find longest common subsequence length between two strings
|
|
217
111
|
*/
|
|
@@ -252,4 +146,262 @@ function getCharacterDifferences(addedLines, deletedLines) {
|
|
|
252
146
|
charactersRemoved: deletedText.length - lcsLen,
|
|
253
147
|
};
|
|
254
148
|
}
|
|
149
|
+
function processEditSuggestion(unifiedDiff, triggerPosition, document, rightContext) {
|
|
150
|
+
// Assume it's an edit if anything goes wrong, at the very least it will not be rendered incorrectly
|
|
151
|
+
let diffCategory = 'edit';
|
|
152
|
+
try {
|
|
153
|
+
diffCategory = categorizeUnifieddiff(unifiedDiff, triggerPosition.line);
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
// We dont have logger here....
|
|
157
|
+
diffCategory = 'edit';
|
|
158
|
+
}
|
|
159
|
+
if (diffCategory === 'addOnly') {
|
|
160
|
+
const preprocessAdd = extractAdditions(unifiedDiff);
|
|
161
|
+
const leftContextAtTriggerLine = document.getText(protocol_1.Range.create(protocol_1.Position.create(triggerPosition.line, 0), triggerPosition));
|
|
162
|
+
/**
|
|
163
|
+
* SHOULD NOT remove the entire overlapping string, the way inline suggestion prefix matching work depends on where it triggers
|
|
164
|
+
* For example (^ note where user triggers)
|
|
165
|
+
* console.lo
|
|
166
|
+
* ^
|
|
167
|
+
* if LSP returns `g('foo')` instead of `.log()` the suggestion will be discarded because prefix doesnt match
|
|
168
|
+
*/
|
|
169
|
+
const processedAdd = removeOverlapCodeFromSuggestion(leftContextAtTriggerLine, preprocessAdd);
|
|
170
|
+
const mergedWithRightContext = (0, mergeRightUtils_1.truncateOverlapWithRightContext)(rightContext, processedAdd);
|
|
171
|
+
return {
|
|
172
|
+
suggestionContent: mergedWithRightContext,
|
|
173
|
+
type: codeWhispererService_1.SuggestionType.COMPLETION,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
return {
|
|
178
|
+
suggestionContent: unifiedDiff,
|
|
179
|
+
type: codeWhispererService_1.SuggestionType.EDIT,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// TODO: refine
|
|
184
|
+
function readUdiff(unifiedDiff) {
|
|
185
|
+
let hunk;
|
|
186
|
+
try {
|
|
187
|
+
const patches = (0, diff_1.parsePatch)(unifiedDiff);
|
|
188
|
+
if (patches.length !== 1) {
|
|
189
|
+
throw new Error(`Provided unified diff from has 0 or more than 1 patches`);
|
|
190
|
+
}
|
|
191
|
+
hunk = patches[0].hunks[0];
|
|
192
|
+
if (!hunk) {
|
|
193
|
+
throw new Error(`Null hunk`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
throw e;
|
|
198
|
+
}
|
|
199
|
+
// TODO: Should use hunk instead of parsing manually
|
|
200
|
+
const lines = unifiedDiff.split('\n');
|
|
201
|
+
const headerEndIndex = lines.findIndex(l => l.startsWith('@@'));
|
|
202
|
+
if (headerEndIndex === -1) {
|
|
203
|
+
throw new Error('not able to parse');
|
|
204
|
+
}
|
|
205
|
+
const relevantLines = lines.slice(headerEndIndex + 1);
|
|
206
|
+
if (relevantLines.length === 0) {
|
|
207
|
+
throw new Error('not able to parse');
|
|
208
|
+
}
|
|
209
|
+
const minusIndexes = [];
|
|
210
|
+
const plusIndexes = [];
|
|
211
|
+
for (let i = 0; i < relevantLines.length; i++) {
|
|
212
|
+
const l = relevantLines[i];
|
|
213
|
+
if (l.startsWith('-')) {
|
|
214
|
+
minusIndexes.push(i);
|
|
215
|
+
}
|
|
216
|
+
else if (l.startsWith('+')) {
|
|
217
|
+
plusIndexes.push(i);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const firstMinusIndex = relevantLines.findIndex(s => s.startsWith('-'));
|
|
221
|
+
const firstPlusIndex = relevantLines.findIndex(s => s.startsWith('+'));
|
|
222
|
+
// TODO: Comment these out as they are used for a different version of addonly type determination logic in case the current implementation doesn't work.
|
|
223
|
+
// Could remove later if we are sure current imple works.
|
|
224
|
+
/**
|
|
225
|
+
* Concatenate all contiguous added lines (i.e., unbroken sequence of "+"s).
|
|
226
|
+
* Exclude all newlines when concatenating, so we get a single line representing the new text
|
|
227
|
+
*/
|
|
228
|
+
// let singleLine = ''
|
|
229
|
+
// let prev: number | undefined
|
|
230
|
+
// for (const idx of plusIndexes) {
|
|
231
|
+
// if (!prev || idx === prev + 1) {
|
|
232
|
+
// const removedPlus = relevantLines[idx].substring(1)
|
|
233
|
+
// const removedStartNewline = trimStartNewline(removedPlus)
|
|
234
|
+
// singleLine += removedStartNewline
|
|
235
|
+
// } else {
|
|
236
|
+
// break
|
|
237
|
+
// }
|
|
238
|
+
// }
|
|
239
|
+
return {
|
|
240
|
+
linesWithoutHeaders: relevantLines,
|
|
241
|
+
firstMinusIndex: firstMinusIndex,
|
|
242
|
+
firstPlusIndex: firstPlusIndex,
|
|
243
|
+
minusIndexes: minusIndexes,
|
|
244
|
+
plusIndexes: plusIndexes,
|
|
245
|
+
hunk: hunk,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
// Theoretically, we should always pass userTriggerAtLine, keeping it nullable for easier testing for now
|
|
249
|
+
function categorizeUnifieddiff(unifiedDiff, userTriggerAtLine) {
|
|
250
|
+
try {
|
|
251
|
+
const d = readUdiff(unifiedDiff);
|
|
252
|
+
const hunk = d.hunk;
|
|
253
|
+
const firstMinusIndex = d.firstMinusIndex;
|
|
254
|
+
const firstPlusIndex = d.firstPlusIndex;
|
|
255
|
+
const diffWithoutHeaders = d.linesWithoutHeaders;
|
|
256
|
+
// Shouldn't be the case but if there is no - nor +, assume it's an edit
|
|
257
|
+
if (firstMinusIndex === -1 && firstPlusIndex === -1) {
|
|
258
|
+
return 'edit';
|
|
259
|
+
}
|
|
260
|
+
// If first "EDIT" line is not where users trigger, it must be EDIT
|
|
261
|
+
// Note hunk.start is 1 based index
|
|
262
|
+
const firstLineEdited = hunk.oldStart - 1 + Math.min(...d.minusIndexes, ...d.plusIndexes);
|
|
263
|
+
if (userTriggerAtLine !== undefined && userTriggerAtLine !== firstLineEdited) {
|
|
264
|
+
return 'edit';
|
|
265
|
+
}
|
|
266
|
+
// Naive case, only +
|
|
267
|
+
if (firstMinusIndex === -1 && firstPlusIndex !== -1) {
|
|
268
|
+
return 'addOnly';
|
|
269
|
+
}
|
|
270
|
+
// Naive case, only -
|
|
271
|
+
if (firstMinusIndex !== -1 && firstPlusIndex === -1) {
|
|
272
|
+
return 'deleteOnly';
|
|
273
|
+
}
|
|
274
|
+
const minusIndexes = d.minusIndexes;
|
|
275
|
+
const plusIndexes = d.plusIndexes;
|
|
276
|
+
// If there are multiple (> 1) non empty '-' lines, it must be edit
|
|
277
|
+
const c = minusIndexes.reduce((acc, cur) => {
|
|
278
|
+
if (diffWithoutHeaders[cur].trim().length > 0) {
|
|
279
|
+
return acc++;
|
|
280
|
+
}
|
|
281
|
+
return acc;
|
|
282
|
+
}, 0);
|
|
283
|
+
if (c > 1) {
|
|
284
|
+
return 'edit';
|
|
285
|
+
}
|
|
286
|
+
// If last '-' line is followed by '+' block, it could be addonly
|
|
287
|
+
if (plusIndexes[0] === minusIndexes[minusIndexes.length - 1] + 1) {
|
|
288
|
+
/**
|
|
289
|
+
-------------------------------
|
|
290
|
+
- return
|
|
291
|
+
+ return a - b;
|
|
292
|
+
-------------------------------
|
|
293
|
+
commonPrefix = "return "
|
|
294
|
+
minusLinesDelta = ""
|
|
295
|
+
|
|
296
|
+
--------------------------------
|
|
297
|
+
-\t\t\t
|
|
298
|
+
+\treturn a - b;
|
|
299
|
+
--------------------------------
|
|
300
|
+
commonPrefix = "\t"
|
|
301
|
+
minusLinesDelta = "\t\t"
|
|
302
|
+
|
|
303
|
+
*
|
|
304
|
+
*
|
|
305
|
+
*
|
|
306
|
+
*/
|
|
307
|
+
const minusLine = diffWithoutHeaders[minusIndexes[minusIndexes.length - 1]].substring(1);
|
|
308
|
+
const pluscode = extractAdditions(unifiedDiff);
|
|
309
|
+
// If minusLine subtract the longest common substring of minusLine and plugcode and it's empty string, it's addonly
|
|
310
|
+
const commonPrefix = longestCommonPrefix(minusLine, pluscode);
|
|
311
|
+
const minusLinesDelta = minusLine.substring(commonPrefix.length);
|
|
312
|
+
if (minusLinesDelta.trim().length === 0) {
|
|
313
|
+
return 'addOnly';
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
-------------------------------
|
|
317
|
+
- return a * b;
|
|
318
|
+
+ return a * b * c;
|
|
319
|
+
-------------------------------
|
|
320
|
+
commonPrefix = "return a * b"
|
|
321
|
+
minusLinesDelta = ";"
|
|
322
|
+
pluscodeDelta = " * c;"
|
|
323
|
+
*
|
|
324
|
+
*/
|
|
325
|
+
const pluscodeDelta = pluscode.substring(commonPrefix.length);
|
|
326
|
+
if (pluscodeDelta.endsWith(minusLinesDelta)) {
|
|
327
|
+
return 'addOnly';
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return 'edit';
|
|
331
|
+
}
|
|
332
|
+
catch (e) {
|
|
333
|
+
return 'edit';
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// TODO: current implementation here assumes service only return 1 chunk of edits (consecutive lines) and hacky
|
|
337
|
+
function extractAdditions(unifiedDiff) {
|
|
338
|
+
const lines = unifiedDiff.split('\n');
|
|
339
|
+
let completionSuggestion = '';
|
|
340
|
+
let isInAdditionBlock = false;
|
|
341
|
+
for (const line of lines) {
|
|
342
|
+
// Skip diff headers (files)
|
|
343
|
+
if (line.startsWith('+++') || line.startsWith('---')) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
// Skip hunk headers (@@ lines)
|
|
347
|
+
if (line.startsWith('@@')) {
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
// Handle additions
|
|
351
|
+
if (line.startsWith('+')) {
|
|
352
|
+
completionSuggestion += line.substring(1) + '\n';
|
|
353
|
+
isInAdditionBlock = true;
|
|
354
|
+
}
|
|
355
|
+
else if (isInAdditionBlock && !line.startsWith('+')) {
|
|
356
|
+
// End of addition block
|
|
357
|
+
isInAdditionBlock = false;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
// Remove trailing newline
|
|
361
|
+
return completionSuggestion.trimEnd();
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
*
|
|
365
|
+
* example
|
|
366
|
+
* code = 'return'
|
|
367
|
+
* suggestion = 'return a + b;'
|
|
368
|
+
* output = ' a + b;'
|
|
369
|
+
*/
|
|
370
|
+
function removeOverlapCodeFromSuggestion(code, suggestion) {
|
|
371
|
+
const suggestionLines = suggestion.split('\n');
|
|
372
|
+
const firstLineSuggestion = suggestionLines[0];
|
|
373
|
+
// Find the common string in code surfix and prefix of suggestion
|
|
374
|
+
const s = (0, mergeRightUtils_1.getPrefixSuffixOverlap)(code, firstLineSuggestion);
|
|
375
|
+
// Remove overlap s from suggestion
|
|
376
|
+
return suggestion.substring(s.length);
|
|
377
|
+
}
|
|
378
|
+
function longestCommonPrefix(str1, str2) {
|
|
379
|
+
const minLength = Math.min(str1.length, str2.length);
|
|
380
|
+
let prefix = '';
|
|
381
|
+
for (let i = 0; i < minLength; i++) {
|
|
382
|
+
if (str1[i] === str2[i]) {
|
|
383
|
+
prefix += str1[i];
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return prefix;
|
|
390
|
+
}
|
|
391
|
+
// TODO: They are used for a different version of addonly type determination logic in case the current implementation doesn't work.
|
|
392
|
+
// Could remove later if we are sure current impl works.
|
|
393
|
+
// function trimStartNewline(str: string): string {
|
|
394
|
+
// return str.replace(/^[\n\r]+/, '')
|
|
395
|
+
// }
|
|
396
|
+
// function hasOneContiguousInsert(original: string, changed: string) {
|
|
397
|
+
// const delta = changed.length - original.length
|
|
398
|
+
// if (delta <= 0) {
|
|
399
|
+
// // Changed string must be longer
|
|
400
|
+
// return false
|
|
401
|
+
// }
|
|
402
|
+
// let p, s
|
|
403
|
+
// for (p = 0; original[p] === changed[p] && p < original.length; ++p);
|
|
404
|
+
// for (s = original.length - 1; original[s] === changed[s + delta] && s >= 0; --s);
|
|
405
|
+
// return p === s + 1
|
|
406
|
+
// }
|
|
255
407
|
//# sourceMappingURL=diffUtils.js.map
|