IDEA-98818 Cyclic expand word doesn't work as expected for newly defined variables

This commit is contained in:
peter
2013-01-11 14:15:42 +01:00
parent d94a902ccd
commit 3e96a9a2f5
2 changed files with 51 additions and 14 deletions

View File

@@ -0,0 +1,36 @@
/*
* 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.testFramework.fixtures.LightCodeInsightFixtureTestCase
/**
* @author peter
*/
class HippieCompletionTest extends LightCodeInsightFixtureTestCase {
public void testDollars() {
myFixture.configureByText "a.txt", '''
$some_long_variable_name = Obj::instance();
$some_lon<caret>
'''
myFixture.performEditorAction("HippieCompletion")
myFixture.checkResult '''
$some_long_variable_name = Obj::instance();
$some_long_variable_name<caret>
'''
}
}

View File

@@ -237,25 +237,26 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler {
}
private static CompletionData computeData(final Editor editor, final CharSequence charsSequence) {
int offset = editor.getCaretModel().getOffset();
while (offset > 1 && Character.isJavaIdentifierPart(charsSequence.charAt(offset - 1))) offset--;
final int offset = editor.getCaretModel().getOffset();
final CompletionData data = new CompletionData();
int endOffset = offset;
data.startOffset = offset;
while (charsSequence.length() > endOffset && Character.isJavaIdentifierPart(charsSequence.charAt(endOffset)) &&
endOffset < editor.getDocument().getTextLength()) {
if (endOffset == editor.getCaretModel().getOffset()) {
data.myPrefix = charsSequence.subSequence(offset, endOffset).toString();
IdTableBuilding.scanWords(new IdTableBuilding.ScanWordProcessor() {
@Override
public void run(final CharSequence chars, @Nullable char[] charsArray, final int start, final int end) {
if (start <= offset && end >= offset) {
data.myPrefix = charsSequence.subSequence(start, offset).toString();
data.myWordUnderCursor = charsSequence.subSequence(start, end).toString();
data.startOffset = start;
}
}
endOffset++;
}, charsSequence, 0, charsSequence.length());
if (data.myPrefix == null) {
data.myPrefix = "";
data.myWordUnderCursor = "";
data.startOffset = offset;
}
data.myWordUnderCursor = charsSequence.subSequence(offset, endOffset).toString();
if (data.myPrefix == null) data.myPrefix = data.myWordUnderCursor;
return data;
}