Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Open Call Hierarchy' does not jump to reference where it is invoked at #1824

Merged
merged 1 commit into from
Sep 9, 2021

Conversation

snjeza
Copy link
Contributor

@snjeza snjeza commented Aug 2, 2021

Fixes redhat-developer/vscode-java#2044

Signed-off-by: Snjezana Peco snjezana.peco@redhat.com

@snjeza
Copy link
Contributor Author

snjeza commented Aug 2, 2021

test this please

List<Range> ranges = toCallRanges(call.getMethodCall().getCallLocations());
result.add(new CallHierarchyIncomingCall(symbol, ranges));
Collection<CallLocation> callLocations = call.getMethodCall().getCallLocations();
List<Range> ranges = toCallRanges(callLocations);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move down the if block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fixed. ranges should only be computed if callLocations != null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. still not fixed. List<Range> ranges = toCallRanges(callLocations); needs to go inside the if block.

Collection<CallLocation> callLocations = call.getMethodCall().getCallLocations();
if (callLocations != null) {
	List<Range> ranges = toCallRanges(callLocations);
	for (CallLocation location : callLocations) {
		IOpenable openable = getOpenable(location);
		Range callRange = getRange(openable, location);
		CallHierarchyItem symbol = toCallHierarchyItem(call.getMember());
		symbol.setSelectionRange(callRange);
		result.add(new CallHierarchyIncomingCall(symbol, ranges));
	}
}

@@ -181,6 +191,9 @@ private IMember getCallHierarchyElement(String uri, int line, int character, IPr
return null;
}

if (!wrapper.canHaveChildren()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be combined with previous if block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 257 to 263
Collection<CallLocation> callLocations = call.getMethodCall().getCallLocations();
List<Range> ranges = toCallRanges(callLocations);
if (callLocations != null) {
for (CallLocation location : callLocations) {
IOpenable openable = location.getMember().getCompilationUnit();
if (openable == null) {
openable = location.getMember().getTypeRoot();
}
int[] start = JsonRpcHelpers.toLine(openable, location.getStart());
int[] end = JsonRpcHelpers.toLine(openable, location.getEnd());
Assert.isNotNull(start, "start");
Assert.isNotNull(end, "end");
// Assert.isLegal(start[0] == end[0], "Expected equal start and end lines. Start was: " + Arrays.toString(start) + " End was:" + Arrays.toString(end));
CallHierarchyItem symbol = toCallHierarchyItem(call.getMember());
result.add(new CallHierarchyOutgoingCall(symbol, ranges));
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid duplicate code, please refactor L208-L226 to a method call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@snjeza
Copy link
Contributor Author

snjeza commented Aug 27, 2021

@fbricon I have updated the PR.

@huangfeiyu
Copy link

huangfeiyu commented Sep 7, 2021

@snjeza @fbricon Thank you both! It will be super convenient after you fixed it. I used the function frequently.

@snjeza
Copy link
Contributor Author

snjeza commented Sep 7, 2021

@fbricon I have updated the PR.

@rgrunber
Copy link
Contributor

rgrunber commented Sep 7, 2021

One small issue I noticed. This seems to work fine for "Call Hierarchy", because it just relies on the selection range when jumping to an item. However, "Peek -> Call Hierarchy" relies on the first fromRange value and those are duplicated across calls that occur in the same method.

Are we ok with this ? It seems like it should be possible to adjust this but might make the code a bit more complicated.

peek-call-hierarchy

@@ -221,13 +249,20 @@ private IMember getCallHierarchyElement(String uri, int line, int character, IPr

List<CallHierarchyOutgoingCall> result = new ArrayList<>();
for (MethodWrapper call : calls) {
Collection<CallLocation> callLocations = call.getMethodCall().getCallLocations();
List<Range> ranges = toCallRanges(callLocations);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, List<Range> ranges = toCallRanges(callLocations); needs to go inside the if block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you, please, check it again?

@fbricon
Copy link
Contributor

fbricon commented Sep 8, 2021

Are we ok with this ? It seems like it should be possible to adjust this but might make the code a bit more complicated.

Yeah that sucks. If it's easy to fix in this PR, let's do this, else, we'll fix it in a subsequent change.

@snjeza snjeza force-pushed the issue-2044 branch 2 times, most recently from 6649d53 to 38a131c Compare September 8, 2021 17:11
Comment on lines 255 to 257
Iterator<CallLocation> iter = callLocations.iterator();
while (iter.hasNext()) {
iter.next();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is that helping since you're not using the current object from the iterator? Might has well check if callLocations is empty in the if block L253.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
@snjeza
Copy link
Contributor Author

snjeza commented Sep 8, 2021

test this please

Copy link
Contributor

@rgrunber rgrunber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this. Feel free to merge when ready, and file a bug for #1824 (comment) to track it once this is merged..

@snjeza snjeza merged commit 7f39397 into eclipse-jdtls:master Sep 9, 2021
@huangfeiyu
Copy link

Hi dear @snjeza, @fbricon do you know will this be included in the next milestone build?

@rgrunber
Copy link
Contributor

Yes. This should be included in the next eclipse.jdt.ls (1.4.0) release. You could also try it out with http://download.eclipse.org/jdtls/snapshots/jdt-language-server-latest.tar.gz , once it gets built there.

@huangfeiyu
Copy link

Thank you @rgrunber, that's exciting to hear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Open Call Hierarchy" does not jump to the reference where it is invoked at
4 participants