下面列出了怎么用org.eclipse.lsp4j.TypeDefinitionParams的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> typeDefinition(
TypeDefinitionParams params) {
return computeDOMAsync(params.getTextDocument(), (cancelChecker, xmlDocument) -> {
if (typeDefinitionLinkSupport) {
return Either.forRight(
getXMLLanguageService().findTypeDefinition(xmlDocument, params.getPosition(), cancelChecker));
}
List<? extends Location> locations = getXMLLanguageService()
.findTypeDefinition(xmlDocument, params.getPosition(), cancelChecker) //
.stream() //
.map(locationLink -> XMLPositionUtility.toLocation(locationLink)) //
.collect(Collectors.toList());
return Either.forLeft(locations);
});
}
@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> typeDefinition(TypeDefinitionParams position) {
logInfo(">> document/typeDefinition");
NavigateToTypeDefinitionHandler handler = new NavigateToTypeDefinitionHandler();
return computeAsync((monitor) -> {
waitForLifecycleJobs(monitor);
return Either.forLeft((handler.typeDefinition(position, monitor)));
});
}
@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> typeDefinition(TypeDefinitionParams position) {
logInfo(">> document/typeDefinition");
NavigateToTypeDefinitionHandler handler = new NavigateToTypeDefinitionHandler();
return computeAsync((monitor) -> {
waitForLifecycleJobs(monitor);
List<? extends Location> locations = handler.typeDefinition(position, monitor);
for (Location location : locations) {
location.setUri(JDTUtils.replaceUriFragment(location.getUri(), SYNTAX_SERVER_ID));
}
return Either.forLeft(locations);
});
}
@Test
public void testTypeDefinition() throws Exception {
URI fileURI = openFile("maven/salut4", "src/main/java/java/Foo.java");
TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileURI.toString());
TypeDefinitionParams params = new TypeDefinitionParams(identifier, new Position(11, 24));
Either<List<? extends Location>, List<? extends LocationLink>> result = server.typeDefinition(params).join();
assertTrue(result.isLeft());
assertNotNull(result.getLeft());
assertEquals(1, result.getLeft().size());
String targetUri = result.getLeft().get(0).getUri();
assertNotNull(targetUri);
assertEquals(ResourceUtils.toClientUri(getFileUri("maven/salut4", "src/main/java/java/Bar.java")), targetUri);
}
/**
* Finds where the type of the definition referenced at the current position
* in a text document is defined.
*/
@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> typeDefinition(TypeDefinitionParams 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
{
TypeDefinitionProvider provider = new TypeDefinitionProvider(workspaceFolderManager, fileTracker);
return provider.typeDefinition(params, cancelToken);
}
finally
{
compilerWorkspace.doneBuilding();
}
});
}
/**
* The goto type definition request is sent from the client to the server to resolve
* the type definition location of a symbol at a given text document position.
*
* Registration Options: TextDocumentRegistrationOptions
*
* Since version 3.6.0
*/
@JsonRequest
@ResponseJsonAdapter(LocationLinkListAdapter.class)
default CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> typeDefinition(TypeDefinitionParams params) {
throw new UnsupportedOperationException();
}