generated from redhat-developer/new-project-template
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
496 additions
and
12 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
57 changes: 57 additions & 0 deletions
57
src/main/java/com/redhat/devtools/lsp4ij/features/documentSymbol/DocumentSymbolData.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,57 @@ | ||
/******************************************************************************* | ||
* 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: | ||
* CppCXY | ||
******************************************************************************/ | ||
package com.redhat.devtools.lsp4ij.features.documentSymbol; | ||
|
||
import com.intellij.navigation.ItemPresentation; | ||
import com.intellij.openapi.util.NlsSafe; | ||
import com.redhat.devtools.lsp4ij.ui.IconMapper; | ||
import org.eclipse.lsp4j.DocumentSymbol; | ||
import org.eclipse.lsp4j.SymbolKind; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
|
||
|
||
/** | ||
* LSP document symbol data. | ||
* | ||
* @param documentSymbol the LSP document symbol | ||
*/ | ||
record DocumentSymbolData(@NotNull DocumentSymbol documentSymbol) { | ||
|
||
private record LSPItemPresentation(String name, SymbolKind symbolKind, String locationString) implements ItemPresentation { | ||
|
||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public @NlsSafe @Nullable String getPresentableText() { | ||
return name(); | ||
} | ||
|
||
@Override | ||
public @Nullable Icon getIcon(boolean unused) { | ||
return IconMapper.getIcon(symbolKind); | ||
} | ||
|
||
@Override | ||
public @NlsSafe @Nullable String getLocationString() { | ||
return locationString; | ||
} | ||
|
||
} | ||
|
||
public ItemPresentation getPresentation() { | ||
return new LSPItemPresentation(documentSymbol.getName(), documentSymbol.getKind(), documentSymbol.getDetail()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...redhat/devtools/lsp4ij/features/documentSymbol/LSPDocumentSymbolStructureViewFactory.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,48 @@ | ||
/******************************************************************************* | ||
* 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: | ||
* CppCXY | ||
******************************************************************************/ | ||
package com.redhat.devtools.lsp4ij.features.documentSymbol; | ||
|
||
import com.intellij.ide.structureView.StructureViewBuilder; | ||
import com.intellij.ide.structureView.StructureViewModel; | ||
import com.intellij.ide.structureView.TreeBasedStructureViewBuilder; | ||
import com.intellij.lang.PsiStructureViewFactory; | ||
import com.intellij.openapi.editor.Editor; | ||
import com.intellij.psi.PsiFile; | ||
import com.redhat.devtools.lsp4ij.LanguageServersRegistry; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* LSP document symbol structure view factory. | ||
*/ | ||
public class LSPDocumentSymbolStructureViewFactory implements PsiStructureViewFactory { | ||
|
||
@Override | ||
public @Nullable StructureViewBuilder getStructureViewBuilder(@NotNull PsiFile psiFile) { | ||
if (!LanguageServersRegistry.getInstance().isFileSupported(psiFile)) { | ||
return null; | ||
} | ||
return new LSPDocumentSymbolStructureViewBuilder(psiFile); | ||
} | ||
|
||
private static class LSPDocumentSymbolStructureViewBuilder extends TreeBasedStructureViewBuilder { | ||
private final PsiFile psiFile; | ||
|
||
public LSPDocumentSymbolStructureViewBuilder(@NotNull PsiFile psiFile) { | ||
this.psiFile = psiFile; | ||
} | ||
|
||
@Override | ||
public @NotNull StructureViewModel createStructureViewModel(@Nullable Editor editor) { | ||
return new LSPDocumentSymbolStructureViewModel(psiFile, editor); | ||
} | ||
} | ||
} |
Oops, something went wrong.