org.eclipse.lsp4j.CodeLensParams Java Examples

The following examples show how to use org.eclipse.lsp4j.CodeLensParams. 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: CodeLensHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testGetCodeLensSymbolsForClass() throws Exception {
	Preferences implementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY, "true"));
	Mockito.reset(preferenceManager);
	when(preferenceManager.getPreferences()).thenReturn(implementationsCodeLenses);
	handler = new CodeLensHandler(preferenceManager);
	String uriString = ClassFileUtil.getURI(project, "java.lang.Runnable");
	String payload = createCodeLensSymbolRequest(new URI(uriString));
	CodeLensParams codeLensParams = getParams(payload);
	String uri = codeLensParams.getTextDocument().getUri();
	assertFalse(uri.isEmpty());
	List<CodeLens> lenses = handler.getCodeLensSymbols(uri, monitor);
	assertEquals("Found " + lenses, 2, lenses.size());
	List<Object> data = (List<Object>) lenses.get(0).getData();
	assertTrue("Unexpected type " + data, data.contains(CodeLensHandler.REFERENCES_TYPE));
	data = (List<Object>) lenses.get(1).getData();
	assertTrue("Unexpected type " + data, data.contains(CodeLensHandler.IMPLEMENTATION_TYPE));
}
 
Example #2
Source File: CodeLensHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDisableCodeLensSymbols() throws Exception {
	Preferences noCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.REFERENCES_CODE_LENS_ENABLED_KEY, "false"));
	Mockito.reset(preferenceManager);
	when(preferenceManager.getPreferences()).thenReturn(noCodeLenses);
	handler = new CodeLensHandler(preferenceManager);

	String payload = createCodeLensSymbolsRequest("src/java/IFoo.java");
	CodeLensParams codeLensParams = getParams(payload);
	String uri = codeLensParams.getTextDocument().getUri();
	assertFalse(uri.isEmpty());

	//when
	List<CodeLens> result = handler.getCodeLensSymbols(uri, monitor);

	//then
	assertEquals(0, result.size());
}
 
Example #3
Source File: CodeLensHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testEnableImplementationsCodeLensSymbols() throws Exception {
	Preferences implementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY, "true"));
	Mockito.reset(preferenceManager);
	when(preferenceManager.getPreferences()).thenReturn(implementationsCodeLenses);
	handler = new CodeLensHandler(preferenceManager);

	String payload = createCodeLensSymbolsRequest("src/java/IFoo.java");
	CodeLensParams codeLensParams = getParams(payload);
	String uri = codeLensParams.getTextDocument().getUri();
	assertFalse(uri.isEmpty());

	//when
	List<CodeLens> result = handler.getCodeLensSymbols(uri, monitor);

	//then
	assertEquals(2, result.size());
	CodeLens lens = result.get(1);
	@SuppressWarnings("unchecked")
	List<Object> data = (List<Object>) lens.getData();
	String type = (String) data.get(2);
	assertEquals(type, "implementations");
}
 
Example #4
Source File: CodeLensHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDisableImplementationsCodeLensSymbols() throws Exception {
	Preferences noImplementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY, "false"));
	Mockito.reset(preferenceManager);
	when(preferenceManager.getPreferences()).thenReturn(noImplementationsCodeLenses);
	Preferences noReferencesCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.REFERENCES_CODE_LENS_ENABLED_KEY, "false"));
	Mockito.reset(preferenceManager);
	when(preferenceManager.getPreferences()).thenReturn(noReferencesCodeLenses);
	handler = new CodeLensHandler(preferenceManager);

	String payload = createCodeLensSymbolsRequest("src/java/IFoo.java");
	CodeLensParams codeLensParams = getParams(payload);
	String uri = codeLensParams.getTextDocument().getUri();
	assertFalse(uri.isEmpty());

	//when
	List<CodeLens> result = handler.getCodeLensSymbols(uri, monitor);

	//then
	assertEquals(0, result.size());
}
 
Example #5
Source File: XMLTextDocumentService.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams params) {
	if (!sharedSettings.getCodeLensSettings().isEnabled()) {
		return CompletableFuture.completedFuture(Collections.emptyList());
	}
	return computeDOMAsync(params.getTextDocument(), (cancelChecker, xmlDocument) -> {
		return getXMLLanguageService().getCodeLens(xmlDocument, sharedSettings.getCodeLensSettings(),
				cancelChecker);
	});
}
 
Example #6
Source File: XLanguageServerImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams params) {
	URI uri = getURI(params.getTextDocument());
	return openFilesManager.runInOpenFileContext(uri, "codeLens", (ofc, ci) -> {
		return codeLens(ofc, params, ci);
	});
}
 
Example #7
Source File: XLanguageServerImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Compute the code lenses.
 */
protected List<? extends CodeLens> codeLens(OpenFileContext ofc, CodeLensParams params,
		CancelIndicator cancelIndicator) {
	URI uri = ofc.getURI();
	ICodeLensService codeLensService = getService(uri, ICodeLensService.class);
	if ((codeLensService == null)) {
		return Collections.emptyList();
	}
	XtextResource res = ofc.getResource();
	XDocument doc = ofc.getDocument();
	List<? extends CodeLens> result = codeLensService.computeCodeLenses(doc, res, params, cancelIndicator);
	installURI(result, uri.toString());
	return result;
}
 
Example #8
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Compute the code lenses. Executed in a read request.
 * @since 2.20
 */
