generated from redhat-developer/new-project-template
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support for TypeHierachy + CallHierarchy
Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
e5199d6
commit 429bfa1
Showing
40 changed files
with
2,509 additions
and
54 deletions.
There are no files selected for viewing
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
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
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
78 changes: 78 additions & 0 deletions
78
src/main/java/com/redhat/devtools/lsp4ij/client/features/LSPCallHierarchyFeature.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) 2024 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.client.features; | ||
|
||
import com.intellij.psi.PsiFile; | ||
import com.redhat.devtools.lsp4ij.server.capabilities.CallHierarchyCapabilityRegistry; | ||
import org.eclipse.lsp4j.CallHierarchyItem; | ||
import org.eclipse.lsp4j.ServerCapabilities; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* LSP call hierarchy feature. | ||
*/ | ||
@ApiStatus.Experimental | ||
public class LSPCallHierarchyFeature extends AbstractLSPDocumentFeature { | ||
|
||
private CallHierarchyCapabilityRegistry callHierarchyCapabilityRegistry; | ||
|
||
@Override | ||
public boolean isSupported(@NotNull PsiFile file) { | ||
return isCallHierarchySupported(file); | ||
} | ||
|
||
/** | ||
* Returns true if the file associated with a language server can support call hierarchy and false otherwise. | ||
* | ||
* @param file the file. | ||
* @return true if the file associated with a language server can support call hierarchy and false otherwise. | ||
*/ | ||
public boolean isCallHierarchySupported(@NotNull PsiFile file) { | ||
return getCallHierarchyCapabilityRegistry().isCallHierarchySupported(file); | ||
} | ||
|
||
public CallHierarchyCapabilityRegistry getCallHierarchyCapabilityRegistry() { | ||
if (callHierarchyCapabilityRegistry == null) { | ||
initCallHierarchyCapabilityRegistry(); | ||
} | ||
return callHierarchyCapabilityRegistry; | ||
} | ||
|
||
private synchronized void initCallHierarchyCapabilityRegistry() { | ||
if (callHierarchyCapabilityRegistry != null) { | ||
return; | ||
} | ||
var clientFeatures = getClientFeatures(); | ||
callHierarchyCapabilityRegistry = new CallHierarchyCapabilityRegistry(clientFeatures); | ||
callHierarchyCapabilityRegistry.setServerCapabilities(clientFeatures.getServerWrapper().getServerCapabilitiesSync()); | ||
} | ||
|
||
@Override | ||
public void setServerCapabilities(@Nullable ServerCapabilities serverCapabilities) { | ||
if (callHierarchyCapabilityRegistry != null) { | ||
callHierarchyCapabilityRegistry.setServerCapabilities(serverCapabilities); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the callHierarchyItem text from the LSP callHierarchyItem and null otherwise (to ignore the LSP CallHierarchyItem). | ||
* | ||
* @param callHierarchyItem the LSP callHierarchyItem | ||
* @return the callHierarchyItem text from the LSP callHierarchyItem and null otherwise (to ignore the LSP CallHierarchyItem). | ||
*/ | ||
@Nullable | ||
public String getText(@NotNull CallHierarchyItem callHierarchyItem) { | ||
return callHierarchyItem.getName(); | ||
} | ||
|
||
} |
Oops, something went wrong.