Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Editor is already disposed in LSP hover operation (#914)
Fixes #914 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
azerr
committed
Jun 7, 2023
1 parent
55e3388
commit 4a93a99
Showing
2 changed files
with
112 additions
and
48 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...main/java/com/redhat/devtools/intellij/lsp4ij/operations/hover/LSPPsiElementForHover.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.intellij.lsp4ij.operations.hover; | ||
|
||
import com.intellij.lang.ASTNode; | ||
import com.intellij.lang.Language; | ||
import com.intellij.openapi.editor.Editor; | ||
import com.intellij.openapi.fileTypes.PlainTextLanguage; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.util.Key; | ||
import com.intellij.openapi.util.TextRange; | ||
import com.intellij.psi.*; | ||
import com.intellij.psi.impl.FakePsiElement; | ||
import com.intellij.psi.impl.PsiElementBase; | ||
import com.intellij.psi.scope.PsiScopeProcessor; | ||
import com.intellij.psi.search.GlobalSearchScope; | ||
import com.intellij.psi.search.SearchScope; | ||
import com.intellij.util.IncorrectOperationException; | ||
import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils; | ||
import com.redhat.devtools.intellij.lsp4ij.operations.diagnostics.LSPPsiReference; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class LSPPsiElementForHover extends FakePsiElement { | ||
private final Project project; | ||
private final PsiFile file; | ||
private Editor editor; | ||
|
||
private int targetOffset; | ||
|
||
public LSPPsiElementForHover(Editor editor, PsiFile file, int targetOffset) { | ||
this.editor = editor; | ||
this.file = file; | ||
this.project = LSPIJUtils.getProject(file.getVirtualFile()).getProject(); | ||
this.targetOffset = targetOffset; | ||
} | ||
|
||
public int getTargetOffset() { | ||
return targetOffset; | ||
} | ||
|
||
public Editor getEditor() { | ||
return editor; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Project getProject() throws PsiInvalidElementAccessException { | ||
return project; | ||
} | ||
|
||
@Override | ||
public PsiFile getContainingFile() { | ||
return file; | ||
} | ||
|
||
@Override | ||
public PsiElement getParent() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isValid() { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters