类org.eclipse.lsp4j.HoverParams源码实例Demo

下面列出了怎么用org.eclipse.lsp4j.HoverParams的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: eclipse.jdt.ls   文件: SyntaxServerTest.java
@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());
}
 
源代码2 项目: eclipse.jdt.ls   文件: SyntaxServerTest.java
@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());
}
 
源代码3 项目: eclipse.jdt.ls   文件: SyntaxServerTest.java
@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());
}
 
@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());
	}
}
 
@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);
}
 
@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);
}
 
@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);
}
 
@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);
}
 
@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();
}
 
@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();
}
 
@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();
}
 
@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);		
}
 
@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"));		
}
 
@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);		
}
 
@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);
}
 
@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\"");
}
 
@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();
}
 
源代码18 项目: wildwebdeveloper   文件: TestTypeScript.java
@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"));
}
 
源代码19 项目: vscode-as3mxml   文件: ActionScriptServices.java
/**
 * 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();
        }
    });
}
 
源代码20 项目: xtext-core   文件: LanguageServerImpl.java
/**
 * 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));
}
 
源代码21 项目: intellij-quarkus   文件: LSPIJUtils.java
public static HoverParams toHoverParams(int offset, Document document) {
    return toTextDocumentPositionParamsCommon(new HoverParams(), offset, document);
}
 
源代码22 项目: lemminx   文件: XMLTextDocumentService.java
@Override
public CompletableFuture<Hover> hover(HoverParams params) {
	return computeDOMAsync(params.getTextDocument(), (cancelChecker, xmlDocument) -> {
		return getXMLLanguageService().doHover(xmlDocument, params.getPosition(), sharedSettings, cancelChecker);
	});
}
 
源代码23 项目: eclipse.jdt.ls   文件: JDTLanguageServer.java
@Override
public CompletableFuture<Hover> hover(HoverParams position) {
	logInfo(">> document/hover");
	HoverHandler handler = new HoverHandler(this.preferenceManager);
	return computeAsync((monitor) -> handler.hover(position, monitor));
}
 
源代码24 项目: eclipse.jdt.ls   文件: SyntaxLanguageServer.java
@Override
public CompletableFuture<Hover> hover(HoverParams position) {
	logInfo(">> document/hover");
	HoverHandler handler = new HoverHandler(this.preferenceManager);
	return computeAsync((monitor) -> handler.hover(position, monitor));
}
 
源代码25 项目: xtext-core   文件: LanguageServerImpl.java
@Override
public CompletableFuture<Hover> hover(HoverParams params) {
	return requestManager.runRead((cancelIndicator) -> hover(params, cancelIndicator));
}
 
源代码26 项目: xtext-core   文件: HoverService.java
@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);
}
 
源代码27 项目: xtext-core   文件: IHoverService.java
/**
 * callback for 'textDocument/hover' requests.
 * @since 2.21
 */
Hover hover(Document document, XtextResource resource, HoverParams params,
		CancelIndicator cancelIndicator);
 
源代码28 项目: lsp4j   文件: TextDocumentService.java
/**
 * 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();
}
 
 类所在包
 类方法
 同包方法