微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.eclipse.lsp4j.Hover的实例源码

项目:camel-language-server    文件CamelLanguageServerHoverTest.java   
@Test
public void testProvideDocumentationOnHover() throws Exception {
    CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"ahc:httpUri\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n");

    TextDocumentPositionParams position = new TextDocumentPositionParams(new TextDocumentIdentifier(DUMMY_URI),new Position(0,13));
    CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(position);

    assertthat(hover.get().getContents().get(0).getLeft()).isEqualTo(AHC_DOCUMENTATION);
}
项目:eclipse.jdt.ls    文件HoverHandlerTest.java   
@Test
public void testHover() throws Exception {
    //given
    //Hovers on the System.out
    String payload = createHoverRequest("src/java/Foo.java",5,15);
    TextDocumentPositionParams position = getParams(payload);

    //when
    Hover hover = handler.hover(position,monitor);

    //then
    assertNotNull(hover);
    assertNotNull(hover.getContents());
    MarkedString signature = hover.getContents().get(0).getRight();
    assertEquals("Unexpected hover " + signature,"java",signature.getLanguage());
    assertEquals("Unexpected hover " + signature,"java.Foo",signature.getValue());
    String doc = hover.getContents().get(1).getLeft();
    assertEquals("Unexpected hover " + doc,"This is foo",doc);
}
项目:eclipse.jdt.ls    文件HoverHandlerTest.java   
@Test
public void testHoverStandalone() throws Exception {
    //given
    //Hovers on the System.out
    URI standalone = Paths.get("projects","maven","salut","src","main","Foo.java").toUri();
    String payload = createHoverRequest(standalone,10,71);
    TextDocumentPositionParams position = getParams(payload);

    //when
    Hover hover = handler.hover(position,signature.getValue());
    String doc = hover.getContents().get(1).getLeft();
    assertEquals("Unexpected hover "+doc,doc);
}
项目:eclipse.jdt.ls    文件HoverHandlerTest.java   
@Test
public void testHoverPackage() throws Exception {
    // given
    // Hovers on the java.internal package
    String payload = createHoverRequest("src/java/Baz.java",2,16);
    TextDocumentPositionParams position = getParams(payload);

    // when
    Hover hover = handler.hover(position,monitor);

    // then
    assertNotNull(hover);
    String signature = hover.getContents().get(0).getRight().getValue();//
    assertEquals("Unexpected signature ","java.internal",signature);
    String result = hover.getContents().get(1).getLeft();//
    assertEquals("Unexpected hover ","this is a **bold** package!",result);
}
项目:eclipse.jdt.ls    文件HoverHandlerTest.java   
@Test
public void testemptyHover() throws Exception {
    //given
    //Hovers on the System.out
    URI standalone = Paths.get("projects",1,2);
    TextDocumentPositionParams position = getParams(payload);

    //when
    Hover hover = handler.hover(position,monitor);

    //then
    assertNotNull(hover);
    assertNotNull(hover.getContents());
    assertEquals(1,hover.getContents().size());
    assertEquals("Should find empty hover for " + payload,"",hover.getContents().get(0).getLeft());
}
项目:eclipse.jdt.ls    文件HoverHandlerTest.java   
@Test
public void testHoverVariable() throws Exception {
    //given
    //Hover on args parameter
    String argParam = createHoverRequest("src/java/Foo.java",7,37);
    TextDocumentPositionParams position = getParams(argParam);

    //when
    Hover hover = handler.hover(position,"String[] args - java.Foo.main(String[])",signature.getValue());
}
项目:eclipse.jdt.ls    文件HoverHandlerTest.java   
@Test
public void testHoverOnPackageWithJavadoc() throws Exception {
    importProjects("maven/salut2");
    project = WorkspaceHelper.getProject("salut2");
    handler = new HoverHandler(preferenceManager);
    //given
    //Hovers on the org.apache.commons import
    String payload = createHoverRequest("src/main/java/foo/Bar.java",22);
    TextDocumentPositionParams position = getParams(payload);

    //when
    Hover hover = handler.hover(position,monitor);
    assertNotNull(hover);
    String result = hover.getContents().get(0).getRight().getValue();//
    assertEquals("Unexpected hover ","org.apache.commons",result);

    assertEquals(logListener.getErrors().toString(),logListener.getErrors().size());
}
项目:eclipse.jdt.ls    文件HoverHandlerTest.java   
@Test
public void testHoverThrowable() throws Exception {
    String uriString = ClassFileUtil.getURI(project,"java.lang.Exception");
    IClassFile classFile = JDTUtils.resolveClassFile(uriString);
    String contents = JavaLanguageServerPlugin.getContentProviderManager().getSource(classFile,monitor);
    IDocument document = new Document(contents);
    IRegion region = new FindReplaceDocumentAdapter(document).find(0,"Throwable",true,false,false);
    int offset = region.getoffset();
    int line = document.getLineOfOffset(offset);
    int character = offset - document.getLineOffset(line);
    TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uriString);
    Position position = new Position(line,character);
    TextDocumentPositionParams params = new TextDocumentPositionParams(textDocument,position);
    Hover hover = handler.hover(params,monitor);
    assertNotNull(hover);
    assertTrue("Unexpected hover ",!hover.getContents().isEmpty());
}
项目:xtext-core    文件LanguageServerImpl.java   
@Override
public CompletableFuture<Hover> hover(final TextDocumentPositionParams params) {
  final Function1<CancelIndicator,Hover> _function = (CancelIndicator cancelIndicator) -> {
    final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri());
    final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri);
    IHoverService _get = null;
    if (resourceServiceProvider!=null) {
      _get=resourceServiceProvider.<IHoverService>get(IHoverService.class);
    }
    final IHoverService hoverService = _get;
    if ((hoverService == null)) {
      return IHoverService.EMPTY_HOVER;
    }
    final Function2<Document,XtextResource,Hover> _function_1 = (Document document,XtextResource resource) -> {
      return hoverService.hover(document,resource,params,cancelIndicator);
    };
    return this.workspaceManager.<Hover>doRead(uri,_function_1);
  };
  return this.requestManager.<Hover>runRead(_function);
}
项目:camel-language-server    文件HoverProcessor.java   
public CompletableFuture<Hover> getHover(Position position) {
    try {
        ParserFileHelper parserFileHelper = new ParserFileHelper();
        if(parserFileHelper.getCorrespondingCamelNodeForCompletion(textDocumentItem,position.getLine()) != null){
            String camelComponentUri = parserFileHelper.getCamelComponentUri(textDocumentItem,position);
            String componentName = StringUtils.asComponentName(camelComponentUri);
            if (componentName != null) {
                return camelCatalog.thenApply(new HoverFuture(componentName));
            }
        }
    } catch (Exception e) {
        LOGGER.error("Error searching hover",e);
    }
    return CompletableFuture.completedFuture(null);
}
项目:camel-language-server    文件HoverFuture.java   
@Override
public Hover apply(CamelCatalog camelCatalog) {
    Hover hover = new Hover();
    ComponentModel componentModel = ModelHelper.generateComponentModel(camelCatalog.componentJSonSchema(componentName),true);
    hover.setContents(Collections.singletonList((Either.forLeft(componentModel.getDescription()))));
    return hover;
}
项目:camel-language-server    文件CamelLanguageServerHoverTest.java   
@Test
public void testDontProvideDocumentationOnHoverForBadplaces() throws Exception {
    CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"ahc:httpUri\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n");

    TextDocumentPositionParams position = new TextDocumentPositionParams(new TextDocumentIdentifier(DUMMY_URI),4));
    CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(position);

    assertthat(hover.get()).isNull();
}
项目:vscode-javac    文件Hovers.java   
public static Hover hoverText(Element el,Javadocs docs) {
    Optional<String> doc = docs.doc(el).map(Hovers::commentText).map(Javadocs::htmlToMarkdown);
    String sig = signature(el);
    String result =
            doc.map(text -> String.format("```java\n%s\n```\n%s",sig,text)).orElse(sig);

    return new Hover(Collections.singletonList(Either.forLeft(result)),null);
}
项目:eclipse.jdt.ls    文件HoverHandler.java   
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);
    }
    Hover $ = new Hover();
    $.setContents(content);
    return $;
}
项目:eclipse.jdt.ls    文件HoverHandlerTest.java   
@Test
public void testHoverInheritedJavadoc() throws Exception {
    // given
    // Hovers on the overriding foo()
    String payload = createHoverRequest("src/java/Bar.java",22,19);
    TextDocumentPositionParams position = getParams(payload);

    // when
    Hover hover = handler.hover(position,monitor);

    // then
    assertNotNull(hover);
    String result = hover.getContents().get(1).getLeft();//
    assertEquals("Unexpected hover ","This method comes from Foo",result);
}
项目:eclipse.jdt.ls    文件HoverHandlerTest.java   
@Test
public void testHoverOverNullElement() throws Exception {
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1",null);
    StringBuilder buf = new StringBuilder();
    buf.append("package test1;\n");
    buf.append("import javax.xml.bind.Binder;\n");
    buf.append("public class E {}\n");
    Icompilationunit cu = pack1.createcompilationunit("E.java",buf.toString(),null);
    Hover hover = getHover(cu,8);
    assertNotNull(hover);
    assertEquals(1,hover.getContents().size());
    assertEquals("Unexpected hover ","javax",hover.getContents().get(0).getRight().getValue());
}
项目:eclipse.jdt.ls    文件HoverHandlerTest.java   
@Test
public void testHoverUnresolvedType() throws Exception {
    importProjects("eclipse/unresolvedtype");
    project = WorkspaceHelper.getProject("unresolvedtype");
    handler = new HoverHandler(preferenceManager);
    //given
    //Hovers on the IFoo
    String payload = createHoverRequest("src/pckg/Foo.java",31);
    TextDocumentPositionParams position = getParams(payload);

    // when
    Hover hover = handler.hover(position,hover.getContents().isEmpty());
}
项目:eclipse.jdt.ls    文件HoverHandlerTest.java   
/**
 * @param cu
 * @return
 */
