Java Code Examples for org.eclipse.lsp4j.Hover#setContents()

The following examples show how to use org.eclipse.lsp4j.Hover#setContents() . 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: HoverTypeAdapter.java    From lsp4j with Eclipse Public License 2.0 6 votes vote down vote up
public Hover read(final JsonReader in) throws IOException {
  JsonToken nextToken = in.peek();
  if (nextToken == JsonToken.NULL) {
  	return null;
  }
  
  Hover result = new Hover();
  in.beginObject();
  while (in.hasNext()) {
  	String name = in.nextName();
  	switch (name) {
  	case "contents":
  		result.setContents(readContents(in));
  		break;
  	case "range":
  		result.setRange(readRange(in));
  		break;
  	default:
  		in.skipValue();
  	}
  }
  in.endObject();
  return result;
}
 
Example 2
Source File: HoverProvider.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
public CompletableFuture<Hover> provideHover(TextDocumentIdentifier textDocument, Position position) {
	Hover hover = new Hover();
	List<Either<String, MarkedString>> contents = new ArrayList<>();
	hover.setContents(contents);

	if (ast == null) {
		//this shouldn't happen, but let's avoid an exception if something
		//goes terribly wrong.
		return CompletableFuture.completedFuture(hover);
	}

	URI uri = URI.create(textDocument.getUri());
	ASTNode offsetNode = ast.getNodeAtLineAndColumn(uri, position.getLine(), position.getCharacter());
	if (offsetNode == null) {
		return CompletableFuture.completedFuture(hover);
	}

	ASTNode definitionNode = GroovyASTUtils.getDefinition(offsetNode, false, ast);
	if (definitionNode == null) {
		return CompletableFuture.completedFuture(hover);
	}

	String content = getContent(definitionNode);
	if (content == null) {
		return CompletableFuture.completedFuture(hover);
	}

	contents.add(Either.forRight(new MarkedString("groovy", content)));
	return CompletableFuture.completedFuture(hover);
}
 
Example 3
Source File: HoverFuture.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Override
public Hover apply(CamelCatalog camelCatalog) {
	String componentJSonSchema = camelCatalog.componentJSonSchema(uriElement.getComponentName());
	if (componentJSonSchema != null) {
		Hover hover = new Hover();
		ComponentModel componentModel = ModelHelper.generateComponentModel(componentJSonSchema, true);
		hover.setContents(Collections.singletonList((Either.forLeft(uriElement.getDescription(componentModel)))));
		return hover;
	}
	return null;
}
 
Example 4
Source File: HoverHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public Hover hover(TextDocumentPositionParams position, IProgressMonitor monitor) {
	ITypeRoot unit = JDTUtils.resolveTypeRoot(position.getTextDocument().getUri());

	List<Either<String, MarkedString>> content = null;
	if (unit != null && !monitor.isCanceled()) {
		content = computeHover(unit, position.getPosition().getLine(), position.getPosition().getCharacter(), monitor);
	} else {
		content = Collections.singletonList(Either.forLeft(""));
	}
	Hover $ = new Hover();
	$.setContents(content);
	return $;
}