protected List<? extends CodeLens> codeLens(CodeLensParams params, CancelIndicator cancelIndicator) {
	URI uri = getURI(params.getTextDocument());
	ICodeLensService codeLensService = getService(uri, ICodeLensService.class);
	if (codeLensService == null) {
		return Collections.emptyList();
	}
	return workspaceManager.doRead(uri, (document, resource) -> {
		List<? extends CodeLens> result = codeLensService.computeCodeLenses(document, resource, params,
				cancelIndicator);
		installURI(result, uri.toString());
		return result;
	});
}
 
Example #9
Source File: JDTLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams params) {
	logInfo(">> document/codeLens");
	CodeLensHandler handler = new CodeLensHandler(preferenceManager);
	return computeAsync((monitor) -> {
		waitForLifecycleJobs(monitor);
		return handler.getCodeLensSymbols(params.getTextDocument().getUri(), monitor);
	});
}
 
Example #10
Source File: CodeLensHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetCodeLensSymbols() throws Exception {
	String payload = createCodeLensSymbolsRequest("src/java/Foo.java");
	CodeLensParams codeLensParams = getParams(payload);
	String uri = codeLensParams.getTextDocument().getUri();
	assertFalse(uri.isEmpty());
	//when
	List<CodeLens> result = handler.getCodeLensSymbols(uri, monitor);

	//then
	assertEquals("Found " + result, 3, result.size());

	CodeLens cl = result.get(0);
	Range r = cl.getRange();
	//CodeLens on main method
	assertRange(7, 20, 24, r);

	cl = result.get(1);
	r = cl.getRange();
	// CodeLens on foo method
	assertRange(14, 13, 16, r);

	cl = result.get(2);
	r = cl.getRange();
	//CodeLens on Foo type
	assertRange(5, 13, 16, r);
}
 
Example #11
Source File: CodeLensHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetCodeLenseBoundaries() {
	List<CodeLens> result = handler.getCodeLensSymbols(null, monitor);
	assertNotNull(result);
	assertEquals(0, result.size());

	String payload = createCodeLensSymbolsRequest("src/java/Missing.java");
	CodeLensParams codeLensParams = getParams(payload);
	String uri = codeLensParams.getTextDocument().getUri();
	result = handler.getCodeLensSymbols(uri, monitor);
	assertEquals(0, result.size());
}
 
Example #12
Source File: CodeLensHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testIgnoreLombokCodeLensSymbols() throws Exception {
	String payload = createCodeLensSymbolsRequest("src/java/Bar.java");
	CodeLensParams codeLensParams = getParams(payload);
	String uri = codeLensParams.getTextDocument().getUri();
	assertFalse(uri.isEmpty());
	//when
	List<CodeLens> result = handler.getCodeLensSymbols(uri, monitor);

	//then
	assertEquals("Found " + result, 4, result.size());

	//CodeLens on constructor
	CodeLens cl = result.get(0);
	assertRange(7, 11, 14, cl.getRange());

	//CodeLens on somethingFromJPAModelGen
	cl = result.get(1);
	assertRange(16, 16, 40, cl.getRange());

	// CodeLens on foo
	cl = result.get(2);
	assertRange(22, 16, 19, cl.getRange());

	//CodeLens on Bar type
	cl = result.get(3);
	assertRange(5, 13, 16, cl.getRange());
}
 
Example #13
Source File: CodeLensService.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<? extends CodeLens> computeCodeLenses(Document document, XtextResource resource, CodeLensParams params,
		CancelIndicator indicator) {
	CodeLens codeLens = new CodeLens();
	Command command = new Command();
	command.setCommand("do.this");
	command.setTitle("Do Awesome Stuff");
	command.setArguments(Lists.newArrayList("foo", Integer.valueOf(1), Boolean.valueOf(true)));
	codeLens.setCommand(command);
	Position _position = new Position(1, 2);
	codeLens.setData(_position);
	return Lists.newArrayList(codeLens);
}
 
Example #14
Source File: CamelTextDocumentService.java    From camel-language-server with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams params) {
	LOGGER.info("codeLens: {}", params.getTextDocument());
	return CompletableFuture.completedFuture(Collections.emptyList());
}
 
Example #15
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams params) {
	return requestManager.runRead((cancelIndicator) -> codeLens(params, cancelIndicator));
}
 
Example #16
Source File: ActionScriptServices.java    From vscode-as3mxml with Apache License 2.0 4 votes vote down vote up
/**
 * This feature is not implemented at this time.
 */
@Override
public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams params)
{
    return CompletableFuture.completedFuture(Collections.emptyList());
}
 
Example #17
Source File: TeiidDdlTextDocumentService.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams params) {
    LOGGER.debug("codeLens: {}", params.getTextDocument());
    return CompletableFuture.completedFuture(Collections.emptyList());
}
 
Example #18
Source File: TextDocumentServiceImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams arg0) {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example #19
Source File: ICodeLensService.java    From xtext-core with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Compute code lenses for the given context.
 */
List<? extends CodeLens> computeCodeLenses(Document document, XtextResource resource, CodeLensParams params, CancelIndicator indicator);
 
Example #20
Source File: TextDocumentService.java    From lsp4j with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * The code lens request is sent from the client to the server to compute
 * code lenses for a given text document.
 * 
 * Registration Options: CodeLensRegistrationOptions
 */
@JsonRequest
default CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams params) {
	throw new UnsupportedOperationException();
}