File tree Expand file tree Collapse file tree 2 files changed +58
-2
lines changed
plugin/src/software/aws/toolkits/eclipse/amazonq/util Expand file tree Collapse file tree 2 files changed +58
-2
lines changed Original file line number Diff line number Diff line change 28
28
29
29
import static software .aws .toolkits .eclipse .amazonq .util .QConstants .Q_INLINE_HINT_TEXT_STYLE ;
30
30
import static software .aws .toolkits .eclipse .amazonq .util .QEclipseEditorUtils .getActiveTextViewer ;
31
+ import static software .aws .toolkits .eclipse .amazonq .util .SuggestionTextUtil .replaceSpacesWithTabs ;
31
32
32
33
public final class QInvocationSession extends QResource {
33
34
@@ -160,8 +161,8 @@ public void invoke() {
160
161
.inlineCompletionWithReferences (params )
161
162
.thenApply (result -> result .getItems ().parallelStream ().map (item -> {
162
163
if (isTabOnly ) {
163
- String origText = item .getInsertText ();
164
- String sanitizedText = origText .replace ("\n " + " " . repeat ( tabSize ) , "\n \t " );
164
+ String sanitizedText = replaceSpacesWithTabs ( item .getInsertText (), tabSize );
165
+ System . out . println ( "Sanitized text: " + sanitizedText .replace ("\n " , " \\ n" ). replace ( " \t " , "\\ t" ) );
165
166
item .setInsertText (sanitizedText );
166
167
}
167
168
return item ;
Original file line number Diff line number Diff line change
1
+ // Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+
3
+ package software .aws .toolkits .eclipse .amazonq .util ;
4
+
5
+ public final class SuggestionTextUtil {
6
+
7
+ private SuggestionTextUtil () {
8
+ }
9
+
10
+ public static String replaceSpacesWithTabs (String input , int tabSize ) {
11
+ StringBuilder result = new StringBuilder ();
12
+ String [] lines = input .split ("\\ r?\\ n" );
13
+
14
+ for (int i = 0 ; i < lines .length ; i ++) {
15
+ String line = lines [i ];
16
+ int numSpaces = 0 ;
17
+ StringBuilder newLine = new StringBuilder ();
18
+
19
+ for (int j = 0 ; j < line .length (); j ++) {
20
+ char c = line .charAt (j );
21
+ if (c == ' ' ) {
22
+ numSpaces ++;
23
+ } else {
24
+ newLine .append (getTabsForSpaces (numSpaces , tabSize ));
25
+ newLine .append (c );
26
+ numSpaces = 0 ;
27
+ }
28
+ }
29
+
30
+ if (i < lines .length - 1 ) {
31
+ newLine .append ("\n " );
32
+ }
33
+
34
+ result .append (newLine );
35
+ }
36
+
37
+ return result .toString ();
38
+ }
39
+
40
+ private static String getTabsForSpaces (int numSpaces , int tabSize ) {
41
+ int numTabs = numSpaces / tabSize ;
42
+ StringBuilder tabs = new StringBuilder ();
43
+
44
+ for (int i = 0 ; i < numTabs ; i ++) {
45
+ tabs .append ("\t " );
46
+ }
47
+
48
+ int remainingSpaces = numSpaces % tabSize ;
49
+ for (int i = 0 ; i < remainingSpaces ; i ++) {
50
+ tabs .append (" " );
51
+ }
52
+
53
+ return tabs .toString ();
54
+ }
55
+ }
You can’t perform that action at this time.
0 commit comments