Java Code Examples for org.eclipse.lsp4j.CodeLens#setData()

The following examples show how to use org.eclipse.lsp4j.CodeLens#setData() . 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: XLanguageServerImpl.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Remove the document uri from the data of the given code lense.
 */
protected URI uninstallURI(CodeLens lens) {
	URI result = null;
	Object data = lens.getData();
	if (data instanceof String) {
		result = URI.createURI(data.toString());
		lens.setData(null);
	} else {
		if (data instanceof List<?>) {
			List<?> l = ((List<?>) data);
			result = URI.createURI(l.get(0).toString());
			lens.setData(l.get(1));
		}
	}
	return result;
}
 
Example 2
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Remove the document uri from the data of the given code lense.
 */
protected URI uninstallURI(CodeLens lens) {
	URI result = null;
	Object data = lens.getData();
	if (data instanceof String) {
		result = URI.createURI(data.toString());
		lens.setData(null);
	} else {
		if (data instanceof List<?>) {
			List<?> l = (List<?>) data;
			result = URI.createURI(l.get(0).toString());
			lens.setData(l.get(1));
		}
	}
	return result;
}
 
Example 3
Source File: XLanguageServerImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Put the document uri into the data of the given code lenses.
 */
protected void installURI(List<? extends CodeLens> codeLenses, String uri) {
	for (CodeLens lens : codeLenses) {
		Object data = lens.getData();
		if (data != null) {
			lens.setData(Arrays.asList(uri, lens.getData()));
		} else {
			lens.setData(uri);
		}
	}
}
 
Example 4
Source File: CodeLensHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private CodeLens getCodeLens(String type, IJavaElement element, ITypeRoot typeRoot) throws JavaModelException {
	ISourceRange r = ((ISourceReference) element).getNameRange();
	if (r == null) {
		return null;
	}
	CodeLens lens = new CodeLens();
	final Range range = JDTUtils.toRange(typeRoot, r.getOffset(), r.getLength());
	lens.setRange(range);
	String uri = ResourceUtils.toClientUri(JDTUtils.toUri(typeRoot));
	lens.setData(Arrays.asList(uri, range.getStart(), type));
	return lens;
}
 
Example 5
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 6
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Put the document uri into the data of the given code lenses.
 */
protected void installURI(List<? extends CodeLens> codeLenses, String uri) {
	for (CodeLens lens : codeLenses) {
		Object data = lens.getData();
		if (data != null) {
			lens.setData(Arrays.asList(uri, lens.getData()));
		} else {
			lens.setData(uri);
		}
	}
}
 
Example 7
Source File: ValidationTest.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInvalidCodeLens() {
	ResponseMessage message = new ResponseMessage();
	message.setId("1");
	CodeLens codeLens = new CodeLens(new Range(new Position(3, 32), new Position(3, 35)), null, null);
	// forbidden self reference!
	codeLens.setData(codeLens);
	message.setResult(codeLens);
	assertIssues(message, "An element of the message has a direct or indirect reference to itself.");
}