org.eclipse.lsp4j.DefinitionParams Java Examples

The following examples show how to use org.eclipse.lsp4j.DefinitionParams. 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: LSPGotoDeclarationHandler.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement sourceElement, int offset, Editor editor) {
    try {
        URI uri = LSPIJUtils.toUri(editor.getDocument());
        if (uri != null) {
            DefinitionParams parms = new DefinitionParams(new TextDocumentIdentifier(uri.toString()), LSPIJUtils.toPosition(offset, editor.getDocument()));
            Set<PsiElement> targets = new HashSet<>();
            LanguageServiceAccessor.getInstance(sourceElement.getProject()).getLanguageServers(editor.getDocument(), capabilities -> capabilities.getDefinitionProvider()).thenComposeAsync(servers ->

                CompletableFuture.allOf(servers.stream().map(server -> server.getTextDocumentService().definition(parms).thenAcceptAsync(definitions -> targets.addAll(toElements(editor.getProject(), definitions))))
                .toArray(CompletableFuture[]::new))).get();
            return targets.toArray(new PsiElement[targets.size()]);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOGGER.warn(e.getLocalizedMessage(), e);
    }
    return new PsiElement[0];
}
 
Example #2
Source File: XMLTextDocumentService.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition(
		DefinitionParams params) {
	return computeDOMAsync(params.getTextDocument(), (cancelChecker, xmlDocument) -> {
		if (definitionLinkSupport) {
			return Either.forRight(
					getXMLLanguageService().findDefinition(xmlDocument, params.getPosition(), cancelChecker));
		}
		List<? extends Location> locations = getXMLLanguageService()
				.findDefinition(xmlDocument, params.getPosition(), cancelChecker) //
				.stream() //
				.map(locationLink -> XMLPositionUtility.toLocation(locationLink)) //
				.collect(Collectors.toList());
		return Either.forLeft(locations);
	});
}
 
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 testDefinition() throws Exception {
	URI fileURI = openFile("maven/salut4", "src/main/java/java/Foo.java");
	TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileURI.toString());
	DefinitionParams params = new DefinitionParams(identifier, new Position(10, 22));
	Either<List<? extends Location>, List<? extends LocationLink>> result = server.definition(params).join();
	assertTrue(result.isLeft());
	assertNotNull(result.getLeft());
	assertEquals(1, result.getLeft().size());
	String targetUri = result.getLeft().get(0).getUri();
	URI targetURI = JDTUtils.toURI(targetUri);
	assertNotNull(targetURI);
	assertEquals("jdt", targetURI.getScheme());
	assertTrue(targetURI.getPath().endsWith("PrintStream.class"));
	assertEquals(JDTEnvironmentUtils.SYNTAX_SERVER_ID, targetURI.getFragment());
}
 
Example #4
Source File: CamelTextDocumentService.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition(DefinitionParams params) {
	TextDocumentIdentifier textDocument = params.getTextDocument();
	LOGGER.info("definition: {}", textDocument);
	TextDocumentItem textDocumentItem = openedDocuments.get(textDocument.getUri());
	return new DefinitionProcessor(textDocumentItem).getDefinitions(params.getPosition());
}
 
Example #5
Source File: AbstractCamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
protected CompletableFuture<Either<List<? extends Location>,List<? extends LocationLink>>> getDefinitionsFor(CamelLanguageServer camelLanguageServer, Position position) {
	TextDocumentService textDocumentService = camelLanguageServer.getTextDocumentService();
	DefinitionParams params = new DefinitionParams();
	params.setPosition(position);
	params.setTextDocument(new TextDocumentIdentifier(DUMMY_URI+extensionUsed));
	return textDocumentService.definition(params);
}
 
Example #6
Source File: JDTLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition(DefinitionParams position) {
	logInfo(">> document/definition");
	NavigateToDefinitionHandler handler = new NavigateToDefinitionHandler(this.preferenceManager);
	return computeAsync((monitor) -> {
		waitForLifecycleJobs(monitor);
		return Either.forLeft(handler.definition(position, monitor));
	});
}
 
