org.eclipse.lsp4j.HoverParams Java Examples

The following examples show how to use org.eclipse.lsp4j.HoverParams. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyntaxServerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #2
Source File: SyntaxServerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #3
Source File: SyntaxServerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testHover() throws Exception {
	URI fileURI = openFile("maven/salut4", "src/main/java/java/TestJavadoc.java");
	String fileUri = ResourceUtils.fixURI(fileURI);
	TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri);
	HoverParams params = new HoverParams(identifier, new Position(8, 23));
	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("Test", list.get(1).getLeft());
}
 
Example #4
Source File: CamelLanguageServerHoverTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideParameterDocumentationForUnknownParamOnHover() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"file:bla?test=test\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n");
	
	HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".xml"), new Position(0, 26));
	CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams);
	
	assertThat(hover.get().getContents().getLeft().get(0).getLeft()).isEqualTo(String.format(OptionParamURIInstance.INVALID_URI_OPTION, "test"));		
}
 
Example #5
Source File: ActionScriptServices.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
/**
 * Returns information to display in a tooltip when the mouse hovers over
 * something in a text document.
 */
@Override
public CompletableFuture<Hover> hover(HoverParams params)
{
    return CompletableFutures.computeAsync(compilerWorkspace.getExecutorService(), cancelToken ->
    {
        cancelToken.checkCanceled();

        //make sure that the latest changes have been passed to
        //workspace.fileChanged() before proceeding
        if(realTimeProblemsChecker != null)
        {
            realTimeProblemsChecker.updateNow();
        }

        compilerWorkspace.startBuilding();
        try
        {
            HoverProvider provider = new HoverProvider(workspaceFolderManager, fileTracker);
            return provider.hover(params, cancelToken);
        }
        finally
        {
            compilerWorkspace.doneBuilding();
        }
    });
}
 
Example #6
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Compute the hover. Executed in a read request.
 * @since 2.20
 */
protected Hover hover(HoverParams params, CancelIndicator cancelIndicator) {
	URI uri = getURI(params);
	IHoverService hoverService = getService(uri, IHoverService.class);
	if (hoverService == null) {
		return IHoverService.EMPTY_HOVER;
	}
	return workspaceManager.<Hover>doRead(uri,
			(document, resource) -> hoverService.hover(document, resource, params, cancelIndicator));
}
 
Example #7
Source File: TestTypeScript.java    From wildwebdeveloper with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testHTMLinTSXFile() throws Exception {
	IFile file = project.getFile("test.tsx");
	file.create(getClass().getResourceAsStream("/testProjects/htmlIn.tsx"), true, null);
	AbstractTextEditor editor = (AbstractTextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
	IDocument document = LSPEclipseUtils.getDocument(editor);
	DisplayHelper.sleep(2000); // Give time for LS to initialize enough before making edit and sending a didChange
	HoverParams params = new HoverParams(new TextDocumentIdentifier(LSPEclipseUtils.toUri(document).toString()), new Position(0, 18));
	Hover hover = LanguageServiceAccessor.getLanguageServers(document, null).get().get(0).getTextDocumentService().hover(params).get();
	Assert.assertTrue(hover.getContents().toString().contains("button"));
}
 
Example #8
Source File: CamelKModelineOptionNamesHoverTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testNoErrorOnUnknwonOption() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer("// camel-k: unknown=quarkus.enabled=true", ".java");
	
	HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".java"), new Position(0, 14));
	CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams);
	
	assertThat(hover.get()).isNull();
}
 
Example #9
Source File: CamelKModelineOptionNamesHoverTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideDocumentationOnHover() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer("// camel-k: trait=quarkus.enabled=true", ".java");
	
	HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".java"), new Position(0, 14));
	CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams);
	
	assertThat(hover.get().getContents().getLeft().get(0).getLeft()).isEqualTo("Configure a trait. E.g. \"trait=service.enabled=false\"");
}
 
Example #10
Source File: CamelLanguageServerHoverTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideSyntaxForEmptyPathParameterOnHover() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"kafka:\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n");
	
	HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".xml"), new Position(0, 17));
	CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams);
	
	assertThat(hover.get().getContents().getLeft().get(0).getLeft()).isEqualTo(KAFKA_SYNTAX_HOVER);
}
 
Example #11
Source File: CamelLanguageServerHoverTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideSyntaxForPathParameterOnHover() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"kafka:fl\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n");
	
	HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".xml"), new Position(0, 19));
	CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams);
	
	assertThat(hover.get().getContents().getLeft().get(0).getLeft()).isEqualTo(KAFKA_SYNTAX_HOVER);		
}
 
Example #12
Source File: CamelLanguageServerHoverTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideParameterDocumentationOnHover() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"file:bla?filter=test\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n");
	
	HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".xml"), new Position(0, 26));
	CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams);
	
	assertThat(hover.get().getContents().getLeft().get(0).getLeft()).isEqualTo(FILE_FILTER_DOCUMENTATION);		
}
 
Example #13
Source File: CamelLanguageServerHoverTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testDontProvideDocumentationOnUnknownComponent() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"unknowncomponent:\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n");
	
	HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".xml"), new Position(0, 15));
	CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams);
	
	assertThat(hover.get()).isNull();
}
 
