mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Basic objective-c selectors completion
This commit is contained in:
+12
-1
@@ -17,13 +17,17 @@ package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.ReferenceRange;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
@@ -62,6 +66,13 @@ public class CompletionInitializationContext {
|
||||
try {
|
||||
final PsiReference reference = file.findReferenceAt(selectionEndOffset);
|
||||
if(reference != null){
|
||||
final List<TextRange> ranges = ReferenceRange.getAbsoluteRanges(reference);
|
||||
for (TextRange range : ranges) {
|
||||
if (range.contains(selectionEndOffset)) {
|
||||
return range.getEndOffset();
|
||||
}
|
||||
}
|
||||
|
||||
return reference.getElement().getTextRange().getStartOffset() + reference.getRangeInElement().getEndOffset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,8 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.paths.PsiDynaReference;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import static com.intellij.patterns.StandardPatterns.character;
|
||||
import static com.intellij.patterns.StandardPatterns.not;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.filters.ContextGetter;
|
||||
import com.intellij.psi.filters.ElementFilter;
|
||||
@@ -41,6 +40,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.patterns.StandardPatterns.character;
|
||||
import static com.intellij.patterns.StandardPatterns.not;
|
||||
|
||||
/**
|
||||
* @deprecated see {@link com.intellij.codeInsight.completion.CompletionContributor}
|
||||
*/
|
||||
@@ -181,17 +183,23 @@ public class CompletionData {
|
||||
public static String getReferencePrefix(@NotNull PsiElement insertedElement, int offsetInFile) {
|
||||
final PsiReference ref = insertedElement.getContainingFile().findReferenceAt(offsetInFile);
|
||||
if(ref != null) {
|
||||
final List<TextRange> ranges = ReferenceRange.getRanges(ref);
|
||||
final PsiElement element = ref.getElement();
|
||||
final int endIndex = offsetInFile - element.getTextRange().getStartOffset();
|
||||
final int beginIndex = ref.getRangeInElement().getStartOffset();
|
||||
if (beginIndex > endIndex) {
|
||||
LOG.error("Inconsistent reference (found at offset not included in its range): ref=" + ref + " element=" + element + " text=" + element.getText());
|
||||
final int elementStart = element.getTextRange().getStartOffset();
|
||||
for (TextRange refRange : ranges) {
|
||||
if (refRange.contains(offsetInFile - elementStart)) {
|
||||
final int endIndex = offsetInFile - elementStart;
|
||||
final int beginIndex = refRange.getStartOffset();
|
||||
if (beginIndex > endIndex) {
|
||||
LOG.error("Inconsistent reference (found at offset not included in its range): ref=" + ref + " element=" + element + " text=" + element.getText());
|
||||
}
|
||||
if (beginIndex < 0) {
|
||||
LOG.error("Inconsistent reference (begin < 0): ref=" + ref + " element=" + element + "; begin=" + beginIndex + " text=" + element.getText());
|
||||
}
|
||||
LOG.assertTrue(endIndex >= 0);
|
||||
return element.getText().substring(beginIndex, endIndex);
|
||||
}
|
||||
}
|
||||
if (beginIndex < 0) {
|
||||
LOG.error("Inconsistent reference (begin < 0): ref=" + ref + " element=" + element + "; begin=" + beginIndex + " text=" + element.getText());
|
||||
}
|
||||
LOG.assertTrue(endIndex >= 0);
|
||||
return element.getText().substring(beginIndex, endIndex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user