mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
IDEA-102818 Accept Java name completion suggestions by Enter
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMember;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
import com.intellij.util.ThreeState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class JavaNameIdentifierConfidence extends CompletionConfidence {
|
||||
@NotNull
|
||||
@Override
|
||||
public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) {
|
||||
if (CodeInsightSettings.getInstance().SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS) {
|
||||
return ThreeState.UNSURE;
|
||||
}
|
||||
|
||||
final PsiElement position = parameters.getPosition();
|
||||
final PsiElement parent = position.getParent();
|
||||
if (parent instanceof PsiVariable || parent instanceof PsiMember) {
|
||||
final PsiElement nameIdentifier = ((PsiNameIdentifierOwner)parent).getNameIdentifier();
|
||||
if (parent.getLanguage().isKindOf(JavaLanguage.INSTANCE) && nameIdentifier == position) {
|
||||
return ThreeState.YES;
|
||||
}
|
||||
}
|
||||
return ThreeState.UNSURE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1345,4 +1345,36 @@ class Foo {
|
||||
'''
|
||||
}
|
||||
|
||||
public void "test no focus in variable name"() {
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class FooBar {
|
||||
void foo() {
|
||||
FooBar <caret>
|
||||
}
|
||||
}
|
||||
'''
|
||||
type 'f'
|
||||
assert lookup
|
||||
assert !lookup.focused
|
||||
type '\n'
|
||||
assert !myFixture.editor.document.text.contains('fooBar')
|
||||
}
|
||||
|
||||
public void "test choose variable name by enter when selection by chars is disabled"() {
|
||||
CodeInsightSettings.instance.SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS = false
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class FooBar {
|
||||
void foo() {
|
||||
FooBar <caret>
|
||||
}
|
||||
}
|
||||
'''
|
||||
type 'f'
|
||||
assert lookup
|
||||
assert !lookup.focused
|
||||
assert myFixture.lookupElementStrings == ['fooBar']
|
||||
type '\n'
|
||||
assert myFixture.editor.document.text.contains('fooBar')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -278,6 +278,7 @@
|
||||
<lookup.actionProvider implementation="com.intellij.codeInsight.completion.ExcludeFromCompletionLookupActionProvider"
|
||||
id="excludeFromCompletion" order="last"/>
|
||||
|
||||
<completion.confidence language="JAVA" implementationClass="com.intellij.codeInsight.completion.JavaNameIdentifierConfidence" id="javaNameIdentifierDefault"/>
|
||||
<completion.confidence language="JAVA" implementationClass="com.intellij.codeInsight.completion.UnfocusedNameIdentifier" id="javaNameIdentifier"/>
|
||||
<completion.confidence language="JAVA" implementationClass="com.intellij.codeInsight.completion.FocusInJavadoc" id="javadoc" order="before javaComments"/>
|
||||
<completion.confidence language="JAVA" implementationClass="com.intellij.codeInsight.completion.UnfocusedComments" id="javaComments"/>
|
||||
|
||||
Reference in New Issue
Block a user