Example #14
Source File: CamelLanguageServerHoverTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testDontProvideDocumentationOnHoverWhenEndingWithAnd() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"ahc:httpUri?test=test&\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n");
	
	HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".xml"), new Position(0, 15));
	CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams);
	
	assertThat(hover.get()).isNull();
}
 
Example #15
Source File: CamelLanguageServerHoverTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testDontProvideDocumentationOnHoverForBadPlaces() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"ahc:httpUri\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n");
	
	HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".xml"), new Position(0, 4));
	CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams);
	
	assertThat(hover.get()).isNull();
}
 
Example #16
Source File: CamelLanguageServerHoverTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideDocumentationOnHoverForJavaWithModeline() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer(
			"// camel-k : trait=quarkus.enabled=true\n"
			+ "from(\"ahc:httpUri\")",
			".java");
	
	HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".java"), new Position(1, 7));
	CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams);
	
	assertThat(hover.get().getContents().getLeft().get(0).getLeft()).isEqualTo(AHC_DOCUMENTATION);
}
 
Example #17
Source File: CamelLanguageServerHoverTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideDocumentationOnHoverForJava() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer(
			"//camel file\n"
			+ "from(\"ahc:httpUri\")",
			".java");
	
	HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".java"), new Position(1, 7));
	CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams);
	
	assertThat(hover.get().getContents().getLeft().get(0).getLeft()).isEqualTo(AHC_DOCUMENTATION);
}
 
Example #18
Source File: CamelLanguageServerHoverTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideDocumentationOnHoverWithCamelPrefix() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer("<camel:from uri=\"ahc:httpUri\" xmlns:camel=\"http://camel.apache.org/schema/spring\"></camel:from>\n");
	
	HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".xml"), new Position(0, 19));
	CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams);
	
	assertThat(hover.get().getContents().getLeft().get(0).getLeft()).isEqualTo(AHC_DOCUMENTATION);
}
 
Example #19
Source File: CamelLanguageServerHoverTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideDocumentationOnHover() throws Exception {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"ahc:httpUri\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n");
	
	HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".xml"), new Position(0, 13));
	CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams);
	
	assertThat(hover.get().getContents().getLeft().get(0).getLeft()).isEqualTo(AHC_DOCUMENTATION);
}
 
Example #20
Source File: CamelTextDocumentService.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Hover> hover(HoverParams hoverParams) {
	LOGGER.info("hover: {}", hoverParams.getTextDocument());
	TextDocumentItem textDocumentItem = openedDocuments.get(hoverParams.getTextDocument().getUri());
	if(isOnCamelKModeline(hoverParams.getPosition().getLine(), textDocumentItem)) {
		return new CamelKModelineHoverProcessor(textDocumentItem).getHover(hoverParams.getPosition().getCharacter());
	} else {
		return new HoverProcessor(textDocumentItem, getCamelCatalog()).getHover(hoverParams.getPosition());
	}
}
 
Example #21
Source File: XMLTextDocumentService.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<Hover> hover(HoverParams params) {
	return computeDOMAsync(params.getTextDocument(), (cancelChecker, xmlDocument) -> {
		return getXMLLanguageService().doHover(xmlDocument, params.getPosition(), sharedSettings, cancelChecker);
	});
}
 
Example #22
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<Hover> hover(HoverParams params) {
	return requestManager.runRead((cancelIndicator) -> hover(params, cancelIndicator));
}
 
Example #23
Source File: HoverService.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Hover hover(Document document, XtextResource resource, HoverParams params, CancelIndicator cancelIndicator) {
	int offset = document.getOffSet(params.getPosition());
	HoverContext context = createContext(document, resource, offset);
	return hover(context);
}
 
Example #24
Source File: SyntaxLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<Hover> hover(HoverParams position) {
	logInfo(">> document/hover");
	HoverHandler handler = new HoverHandler(this.preferenceManager);
	return computeAsync((monitor) -> handler.hover(position, monitor));
}
 
Example #25
Source File: JDTLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<Hover> hover(HoverParams position) {
	logInfo(">> document/hover");
	HoverHandler handler = new HoverHandler(this.preferenceManager);
	return computeAsync((monitor) -> handler.hover(position, monitor));
}
 
Example #26
Source File: LSPIJUtils.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
public static HoverParams toHoverParams(int offset, Document document) {
    return toTextDocumentPositionParamsCommon(new HoverParams(), offset, document);
}
 
Example #27
Source File: IHoverService.java    From xtext-core with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * callback for 'textDocument/hover' requests.
 * @since 2.21
 */
Hover hover(Document document, XtextResource resource, HoverParams params,
		CancelIndicator cancelIndicator);
 
Example #28
Source File: TextDocumentService.java    From lsp4j with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * The hover request is sent from the client to the server to request hover
 * information at a given text document position.
 * 
 * Registration Options: TextDocumentRegistrationOptions
 */
@JsonRequest
default CompletableFuture<Hover> hover(HoverParams params) {
	throw new UnsupportedOperationException();
}