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

Make syntax server support hovering over a type #1403

Merged
merged 1 commit into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public List<Either<String, MarkedString>> computeHover(int line, int column, IPr
} else {
curr = elements[0];
}
boolean resolved = isResolved(curr, monitor);
if (resolved) {

if (JDTEnvironmentUtils.isSyntaxServer() || isResolved(curr, monitor)) {
IBuffer buffer = curr.getOpenable().getBuffer();
if (buffer == null && curr instanceof BinaryMember) {
IClassFile classFile = ((BinaryMember) curr).getClassFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package java;

/**
* This is Bar.
*/
public class Bar {

public void print() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* This is foo
*/
public class Foo {
public class Foo implements IFoo {

public static void main(String[] args) {
System.out.println(StringUtils.capitalize("Hello world! from " + Foo.class));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package pack;

/**
* This is interface IFoo.
*/
public interface IFoo {

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ public class SyntaxServerTest extends AbstractSyntaxProjectsManagerBasedTest {
private SyntaxLanguageServer server;
private CoreASTProvider sharedASTProvider;

private String oldServerMode = "";
private boolean oldBuildStatus = false;

@Before
public void setup() throws Exception {
oldServerMode = System.getProperty(JDTEnvironmentUtils.SYNTAX_SERVER_ID);
System.setProperty(JDTEnvironmentUtils.SYNTAX_SERVER_ID, "true");
oldBuildStatus = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
ProjectsManager.setAutoBuilding(false);
sharedASTProvider = CoreASTProvider.getInstance();
Expand All @@ -81,6 +84,11 @@ public void setup() throws Exception {

@After
public void tearDown() throws Exception {
if (oldServerMode == null) {
System.clearProperty(JDTEnvironmentUtils.SYNTAX_SERVER_ID);
} else {
System.setProperty(JDTEnvironmentUtils.SYNTAX_SERVER_ID, oldServerMode);
}
ProjectsManager.setAutoBuilding(oldBuildStatus);
server.getClientConnection().disconnect();
for (ICompilationUnit cu : JavaCore.getWorkingCopies(null)) {
Expand Down Expand Up @@ -210,6 +218,40 @@ public void testHover() throws Exception {
assertEquals("Test", list.get(1).getLeft());
}

@Test
public void testHoverType() throws Exception {
URI fileURI = openFile("maven/salut4", "src/main/java/java/Foo.java");
String fileUri = ResourceUtils.fixURI(fileURI);
TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri);
HoverParams params = new HoverParams(identifier, new Position(11, 9));
Hover result = server.hover(params).join();
assertNotNull(result);
assertNotNull(result.getContents());
assertTrue(result.getContents().isLeft());
List<Either<String, MarkedString>> list = result.getContents().getLeft();
assertNotNull(list);
assertEquals(2, list.size());
assertTrue(list.get(1).isLeft());
assertEquals("This is Bar.", list.get(1).getLeft());
}

@Test
public void testHoverUnresolvedType() throws Exception {
URI fileURI = openFile("maven/salut4", "src/main/java/java/Foo.java");
String fileUri = ResourceUtils.fixURI(fileURI);
TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri);
HoverParams params = new HoverParams(identifier, new Position(7, 30));
Hover result = server.hover(params).join();
assertNotNull(result);
assertNotNull(result.getContents());
assertTrue(result.getContents().isLeft());
List<Either<String, MarkedString>> list = result.getContents().getLeft();
assertNotNull(list);
assertEquals(2, list.size());
assertTrue(list.get(1).isLeft());
assertEquals("This is interface IFoo.", list.get(1).getLeft());
}

private URI openFile(String basePath, String filePath) throws Exception {
IPath rootPath = getWorkingTestPath(basePath);
preferences.setRootPaths(Collections.singletonList(rootPath));
Expand Down