Skip to content
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

Add symbol tags as proposed for LSP specification (e.g. visibility tags, static, abstract, etc.) #977 #1149

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions org.eclipse.lsp4e.debug/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.debug.core,
org.eclipse.debug.ui,
org.eclipse.jface,
org.eclipse.lsp4j.jsonrpc;bundle-version="[0.23.1,0.24.0)",
org.eclipse.lsp4j.jsonrpc.debug;bundle-version="[0.23.1,0.24.0)",
org.eclipse.lsp4j.debug;bundle-version="[0.23.1,0.24.0)",
org.eclipse.lsp4j.jsonrpc;bundle-version="[0.24.0,0.25.0)",
org.eclipse.lsp4j.jsonrpc.debug;bundle-version="[0.24.0,0.25.0)",
org.eclipse.lsp4j.debug;bundle-version="[0.24.0,0.25.0)",
org.eclipse.ui.editors,
org.eclipse.core.filesystem,
org.eclipse.ui.ide;bundle-version="[3.16.0,4.0.0)",
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.lsp4e.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.expressions,
org.eclipse.lsp4e.tests.mock;bundle-version="0.6.0",
org.eclipse.lsp4e.debug;bundle-version="0.13.4",
org.eclipse.lsp4j;bundle-version="[0.23.0,0.24.0)",
org.eclipse.lsp4j;bundle-version="[0.24.0,0.25.0)",
org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)",
org.eclipse.ui.tests.harness,
org.eclipse.ui.monitoring,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*******************************************************************************
* Copyright (c) 2024 Advantest GmbH and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Dietrich Travkin (Solunar GmbH) - initial implementation
*******************************************************************************/
package org.eclipse.lsp4e.test.symbols;

import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.List;

import org.eclipse.lsp4e.operations.symbols.SymbolsUtil;
import org.eclipse.lsp4j.DocumentSymbol;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.SymbolTag;
import org.eclipse.lsp4j.WorkspaceSymbol;
import org.junit.Test;

