27
27
import com .redhat .devtools .lsp4ij .client .features .LSPFormattingFeature ;
28
28
import com .redhat .devtools .lsp4ij .client .features .LSPFormattingFeature .FormattingScope ;
29
29
import com .redhat .devtools .lsp4ij .client .features .LSPOnTypeFormattingFeature ;
30
+ import com .redhat .devtools .lsp4ij .client .indexing .ProjectIndexingManager ;
30
31
import com .redhat .devtools .lsp4ij .features .codeBlockProvider .LSPCodeBlockProvider ;
31
32
import com .redhat .devtools .lsp4ij .features .completion .LSPCompletionTriggerTypedHandler ;
32
33
import com .redhat .devtools .lsp4ij .features .selectionRange .LSPSelectionRangeSupport ;
@@ -52,96 +53,98 @@ public Result charTyped(char charTyped,
52
53
@ NotNull Project project ,
53
54
@ NotNull Editor editor ,
54
55
@ NotNull PsiFile file ) {
55
- // Gather all of the relevant client configuration
56
- Ref <Boolean > rangeFormattingSupportedRef = Ref .create (false );
57
- ClientSideOnTypeFormattingSettings onTypeFormattingSettings = new ClientSideOnTypeFormattingSettings ();
58
- LanguageServiceAccessor .getInstance (project ).processLanguageServers (
59
- file ,
60
- ls -> {
61
- // Only include servers that support formatting and don't support server-side on-type formatting
62
- LSPClientFeatures clientFeatures = ls .getClientFeatures ();
63
- LSPFormattingFeature formattingFeature = clientFeatures .getFormattingFeature ();
64
- LSPOnTypeFormattingFeature onTypeFormattingFeature = clientFeatures .getOnTypeFormattingFeature ();
65
- if (formattingFeature .isEnabled (file ) && formattingFeature .isSupported (file ) &&
66
- (!onTypeFormattingFeature .isEnabled (file ) || !onTypeFormattingFeature .isSupported (file ))) {
67
- rangeFormattingSupportedRef .set (rangeFormattingSupportedRef .get () || formattingFeature .isRangeFormattingSupported (file ));
68
-
69
- onTypeFormattingSettings .formatOnCloseBrace |= formattingFeature .isFormatOnCloseBrace (file );
70
- FormattingScope formatOnCloseBraceScope = formattingFeature .getFormatOnCloseBraceScope (file );
71
- if (formatOnCloseBraceScope .compareTo (onTypeFormattingSettings .formatOnCloseBraceScope ) > 0 ) {
72
- onTypeFormattingSettings .formatOnCloseBraceScope = formatOnCloseBraceScope ;
73
- }
74
- onTypeFormattingSettings .formatOnCloseBraceCharacters += formattingFeature .getFormatOnCloseBraceCharacters (file );
56
+ if (!ProjectIndexingManager .isIndexing (project )) {
57
+ // Gather all of the relevant client configuration
58
+ Ref <Boolean > rangeFormattingSupportedRef = Ref .create (false );
59
+ ClientSideOnTypeFormattingSettings onTypeFormattingSettings = new ClientSideOnTypeFormattingSettings ();
60
+ LanguageServiceAccessor .getInstance (project ).processLanguageServers (
61
+ file ,
62
+ ls -> {
63
+ // Only include servers that support formatting and don't support server-side on-type formatting
64
+ LSPClientFeatures clientFeatures = ls .getClientFeatures ();
65
+ LSPFormattingFeature formattingFeature = clientFeatures .getFormattingFeature ();
66
+ LSPOnTypeFormattingFeature onTypeFormattingFeature = clientFeatures .getOnTypeFormattingFeature ();
67
+ if (formattingFeature .isEnabled (file ) && formattingFeature .isSupported (file ) &&
68
+ (!onTypeFormattingFeature .isEnabled (file ) || !onTypeFormattingFeature .isSupported (file ))) {
69
+ rangeFormattingSupportedRef .set (rangeFormattingSupportedRef .get () || formattingFeature .isRangeFormattingSupported (file ));
70
+
71
+ onTypeFormattingSettings .formatOnCloseBrace |= formattingFeature .isFormatOnCloseBrace (file );
72
+ FormattingScope formatOnCloseBraceScope = formattingFeature .getFormatOnCloseBraceScope (file );
73
+ if (formatOnCloseBraceScope .compareTo (onTypeFormattingSettings .formatOnCloseBraceScope ) > 0 ) {
74
+ onTypeFormattingSettings .formatOnCloseBraceScope = formatOnCloseBraceScope ;
75
+ }
76
+ onTypeFormattingSettings .formatOnCloseBraceCharacters += formattingFeature .getFormatOnCloseBraceCharacters (file );
75
77
76
- onTypeFormattingSettings .formatOnStatementTerminator |= formattingFeature .isFormatOnStatementTerminator (file );
77
- FormattingScope formatOnStatementTerminatorScope = formattingFeature .getFormatOnStatementTerminatorScope (file );
78
- if (formatOnStatementTerminatorScope .compareTo (onTypeFormattingSettings .formatOnStatementTerminatorScope ) > 0 ) {
79
- onTypeFormattingSettings .formatOnStatementTerminatorScope = formatOnStatementTerminatorScope ;
80
- }
81
- onTypeFormattingSettings .formatOnStatementTerminatorCharacters += formattingFeature .getFormatOnStatementTerminatorCharacters (file );
78
+ onTypeFormattingSettings .formatOnStatementTerminator |= formattingFeature .isFormatOnStatementTerminator (file );
79
+ FormattingScope formatOnStatementTerminatorScope = formattingFeature .getFormatOnStatementTerminatorScope (file );
80
+ if (formatOnStatementTerminatorScope .compareTo (onTypeFormattingSettings .formatOnStatementTerminatorScope ) > 0 ) {
81
+ onTypeFormattingSettings .formatOnStatementTerminatorScope = formatOnStatementTerminatorScope ;
82
+ }
83
+ onTypeFormattingSettings .formatOnStatementTerminatorCharacters += formattingFeature .getFormatOnStatementTerminatorCharacters (file );
82
84
83
- onTypeFormattingSettings .formatOnCompletionTrigger |= formattingFeature .isFormatOnCompletionTrigger (file );
84
- onTypeFormattingSettings .formatOnCompletionTriggerCharacters += formattingFeature .getFormatOnCompletionTriggerCharacters (file );
85
+ onTypeFormattingSettings .formatOnCompletionTrigger |= formattingFeature .isFormatOnCompletionTrigger (file );
86
+ onTypeFormattingSettings .formatOnCompletionTriggerCharacters += formattingFeature .getFormatOnCompletionTriggerCharacters (file );
87
+ }
85
88
}
86
- }
87
- );
88
- boolean rangeFormattingSupported = rangeFormattingSupportedRef .get ();
89
-
90
- // Close braces
91
- if (onTypeFormattingSettings .formatOnCloseBrace &&
92
- // Make sure the formatter supports formatting of the configured scope
93
- ((onTypeFormattingSettings .formatOnCloseBraceScope == FormattingScope .FILE ) || rangeFormattingSupported )) {
94
- Map .Entry <Character , Character > bracePair = ContainerUtil .find (
95
- LSPIJEditorUtils .getBracePairs (file ).entrySet (),
96
- entry -> entry .getValue () == charTyped
97
89
);
98
- if (bracePair != null ) {
99
- Character openBraceChar = bracePair .getKey ();
100
- Character closeBraceChar = bracePair .getValue ();
101
- if (StringUtil .isEmpty (onTypeFormattingSettings .formatOnCloseBraceCharacters ) ||
102
- (onTypeFormattingSettings .formatOnCloseBraceCharacters .indexOf (closeBraceChar ) > -1 )) {
103
- return handleCloseBraceTyped (
90
+ boolean rangeFormattingSupported = rangeFormattingSupportedRef .get ();
91
+
92
+ // Close braces
93
+ if (onTypeFormattingSettings .formatOnCloseBrace &&
94
+ // Make sure the formatter supports formatting of the configured scope
95
+ ((onTypeFormattingSettings .formatOnCloseBraceScope == FormattingScope .FILE ) || rangeFormattingSupported )) {
96
+ Map .Entry <Character , Character > bracePair = ContainerUtil .find (
97
+ LSPIJEditorUtils .getBracePairs (file ).entrySet (),
98
+ entry -> entry .getValue () == charTyped
99
+ );
100
+ if (bracePair != null ) {
101
+ Character openBraceChar = bracePair .getKey ();
102
+ Character closeBraceChar = bracePair .getValue ();
103
+ if (StringUtil .isEmpty (onTypeFormattingSettings .formatOnCloseBraceCharacters ) ||
104
+ (onTypeFormattingSettings .formatOnCloseBraceCharacters .indexOf (closeBraceChar ) > -1 )) {
105
+ return handleCloseBraceTyped (
106
+ project ,
107
+ editor ,
108
+ file ,
109
+ onTypeFormattingSettings .formatOnCloseBraceScope ,
110
+ openBraceChar ,
111
+ closeBraceChar
112
+ );
113
+ }
114
+ }
115
+ }
116
+
117
+ // Statement terminators
118
+ if (onTypeFormattingSettings .formatOnStatementTerminator &&
119
+ // Make sure the formatter supports formatting of the configured scope
120
+ ((onTypeFormattingSettings .formatOnStatementTerminatorScope == FormattingScope .FILE ) || rangeFormattingSupported )) {
121
+ if (StringUtil .isNotEmpty (onTypeFormattingSettings .formatOnStatementTerminatorCharacters ) &&
122
+ (onTypeFormattingSettings .formatOnStatementTerminatorCharacters .indexOf (charTyped ) > -1 )) {
123
+ return handleStatementTerminatorTyped (
104
124
project ,
105
125
editor ,
106
126
file ,
107
- onTypeFormattingSettings .formatOnCloseBraceScope ,
108
- openBraceChar ,
109
- closeBraceChar
127
+ onTypeFormattingSettings .formatOnStatementTerminatorScope ,
128
+ charTyped
110
129
);
111
130
}
112
131
}
113
- }
114
-
115
- // Statement terminators
116
- if (onTypeFormattingSettings .formatOnStatementTerminator &&
117
- // Make sure the formatter supports formatting of the configured scope
118
- ((onTypeFormattingSettings .formatOnStatementTerminatorScope == FormattingScope .FILE ) || rangeFormattingSupported )) {
119
- if (StringUtil .isNotEmpty (onTypeFormattingSettings .formatOnStatementTerminatorCharacters ) &&
120
- (onTypeFormattingSettings .formatOnStatementTerminatorCharacters .indexOf (charTyped ) > -1 )) {
121
- return handleStatementTerminatorTyped (
122
- project ,
123
- editor ,
124
- file ,
125
- onTypeFormattingSettings .formatOnStatementTerminatorScope ,
126
- charTyped
127
- );
128
- }
129
- }
130
132
131
- // Completion triggers
132
- if (onTypeFormattingSettings .formatOnCompletionTrigger &&
133
- // Make sure the formatter supports range formatting
134
- rangeFormattingSupported &&
135
- // It must be a completion trigger character for the language no matter what
136
- LSPCompletionTriggerTypedHandler .hasLanguageServerSupportingCompletionTriggerCharacters (charTyped , project , file )) {
137
- // But the subset that should trigger completion can be configured
138
- if (StringUtil .isEmpty (onTypeFormattingSettings .formatOnCompletionTriggerCharacters ) ||
139
- (onTypeFormattingSettings .formatOnCompletionTriggerCharacters .indexOf (charTyped ) > -1 )) {
140
- return handleCompletionTriggerTyped (
141
- project ,
142
- editor ,
143
- file
144
- );
133
+ // Completion triggers
134
+ if (onTypeFormattingSettings .formatOnCompletionTrigger &&
135
+ // Make sure the formatter supports range formatting
136
+ rangeFormattingSupported &&
137
+ // It must be a completion trigger character for the language no matter what
138
+ LSPCompletionTriggerTypedHandler .hasLanguageServerSupportingCompletionTriggerCharacters (charTyped , project , file )) {
139
+ // But the subset that should trigger completion can be configured
140
+ if (StringUtil .isEmpty (onTypeFormattingSettings .formatOnCompletionTriggerCharacters ) ||
141
+ (onTypeFormattingSettings .formatOnCompletionTriggerCharacters .indexOf (charTyped ) > -1 )) {
142
+ return handleCompletionTriggerTyped (
143
+ project ,
144
+ editor ,
145
+ file
146
+ );
147
+ }
145
148
}
146
149
}
147
150
0 commit comments