private String getTitleHover(Icompilationunit cu,int line,int character) {
    // when
    Hover hover = getHover(cu,line,character);

    // then
    assertNotNull(hover);
    MarkedString result = hover.getContents().get(0).getRight();
    return result.getValue();
}
项目:xtext-core    文件AbstractLanguageServerTest.java   
protected String _toExpectation(final Hover it) {
  StringConcatenation _builder = new StringConcatenation();
  String _expectation = this.toExpectation(it.getRange());
  _builder.append(_expectation);
  _builder.newLineIfNotEmpty();
  String _expectation_1 = this.toExpectation(it.getContents());
  _builder.append(_expectation_1);
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}
项目:xtext-core    文件HoverService.java   
protected Hover hover(final HoverContext context) {
  if ((context == null)) {
    return IHoverService.EMPTY_HOVER;
  }
  final List<Either<String,MarkedString>> contents = this.getContents(context);
  if ((contents == null)) {
    return IHoverService.EMPTY_HOVER;
  }
  final Range range = this.getRange(context);
  if ((range == null)) {
    return IHoverService.EMPTY_HOVER;
  }
  return new Hover(contents,range);
}
项目:che    文件DtoConversionTest.java   
@Test
public void testEitherConversion() {
  Either<String,MarkedString> either1 = Either.forLeft("foobar");
  Either<String,MarkedString> either2 = Either.forLeft("bar");
  List<Either<String,MarkedString>> entries = Arrays.asList(either1,either2);
  Hover hover = new Hover(entries,new Range(new Position(0,1),new Position(2,3)));

  HoverDto originalDto = new HoverDto(hover);
  Assert.assertTrue(reflectionEquals(originalDto,hover));
  String jsonString = originalDto.toJson();
  HoverDto convertedDto = HoverDto.fromJson(jsonString);
  Assert.assertTrue(reflectionEquals(originalDto,convertedDto));
}
项目:che    文件HoverProvider.java   
private String renderContent(Hover hover) {
  List<String> contents = new ArrayList<>();
  for (Either<String,MarkedString> dto : hover.getContents()) {
    if (dto.isLeft()) {
      // plain markdown text
      contents.add(dto.getLeft());
    } else {
      contents.add(dto.getRight().getLanguage());
      contents.add(dto.getRight().getValue());
    }
  }
  return Joiner.on("\n\n").join(contents);
}
项目:camel-language-server    文件CamelTextDocumentService.java   
@Override
public CompletableFuture<Hover> hover(TextDocumentPositionParams position) {
    LOGGER.info("hover: " + position.getTextDocument());
    TextDocumentItem textDocumentItem = openedDocuments.get(position.getTextDocument().getUri());
    return new HoverProcessor(textDocumentItem,camelCatalog).getHover(position.getPosition());
}
项目:SOMns-vscode    文件SomLanguageServer.java   
@Override
public CompletableFuture<Hover> hover(final TextDocumentPositionParams position) {
  // Todo Auto-generated method stub
  return null;
}
项目:eclipse.jdt.ls    文件JDTLanguageServer.java   
@Override
public CompletableFuture<Hover> hover(TextDocumentPositionParams position) {
    logInfo(">> document/hover");
    HoverHandler handler = new HoverHandler(this.preferenceManager);
    return computeAsync((cc) -> handler.hover(position,toMonitor(cc)));
}
项目:eclipse.jdt.ls    文件HoverHandlerTest.java   
private Hover getHover(Icompilationunit cu,int character) {
    String payload = createHoverRequest(cu,character);
    TextDocumentPositionParams position = getParams(payload);
    return handler.hover(position,monitor);
}
项目:xtext-core    文件HoverTestConfiguration.java   
@Pure
public Procedure1<? super Hover> getAssertHover() {
  return this.assertHover;
}
项目:xtext-core    文件HoverTestConfiguration.java   
public void setAssertHover(final Procedure1<? super Hover> assertHover) {
  this.assertHover = assertHover;
}
项目:xtext-core    文件HoverService.java   
@Override
public Hover hover(final Document document,final XtextResource resource,final TextDocumentPositionParams params,final CancelIndicator cancelIndicator) {
  final int offset = document.getoffSet(params.getPosition());
  final HoverContext context = this.createContext(document,offset);
  return this.hover(context);
}
项目:lsp4j    文件MockLanguageServer.java   
@Override
public CompletableFuture<Hover> hover(TextDocumentPositionParams position) {
    throw new UnsupportedOperationException();
}
项目:che    文件MavenTextDocumentService.java   
@Override
public CompletableFuture<Hover> hover(TextDocumentPositionParams position) {
  return null;
}
项目:SOMns-vscode    文件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
CompletableFuture<Hover> hover(TextDocumentPositionParams position);
项目:xtext-core    文件AbstractLanguageServerTest.java   
protected String toExpectation(final Object it) {
  if (it instanceof Integer) {
    return _toExpectation((Integer)it);
  } else if (it instanceof List) {
    return _toExpectation((List<?>)it);
  } else if (it instanceof DocumentHighlightKind) {
    return _toExpectation((DocumentHighlightKind)it);
  } else if (it instanceof String) {
    return _toExpectation((String)it);
  } else if (it == null) {
    return _toExpectation((Void)null);
  } else if (it instanceof Map) {
    return _toExpectation((Map<Object,Object>)it);
  } else if (it instanceof CodeLens) {
    return _toExpectation((CodeLens)it);
  } else if (it instanceof Coloringinformation) {
    return _toExpectation((Coloringinformation)it);
  } else if (it instanceof Command) {
    return _toExpectation((Command)it);
  } else if (it instanceof CompletionItem) {
    return _toExpectation((CompletionItem)it);
  } else if (it instanceof DocumentHighlight) {
    return _toExpectation((DocumentHighlight)it);
  } else if (it instanceof Hover) {
    return _toExpectation((Hover)it);
  } else if (it instanceof Location) {
    return _toExpectation((Location)it);
  } else if (it instanceof Position) {
    return _toExpectation((Position)it);
  } else if (it instanceof Range) {
    return _toExpectation((Range)it);
  } else if (it instanceof SignatureHelp) {
    return _toExpectation((SignatureHelp)it);
  } else if (it instanceof Symbolinformation) {
    return _toExpectation((Symbolinformation)it);
  } else if (it instanceof TextEdit) {
    return _toExpectation((TextEdit)it);
  } else if (it instanceof WorkspaceEdit) {
    return _toExpectation((WorkspaceEdit)it);
  } else if (it instanceof Either) {
    return _toExpectation((Either<?,?>)it);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it).toString());
  }
}
项目:xtext-core    文件IHoverService.java   
/**
 * callback for 'textDocument/hover' requests.
 */
public abstract Hover hover(final Document document,final CancelIndicator cancelIndicator);
项目: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
CompletableFuture<Hover> hover(TextDocumentPositionParams position);
项目:che    文件TextDocumentServiceClient.java   
/**
 * GWT client implementation of {@link TextDocumentService#hover(TextDocumentPositionParams)}
 *
 * @param params
 * @return
 */
public Promise<Hover> hover(TextDocumentPositionParams params) {
  return transmitDtoAndReceiveDto(params,"textDocument/hover",Hover.class);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。