public class SymbolsUtilTest { //extends AbstractTest {

@Test
public void testDeprecatedCheck() {
List<SymbolTag> symbolTagsWithDeprecated = Arrays.asList(SymbolTag.Package, SymbolTag.Deprecated, SymbolTag.ReadOnly);
List<SymbolTag> symbolTags = Arrays.asList(SymbolTag.Public, SymbolTag.Declaration, SymbolTag.Static);

var symbolInformation = new SymbolInformation();

assertFalse(SymbolsUtil.isDeprecated(symbolInformation));

symbolInformation.setDeprecated(true);

assertTrue(SymbolsUtil.isDeprecated(symbolInformation));

symbolInformation = new SymbolInformation();
symbolInformation.setTags(symbolTagsWithDeprecated);

assertTrue(SymbolsUtil.isDeprecated(symbolInformation));

symbolInformation.setTags(symbolTags);

assertFalse(SymbolsUtil.isDeprecated(symbolInformation));


var workspaceSymbol = new WorkspaceSymbol();

assertFalse(SymbolsUtil.isDeprecated(workspaceSymbol));

workspaceSymbol.setTags(symbolTagsWithDeprecated);

assertTrue(SymbolsUtil.isDeprecated(workspaceSymbol));

workspaceSymbol.setTags(symbolTags);

assertFalse(SymbolsUtil.isDeprecated(workspaceSymbol));


var documentSymbol = new DocumentSymbol();

assertFalse(SymbolsUtil.isDeprecated(documentSymbol));

documentSymbol.setDeprecated(true);

assertTrue(SymbolsUtil.isDeprecated(documentSymbol));

documentSymbol = new DocumentSymbol();
documentSymbol.setTags(symbolTagsWithDeprecated);

assertTrue(SymbolsUtil.isDeprecated(documentSymbol));

documentSymbol.setTags(symbolTags);

assertFalse(SymbolsUtil.isDeprecated(documentSymbol));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2024 Advantest GmbH and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Dietrich Travkin (Solunar GmbH) - initial implementation
*******************************************************************************/
package org.eclipse.lsp4e.test.utils;

import static org.junit.Assert.*;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.lsp4e.ui.LSPImages;
import org.eclipse.lsp4j.SymbolKind;
import org.eclipse.lsp4j.SymbolTag;
import org.eclipse.swt.graphics.Image;
import org.junit.Test;

public class LSPImagesTest {

@Test
public void testImageForSymbolKind() {
for (SymbolKind kind : SymbolKind.values()) {
Image img = LSPImages.imageFromSymbolKind(kind);

assertNotNull(img);
}
}

@Test
public void testOverlayImageForSymbolTag() {
for (SymbolTag tag : SymbolTag.values()) {
ImageDescriptor descriptor = LSPImages.imageDescriptorOverlayFromSymbolTag(tag);
Image img = LSPImages.imageOverlayFromSymbolTag(tag);

assertNotNull(descriptor);
assertNotNull(img);
}
}

}
4 changes: 2 additions & 2 deletions org.eclipse.lsp4e.tests.mock/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Bundle-SymbolicName: org.eclipse.lsp4e.tests.mock
Bundle-Version: 0.16.13.qualifier
Bundle-Vendor: Eclipse LSP4E
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.lsp4j;bundle-version="[0.23.0,0.24.0)",
org.eclipse.lsp4j.jsonrpc;bundle-version="[0.23.0,0.24.0)",
Require-Bundle: org.eclipse.lsp4j;bundle-version="[0.24.0,0.25.0)",
org.eclipse.lsp4j.jsonrpc;bundle-version="[0.24.0,0.25.0)",
org.eclipse.lsp4e,
org.eclipse.jdt.annotation,
com.google.guava
Expand Down
4 changes: 2 additions & 2 deletions org.eclipse.lsp4e/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0",
org.eclipse.tm4e.ui;resolution:=optional,
org.eclipse.ui.editors,
org.eclipse.ui.navigator;bundle-version="3.6.100",
org.eclipse.lsp4j;bundle-version="[0.23.0,0.24.0)",
org.eclipse.lsp4j.jsonrpc;bundle-version="[0.23.0,0.24.0)",
org.eclipse.lsp4j;bundle-version="[0.24.0,0.25.0)",
org.eclipse.lsp4j.jsonrpc;bundle-version="[0.24.0,0.25.0)",
org.eclipse.ui.console,
org.eclipse.ltk.core.refactoring,
org.eclipse.core.expressions;bundle-version="3.5.0",
Expand Down
Binary file modified org.eclipse.lsp4e/icons/full/obj16/constructor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified org.eclipse.lsp4e/icons/full/obj16/constructor@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/ovr16/abstract_co.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/ovr16/constr_ovr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/ovr16/constr_ovr@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/ovr16/definition_co.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/ovr16/deprecated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/ovr16/deprecated@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/ovr16/final_co.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/ovr16/final_co@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/ovr16/package_co.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/ovr16/private_co.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/ovr16/public_co.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/ovr16/read_only_co.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.lsp4e/icons/full/ovr16/sealed_co.png
Binary file added org.eclipse.lsp4e/icons/full/ovr16/sealed_co@2x.png
Binary file added org.eclipse.lsp4e/icons/full/ovr16/static_co.png
Binary file added org.eclipse.lsp4e/icons/full/ovr16/static_co@2x.png
Binary file added org.eclipse.lsp4e/icons/full/ovr16/synch_co.png
Binary file added org.eclipse.lsp4e/icons/full/ovr16/synch_co@2x.png
Binary file added org.eclipse.lsp4e/icons/full/ovr16/transient_co.png
Binary file added org.eclipse.lsp4e/icons/full/ovr16/virtual_co.png
Binary file added org.eclipse.lsp4e/icons/full/ovr16/volatile_co.png
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import org.eclipse.lsp4j.SymbolCapabilities;
import org.eclipse.lsp4j.SymbolKind;
import org.eclipse.lsp4j.SymbolKindCapabilities;
import org.eclipse.lsp4j.SymbolTag;
import org.eclipse.lsp4j.SymbolTagSupportCapabilities;
import org.eclipse.lsp4j.SynchronizationCapabilities;
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
import org.eclipse.lsp4j.TypeDefinitionCapabilities;
Expand Down Expand Up @@ -110,6 +112,7 @@ public static TextDocumentClientCapabilities getTextDocumentClientCapabilities()
final var documentSymbol = new DocumentSymbolCapabilities();
documentSymbol.setHierarchicalDocumentSymbolSupport(true);
documentSymbol.setSymbolKind(new SymbolKindCapabilities(List.of(SymbolKind.values())));
documentSymbol.setTagSupport(new SymbolTagSupportCapabilities(List.of(SymbolTag.values())));
textDocumentClientCapabilities.setDocumentSymbol(documentSymbol);
textDocumentClientCapabilities.setFoldingRange(new FoldingRangeCapabilities());
textDocumentClientCapabilities.setFormatting(new FormattingCapabilities(true));
Expand All @@ -136,7 +139,9 @@ public static WorkspaceClientCapabilities getWorkspaceClientCapabilities() {
workspaceClientCapabilities.setApplyEdit(true);
workspaceClientCapabilities.setConfiguration(true);
workspaceClientCapabilities.setExecuteCommand(new ExecuteCommandCapabilities(true));
workspaceClientCapabilities.setSymbol(new SymbolCapabilities(true));
SymbolCapabilities symbolCapabilities = new SymbolCapabilities(true);
symbolCapabilities.setTagSupport(new SymbolTagSupportCapabilities(List.of(SymbolTag.values())));
workspaceClientCapabilities.setSymbol(symbolCapabilities);
workspaceClientCapabilities.setWorkspaceFolders(true);
final var editCapabilities = new WorkspaceEditCapabilities();
editCapabilities.setDocumentChanges(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/*******************************************************************************
* Copyright (c) 2024 Advantest GmbH and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Dietrich Travkin (Solunar GmbH) - initial implementation
*******************************************************************************/
package org.eclipse.lsp4e.operations.symbols;

import java.util.Collections;
import java.util.List;

import org.eclipse.lsp4e.outline.SymbolsModel.DocumentSymbolWithURI;
import org.eclipse.lsp4j.DocumentSymbol;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.SymbolKind;
import org.eclipse.lsp4j.SymbolTag;
import org.eclipse.lsp4j.WorkspaceSymbol;

public class SymbolsUtil {

public static SymbolKind getKind(SymbolInformation symbolInformation) {
return symbolInformation.getKind();
}

public static SymbolKind getKind(WorkspaceSymbol workspaceSymbol) {
return workspaceSymbol.getKind();
}

public static SymbolKind getKind(DocumentSymbol documentSymbol) {
return documentSymbol.getKind();
}

public static SymbolKind getKind(DocumentSymbolWithURI documentSymbolWithUri) {
return getKind(documentSymbolWithUri.symbol);
}

public static List<SymbolTag> getSymbolTags(SymbolInformation symbolInformation) {
if (symbolInformation.getTags() != null) {
return symbolInformation.getTags();
}

return Collections.emptyList();
}

public static List<SymbolTag> getSymbolTags(WorkspaceSymbol workspaceSymbol) {
if (workspaceSymbol.getTags() != null) {
return workspaceSymbol.getTags();
}

return Collections.emptyList();
}

public static List<SymbolTag> getSymbolTags(DocumentSymbol documentSymbol) {
if (documentSymbol.getTags() != null) {
return documentSymbol.getTags();
}

return Collections.emptyList();
}

public static List<SymbolTag> getSymbolTags(DocumentSymbolWithURI documentSymbolWithUri) {
return getSymbolTags(documentSymbolWithUri.symbol);
}

public static boolean hasSymbolTag(List<SymbolTag> tagList, SymbolTag tag) {
return tagList.contains(tag);
}

public static boolean hasSymbolTag(SymbolInformation symbolInformation, SymbolTag tag) {
return getSymbolTags(symbolInformation).contains(tag);
}

public static boolean hasSymbolTag(WorkspaceSymbol workspaceSymbol, SymbolTag tag) {
return getSymbolTags(workspaceSymbol).contains(tag);
}

public static boolean hasSymbolTag(DocumentSymbol documentSymbol, SymbolTag tag) {
return getSymbolTags(documentSymbol).contains(tag);
}

public static boolean hasSymbolTag(DocumentSymbolWithURI documentSymbolWithUri, SymbolTag tag) {
return getSymbolTags(documentSymbolWithUri).contains(tag);
}

public static boolean isDeprecated(SymbolInformation symbolInformation) {
boolean deprecated = isDeprecated(getSymbolTags(symbolInformation));
return deprecated || (symbolInformation.getDeprecated() == null ? false: symbolInformation.getDeprecated());
}

public static boolean isDeprecated(WorkspaceSymbol workspaceSymbol) {
return isDeprecated(getSymbolTags(workspaceSymbol));
}

public static boolean isDeprecated(DocumentSymbol documentSymbol) {
boolean deprecated = isDeprecated(getSymbolTags(documentSymbol));
return deprecated || (documentSymbol.getDeprecated() == null ? false: documentSymbol.getDeprecated());
}

public static boolean isDeprecated(DocumentSymbolWithURI documentSymbolWithUri) {
return isDeprecated(documentSymbolWithUri.symbol);
}

public static boolean isDeprecated(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Deprecated);
}

public static boolean isPrivate(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Private);
}

public static boolean isPackage(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Package);
}

public static boolean isProtected(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Protected);
}

public static boolean isPublic(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Public);
}

public static boolean isInternal(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Internal);
}

public static boolean isFileVisible(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.File);
}

public static boolean isStatic(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Static);
}

public static boolean isAbstract(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Abstract);
}

public static boolean isFinal(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Final);
}

public static boolean isSealed(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Sealed);
}

public static boolean isTransient(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Transient);
}

public static boolean isVolatile(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Volatile);
}

public static boolean isSynchronized(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Synchronized);
}

public static boolean isVirtual(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Virtual);
}

public static boolean isNullable(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Nullable);
}

public static boolean isNonNull(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.NonNull);
}

public static boolean isDeclaration(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Declaration);
}

public static boolean isDefinition(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.Definition);
}

public static boolean isReadOnly(List<SymbolTag> tags) {
return SymbolsUtil.hasSymbolTag(tags, SymbolTag.ReadOnly);
}

}
Loading
Loading