mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't require EditorWindow for injected file copy
remove unused CompletionContext fields fixed EA-44452 (CCE EditorWindow)
This commit is contained in:
+9
-9
@@ -28,6 +28,7 @@ import com.intellij.diagnostic.LogMessageEx;
|
||||
import com.intellij.diagnostic.errordialog.Attachment;
|
||||
import com.intellij.featureStatistics.FeatureUsageTracker;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.injected.editor.DocumentWindow;
|
||||
import com.intellij.injected.editor.EditorWindow;
|
||||
import com.intellij.lang.FileASTNode;
|
||||
import com.intellij.lang.Language;
|
||||
@@ -601,18 +602,17 @@ public class CodeCompletionHandlerBase {
|
||||
if (injected instanceof PsiFileImpl && injectedLanguageManager.isInjectedFragment(originalFile)) {
|
||||
((PsiFileImpl)injected).setOriginalFile(originalFile);
|
||||
}
|
||||
DocumentWindow documentWindow = InjectedLanguageUtil.getDocumentWindow(injected);
|
||||
assert documentWindow != null : "no DocumentWindow for an injected fragment";
|
||||
|
||||
TextRange host = injectedLanguageManager.injectedToHost(injected, injected.getTextRange());
|
||||
assert hostStartOffset >= host.getStartOffset() : "startOffset before injected";
|
||||
assert hostStartOffset <= host.getEndOffset() : "startOffset after injected";
|
||||
|
||||
EditorWindow injectedEditor = (EditorWindow)InjectedLanguageUtil
|
||||
.getEditorForInjectedLanguageNoCommit(hostEditor, hostCopy, hostStartOffset);
|
||||
assert injected == injectedEditor.getInjectedFile();
|
||||
context = new CompletionContext(hostCopy.getProject(), injectedEditor, injected,
|
||||
translateOffsetMapToInjected(hostEditor, hostMap, injectedEditor));
|
||||
context = new CompletionContext(injected, translateOffsetMapToInjected(hostMap, documentWindow));
|
||||
assert hostStartOffset == injectedLanguageManager.injectedToHost(injected, context.getStartOffset()) : "inconsistent injected offset translation";
|
||||
} else {
|
||||
context = new CompletionContext(hostCopy.getProject(), hostEditor, hostCopy, hostMap);
|
||||
context = new CompletionContext(hostCopy, hostMap);
|
||||
}
|
||||
|
||||
assert context.getStartOffset() < context.file.getTextLength() : "start outside the file";
|
||||
@@ -621,10 +621,10 @@ public class CodeCompletionHandlerBase {
|
||||
return context;
|
||||
}
|
||||
|
||||
private static OffsetMap translateOffsetMapToInjected(Editor hostEditor, OffsetMap hostMap, EditorWindow injectedEditor) {
|
||||
final OffsetMap map = new OffsetMap(injectedEditor.getDocument());
|
||||
private static OffsetMap translateOffsetMapToInjected(OffsetMap hostMap, DocumentWindow injectedDocument) {
|
||||
final OffsetMap map = new OffsetMap(injectedDocument);
|
||||
for (final OffsetKey key : hostMap.getAllOffsets()) {
|
||||
map.addOffset(key, injectedEditor.logicalPositionToOffset(injectedEditor.hostToInjected(hostEditor.offsetToLogicalPosition(hostMap.getOffset(key)))));
|
||||
map.addOffset(key, injectedDocument.hostToInjected(hostMap.getOffset(key)));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -16,22 +16,16 @@
|
||||
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.PsiFile;
|
||||
|
||||
public class CompletionContext {
|
||||
public static final Key<CompletionContext> COMPLETION_CONTEXT_KEY = Key.create("CompletionContext");
|
||||
|
||||
public final Project project;
|
||||
public final Editor editor;
|
||||
public final PsiFile file;
|
||||
private final OffsetMap myOffsetMap;
|
||||
|
||||
public CompletionContext(Project project, Editor editor, PsiFile file, final OffsetMap offsetMap){
|
||||
this.project = project;
|
||||
this.editor = editor;
|
||||
public CompletionContext(PsiFile file, final OffsetMap offsetMap){
|
||||
this.file = file;
|
||||
myOffsetMap = offsetMap;
|
||||
}
|
||||
@@ -40,16 +34,9 @@ public class CompletionContext {
|
||||
return getOffsetMap().getOffset(CompletionInitializationContext.START_OFFSET);
|
||||
}
|
||||
|
||||
public void setStartOffset(final int newStartOffset) {
|
||||
getOffsetMap().addOffset(CompletionInitializationContext.START_OFFSET, newStartOffset);
|
||||
}
|
||||
|
||||
public OffsetMap getOffsetMap() {
|
||||
return myOffsetMap;
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return project;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -478,7 +478,7 @@ public class InjectedLanguageUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static DocumentWindow getDocumentWindow(PsiElement element) {
|
||||
public static DocumentWindow getDocumentWindow(@NotNull PsiElement element) {
|
||||
PsiFile file = element.getContainingFile();
|
||||
if (file == null) return null;
|
||||
VirtualFile virtualFile = file.getVirtualFile();
|
||||
|
||||
Reference in New Issue
Block a user