Java Code Examples for org.eclipse.lsp4j.Location#getRange()

The following examples show how to use org.eclipse.lsp4j.Location#getRange() . 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: CallHierarchyHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private CallHierarchyItem toCallHierarchyItem(IMember member) throws JavaModelException {
	Location fullLocation = getLocation(member, LocationType.FULL_RANGE);
	Range range = fullLocation.getRange();
	String uri = fullLocation.getUri();
	CallHierarchyItem item = new CallHierarchyItem();
	item.setName(JDTUtils.getName(member));
	item.setKind(DocumentSymbolHandler.mapKind(member));
	item.setRange(range);
	item.setSelectionRange(getLocation(member, LocationType.NAME_RANGE).getRange());
	item.setUri(uri);
	IType declaringType = member.getDeclaringType();
	item.setDetail(declaringType == null ? null : declaringType.getFullyQualifiedName());
	if (JDTUtils.isDeprecated(member)) {
		item.setTags(Arrays.asList(SymbolTag.Deprecated));
	}

	return item;
}
 
Example 2
Source File: XSDRenameParticipant.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private List<TextEdit> renameAttributeValueTextEdits(DOMDocument document, DOMAttr attribute, String newText, List<Location> locations) {
	DOMNode attrValue = attribute.getNodeAttrValue();
	List<TextEdit> textEdits = new ArrayList<>();

	int valueStart = attrValue.getStart();
	int valueEnd = attrValue.getEnd();
	Range range = XMLPositionUtility.createRange(valueStart, valueEnd, document);

	// make range not cover " on both ends
	reduceRangeFromBothEnds(range, 1);

	textEdits.add(new TextEdit(range, newText));

	for (Location location: locations) {
		Range textEditRange = location.getRange();
		reduceRangeFromBothEnds(textEditRange, 1);

		String oldAttrValue;
		try {
			oldAttrValue = getAttrTextValueFromPosition(document, location.getRange().getStart());
		} catch (BadLocationException e1) {
			return Collections.emptyList();
		}
		
		int colonIndex = oldAttrValue.indexOf(":");
		
		if (colonIndex > 0) {
			increaseStartRange(textEditRange, colonIndex + 1);
		}

		TextEdit textEdit = new TextEdit(textEditRange, newText);
		textEdits.add(textEdit);
	}

	return textEdits;
}
 
Example 3
Source File: ReferencesProcessorTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testRetrieveASingleDirectReferenceFor_to() throws Exception {
	Location res = testRetrieveReferences(SINGLE_REFERENCE, 1, new Position(5, 18)).get(0);
	Range range = res.getRange();
	assertThat(range.getStart().getLine()).isEqualTo(8);
	assertThat(range.getEnd().getLine()).isEqualTo(8);
}
 
Example 4
Source File: ReferencesProcessorTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testRetrieveASingleDirectReferenceFor_to_whenUsingCamelNamespacePrefix() throws Exception {
	Location res = testRetrieveReferences(SINGLE_REFERENCE_WITH_NAMESPACE_PREFIX, 1, new Position(5, 26)).get(0);
	Range range = res.getRange();
	assertThat(range.getStart().getLine()).isEqualTo(8);
	assertThat(range.getEnd().getLine()).isEqualTo(8);
}
 
Example 5
Source File: ReferencesProcessorTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testRetrieveASingleDirectReferenceFor_from() throws Exception {
	Location res = testRetrieveReferences(SINGLE_REFERENCE, 1, new Position(8, 18)).get(0);
	Range range = res.getRange();
	assertThat(range.getStart().getLine()).isEqualTo(5);
	assertThat(range.getEnd().getLine()).isEqualTo(5);
}
 
Example 6
Source File: DocumentSymbolMapper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * The range enclosing this symbol not including leading/trailing whitespace but everything else like comments.
 */
public Range getRange(EObject object) {
	Location newFullLocation = documentExtensions.newFullLocation(object);
	if (newFullLocation != null) {
		return newFullLocation.getRange();
	}
	return null;
}
 
Example 7
Source File: DocumentSymbolMapper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
 */
public Range getSelectionRange(EObject object) {
	Location newLocation = documentExtensions.newLocation(object);
	if (newLocation != null) {
		return newLocation.getRange();
	}
	return null;
}
 
Example 8
Source File: DocumentSymbolHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private Range getRange(IJavaElement element) throws JavaModelException {
	Location location = JDTUtils.toLocation(element, FULL_RANGE);
	return location == null ? DEFAULT_RANGE : location.getRange();
}
 
Example 9
Source File: DocumentSymbolHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private Range getSelectionRange(IJavaElement element) throws JavaModelException {
	Location location = JDTUtils.toLocation(element);
	return location == null ? DEFAULT_RANGE : location.getRange();
}
 
Example 10
Source File: FindLinksHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public LinkLocation(String displayName, String kind, Location location) {
	super(location.getUri(), location.getRange());
	this.displayName = displayName;
	this.kind = kind;
}