Example #7
Source File: SyntaxLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition(DefinitionParams position) {
	logInfo(">> document/definition");
	NavigateToDefinitionHandler handler = new NavigateToDefinitionHandler(this.preferenceManager);
	return computeAsync((monitor) -> {
		waitForLifecycleJobs(monitor);
		List<? extends Location> locations = handler.definition(position, monitor);
		for (Location location : locations) {
			location.setUri(JDTUtils.replaceUriFragment(location.getUri(), SYNTAX_SERVER_ID));
		}
		return Either.forLeft(locations);
	});
}
 
Example #8
Source File: ActionScriptServices.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
/**
 * Finds where the definition referenced at the current position in a text
 * document is defined.
 */
@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition(DefinitionParams 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
        {
            DefinitionProvider provider = new DefinitionProvider(workspaceFolderManager, fileTracker);
            return provider.definition(params, cancelToken);
        }
        finally
        {
            compilerWorkspace.doneBuilding();
        }
    });
}
 
Example #9
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void testDefinition(final Procedure1<? super DefinitionTestConfiguration> configurator) {
  try {
    @Extension
    final DefinitionTestConfiguration configuration = new DefinitionTestConfiguration();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    final String fileUri = this.initializeContext(configuration).getUri();
    DefinitionParams _definitionParams = new DefinitionParams();
    final Procedure1<DefinitionParams> _function = (DefinitionParams it) -> {
      TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
      it.setTextDocument(_textDocumentIdentifier);
      int _line = configuration.getLine();
      int _column = configuration.getColumn();
      Position _position = new Position(_line, _column);
      it.setPosition(_position);
    };
    DefinitionParams _doubleArrow = ObjectExtensions.<DefinitionParams>operator_doubleArrow(_definitionParams, _function);
    final CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definitionsFuture = this.languageServer.definition(_doubleArrow);
    final Either<List<? extends Location>, List<? extends LocationLink>> definitions = definitionsFuture.get();
    Procedure1<? super List<? extends Location>> _assertDefinitions = configuration.getAssertDefinitions();
    boolean _tripleNotEquals = (_assertDefinitions != null);
    if (_tripleNotEquals) {
      configuration.getAssertDefinitions().apply(definitions.getLeft());
    } else {
      final String actualDefinitions = this.toExpectation(definitions);
      this.assertEquals(configuration.getExpectedDefinitions(), actualDefinitions);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #10
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Compute the definition.
 */
protected List<? extends Location> definition(CancelIndicator cancelIndicator, DefinitionParams params) {
	URI uri = getURI(params);
	DocumentSymbolService documentSymbolService = getService(uri, DocumentSymbolService.class);
	if (documentSymbolService == null) {
		return Collections.emptyList();
	}
	return workspaceManager.doRead(uri,
			(doc, res) -> documentSymbolService.getDefinitions(doc, res, params, resourceAccess, cancelIndicator));
}
 
Example #11
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition(
		DefinitionParams params) {
	return requestManager.runRead(cancelIndicator -> definition(params, cancelIndicator));
}
 
Example #12
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Compute the definition. Executed in a read request.
 * @since 2.20
 */
protected Either<List<? extends Location>, List<? extends LocationLink>> definition(
		DefinitionParams params, CancelIndicator cancelIndicator) {
	return Either.forLeft(definition(cancelIndicator, params));
}
 
Example #13
Source File: DocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.21
 */
public List<? extends Location> getDefinitions(Document document, XtextResource resource, DefinitionParams params,
		IReferenceFinder.IResourceAccess resourceAccess, CancelIndicator cancelIndicator) {
	int offset = document.getOffSet(params.getPosition());
	return getDefinitions(resource, offset, resourceAccess, cancelIndicator);
}
 
Example #14
Source File: TextDocumentService.java    From lsp4j with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * The goto definition request is sent from the client to the server to resolve
 * the definition location of a symbol at a given text document position.
 * 
 * Registration Options: TextDocumentRegistrationOptions
 */
@JsonRequest
@ResponseJsonAdapter(LocationLinkListAdapter.class)
default CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition(DefinitionParams params) {
	throw new UnsupportedOperationException();
}