mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[gtw] GTW-832 refactor cache and its loading for autocompletion for remote project path field selection in gateway
GitOrigin-RevId: 92a8b60285770bae639657dc39dd235ca6bc8a90
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2b49bf9d9d
commit
0ef68e4a53
+14
-7
@@ -80,15 +80,22 @@ public abstract class TextFieldWithAutoCompletionListProvider<T> extends Default
|
||||
public void fillCompletionVariants(@NotNull CompletionParameters parameters,
|
||||
@NotNull String prefix,
|
||||
@NotNull CompletionResultSet result) {
|
||||
addCachedItems(parameters, prefix, result);
|
||||
addNonCachedItems(parameters, prefix, result);
|
||||
}
|
||||
|
||||
private void addCachedItems(@NotNull CompletionParameters parameters, @NotNull String prefix, @NotNull CompletionResultSet result) {
|
||||
Collection<T> items = getItems(prefix, true, parameters);
|
||||
addCompletionElements(result, this, items, -10000);
|
||||
}
|
||||
|
||||
private void addNonCachedItems(@NotNull CompletionParameters parameters, @NotNull String prefix, @NotNull CompletionResultSet result) {
|
||||
final ProgressManager progressManager = ProgressManager.getInstance();
|
||||
ProgressIndicator mainIndicator = progressManager.getProgressIndicator();
|
||||
final ProgressIndicator indicator = mainIndicator != null ? new SensitiveProgressWrapper(mainIndicator) : new EmptyProgressIndicator();
|
||||
Future<Collection<T>>
|
||||
future =
|
||||
ApplicationManager.getApplication().executeOnPooledThread(() -> progressManager.runProcess(() -> getItems(prefix, false, parameters), indicator));
|
||||
Future<Collection<T>> future = ApplicationManager
|
||||
.getApplication()
|
||||
.executeOnPooledThread(() -> progressManager.runProcess(() -> getItems(prefix, false, parameters), indicator));
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
@@ -108,10 +115,10 @@ public abstract class TextFieldWithAutoCompletionListProvider<T> extends Default
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void addCompletionElements(final CompletionResultSet result,
|
||||
final TextCompletionValueDescriptor<T> descriptor,
|
||||
final Collection<? extends T> items,
|
||||
final int index) {
|
||||
protected static <T> void addCompletionElements(final CompletionResultSet result,
|
||||
final TextCompletionValueDescriptor<T> descriptor,
|
||||
final Collection<? extends T> items,
|
||||
final int index) {
|
||||
final AutoCompletionPolicy completionPolicy = ApplicationManager.getApplication().isUnitTestMode()
|
||||
? AutoCompletionPolicy.ALWAYS_AUTOCOMPLETE
|
||||
: AutoCompletionPolicy.NEVER_AUTOCOMPLETE;
|
||||
|
||||
+5
@@ -3,6 +3,7 @@ package com.intellij.ui;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComponentWithBrowseButton;
|
||||
import com.intellij.util.textCompletion.TextCompletionCache;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -17,6 +18,10 @@ public class TextFieldWithAutoCompletionWithBrowseButton
|
||||
super(TextFieldWithAutoCompletion.create(project, Collections.emptyList(), false, null), null);
|
||||
}
|
||||
|
||||
public TextFieldWithAutoCompletionWithBrowseButton(Project project, TextCompletionCache<String> cache, boolean prefixMatchesOnly) {
|
||||
super(TextFieldWithAutoCompletionWithCache.create(cache, prefixMatchesOnly, project, null, false, null), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return getChildComponent().getText();
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.ui;
|
||||
|
||||
import com.intellij.codeInsight.completion.PlainPrefixMatcher;
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.textCompletion.TextCompletionCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class TextFieldWithAutoCompletionWithCache<T> extends TextFieldWithAutoCompletion<T> {
|
||||
public TextFieldWithAutoCompletionWithCache(@Nullable Project project,
|
||||
@NotNull TextFieldWithAutoCompletionWithCacheListProvider<T> provider,
|
||||
boolean showCompletionHint, @Nullable String text) {
|
||||
super(project, provider, showCompletionHint, text);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TextFieldWithAutoCompletionWithCache<String> create(@NotNull TextCompletionCache<String> cache,
|
||||
boolean prefixMatchesOnly,
|
||||
@Nullable Project project,
|
||||
@Nullable Icon icon,
|
||||
boolean showCompletionHint,
|
||||
@Nullable String text) {
|
||||
return new TextFieldWithAutoCompletionWithCache<>(project, new StringsCompletionWithCacheProvider(cache, prefixMatchesOnly, icon), showCompletionHint, text);
|
||||
}
|
||||
|
||||
private static class StringsCompletionWithCacheProvider extends TextFieldWithAutoCompletionWithCacheListProvider<String> implements DumbAware {
|
||||
@Nullable private final Icon myIcon;
|
||||
private final boolean myPrefixMatchesOnly;
|
||||
|
||||
private StringsCompletionWithCacheProvider(@NotNull TextCompletionCache<String> cache, boolean prefixMatchesOnly, @Nullable Icon icon) {
|
||||
super(cache);
|
||||
myIcon = icon;
|
||||
myPrefixMatchesOnly = prefixMatchesOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(String item1, String item2) {
|
||||
return StringUtil.compare(item1, item2, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Icon getIcon(@NotNull String item) {
|
||||
return myIcon;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getLookupString(@NotNull String item) {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PrefixMatcher createPrefixMatcher(@NotNull String prefix) {
|
||||
return new PlainPrefixMatcher(prefix, myPrefixMatchesOnly);
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.ui;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionParameters;
|
||||
import com.intellij.util.textCompletion.TextCompletionCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public abstract class TextFieldWithAutoCompletionWithCacheListProvider<T> extends TextFieldWithAutoCompletionListProvider<T> {
|
||||
protected TextCompletionCache<T> myCache;
|
||||
|
||||
public TextFieldWithAutoCompletionWithCacheListProvider(@NotNull TextCompletionCache<T> cache) {
|
||||
super(Collections.emptyList());
|
||||
myCache = cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItems(@Nullable Collection<T> variants) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<T> getItems(String prefix, boolean cached, CompletionParameters parameters) {
|
||||
if (!cached) {
|
||||
myCache.updateCache(prefix, parameters);
|
||||
}
|
||||
return myCache.getItems(prefix, parameters);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.util.textCompletion;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionParameters;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface TextCompletionCache<T> {
|
||||
void setItems(@NotNull Collection<T> items);
|
||||
|
||||
Collection<T> getItems(@NotNull String prefix, @NotNull CompletionParameters parameters);
|
||||
|
||||
void updateCache(@NotNull String prefix, @NotNull CompletionParameters parameters);
|
||||
}
|
||||
Reference in New Issue
Block a user