Skip to content

Commit 31582ea

Browse files
committed
Restored the check for indexing.
1 parent fc97cdf commit 31582ea

File tree

1 file changed

+82
-79
lines changed

1 file changed

+82
-79
lines changed

src/main/java/com/redhat/devtools/lsp4ij/features/formatting/LSPClientSideOnTypeFormattingTypedHandler.java

+82-79
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.redhat.devtools.lsp4ij.client.features.LSPFormattingFeature;
2828
import com.redhat.devtools.lsp4ij.client.features.LSPFormattingFeature.FormattingScope;
2929
import com.redhat.devtools.lsp4ij.client.features.LSPOnTypeFormattingFeature;
30+
import com.redhat.devtools.lsp4ij.client.indexing.ProjectIndexingManager;
3031
import com.redhat.devtools.lsp4ij.features.codeBlockProvider.LSPCodeBlockProvider;
3132
import com.redhat.devtools.lsp4ij.features.completion.LSPCompletionTriggerTypedHandler;
3233
import com.redhat.devtools.lsp4ij.features.selectionRange.LSPSelectionRangeSupport;
@@ -52,96 +53,98 @@ public Result charTyped(char charTyped,
5253
@NotNull Project project,
5354
@NotNull Editor editor,
5455
@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);
7577

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);
8284

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+
}
8588
}
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
9789
);
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(
104124
project,
105125
editor,
106126
file,
107-
onTypeFormattingSettings.formatOnCloseBraceScope,
108-
openBraceChar,
109-
closeBraceChar
127+
onTypeFormattingSettings.formatOnStatementTerminatorScope,
128+
charTyped
110129
);
111130
}
112131
}
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-
}
130132

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+
}
145148
}
146149
}
147150

0 commit comments

Comments
 (0)