generated from redhat-developer/new-project-template
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Added a file view provider for LSP files that yields fake PSI elements for words. #703
Draft
SCWells72
wants to merge
5
commits into
redhat-developer:main
Choose a base branch
from
SCWells72:lsp_file_view_provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+86
−0
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
79a9d93
Added a file view provider for LSP files that yields fake PSI element…
SCWells72 9fa1328
Merge branch 'redhat-developer:main' into lsp_file_view_provider
SCWells72 8712351
Merge branch 'redhat-developer:main' into lsp_file_view_provider
SCWells72 c21e7d5
Merge branch 'redhat-developer:main' into lsp_file_view_provider
SCWells72 6db958c
Merge branch 'redhat-developer:main' into lsp_file_view_provider
SCWells72 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...om/redhat/devtools/lsp4ij/features/documentSymbol/LSPDocumentFileViewProviderFactory.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.lsp4ij.features.documentSymbol; | ||
|
||
import com.intellij.lang.Language; | ||
import com.intellij.openapi.editor.Document; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.util.TextRange; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.psi.*; | ||
import com.redhat.devtools.lsp4ij.LSPIJUtils; | ||
import com.redhat.devtools.lsp4ij.features.LSPPsiElement; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* File view provider factory for LSP files that yields simple PSI elements for the word under the caret. This helps | ||
* with a number of plugin SDK EPs that need to find distinct elements. | ||
*/ | ||
public class LSPDocumentFileViewProviderFactory implements FileViewProviderFactory { | ||
|
||
@Override | ||
@NotNull | ||
public FileViewProvider createFileViewProvider(@NotNull VirtualFile virtualFile, | ||
Language language, | ||
@NotNull PsiManager manager, | ||
boolean eventSystemEnabled) { | ||
Project project = manager.getProject(); | ||
if (!project.isDisposed() && !virtualFile.isDirectory() && virtualFile.isValid()) { | ||
// NOTE: We can't filter by LSP here, so we just have to make sure that this view provider behaves as the | ||
// standard view provider for non-LSP files | ||
return new LSPDocumentFileViewProvider(manager, virtualFile, eventSystemEnabled); | ||
} | ||
|
||
return new SingleRootFileViewProvider(manager, virtualFile, eventSystemEnabled); | ||
} | ||
|
||
private static class LSPDocumentFileViewProvider extends SingleRootFileViewProvider { | ||
public LSPDocumentFileViewProvider(@NotNull PsiManager manager, | ||
@NotNull VirtualFile virtualFile, | ||
boolean eventSystemEnabled) { | ||
super(manager, virtualFile, eventSystemEnabled); | ||
} | ||
|
||
@Override | ||
public PsiElement findElementAt(int offset) { | ||
VirtualFile virtualFile = getVirtualFile(); | ||
Project project = getManager().getProject(); | ||
PsiFile file = LSPIJUtils.getPsiFile(virtualFile, project); | ||
// TODO: How can we quickly and simply check whether this is an LSP4IJ-managed file? | ||
if (file != null) { | ||
Document document = LSPIJUtils.getDocument(file); | ||
if (document != null) { | ||
TextRange wordTextRange = LSPIJUtils.getWordRangeAt(document, file, offset); | ||
if (wordTextRange != null) { | ||
return new LSPPsiElement(file, wordTextRange) { | ||
@Override | ||
// NOTE: We have to report this as physical even though it's not | ||
public boolean isPhysical() { | ||
return true; | ||
} | ||
}; | ||
} | ||
} | ||
} | ||
|
||
return super.findElementAt(offset); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2024