-
Notifications
You must be signed in to change notification settings - Fork 413
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
fix the NPE in DocumentSymbolHandler when source/location is not avai… #851
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,13 +47,15 @@ | |
import org.eclipse.lsp4j.DocumentSymbol; | ||
import org.eclipse.lsp4j.DocumentSymbolParams; | ||
import org.eclipse.lsp4j.Location; | ||
import org.eclipse.lsp4j.Position; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4j.SymbolInformation; | ||
import org.eclipse.lsp4j.SymbolKind; | ||
import org.eclipse.lsp4j.jsonrpc.messages.Either; | ||
import org.eclipse.xtext.xbase.lib.Exceptions; | ||
|
||
public class DocumentSymbolHandler { | ||
private static Range DEFAULT_RANGE = new Range(new Position(0, 0), new Position(0, 0)); | ||
|
||
private boolean hierarchicalDocumentSymbolSupported; | ||
|
||
|
@@ -171,11 +173,13 @@ private String getName(IJavaElement element) { | |
} | ||
|
||
private Range getRange(IJavaElement element) throws JavaModelException { | ||
return JDTUtils.toLocation(element, FULL_RANGE).getRange(); | ||
Location location = JDTUtils.toLocation(element, FULL_RANGE); | ||
return location == null ? DEFAULT_RANGE : location.getRange(); | ||
} | ||
|
||
private Range getSelectionRange(IJavaElement element) throws JavaModelException { | ||
return JDTUtils.toLocation(element).getRange(); | ||
Location location = JDTUtils.toLocation(element, FULL_RANGE); | ||
return location == null ? DEFAULT_RANGE : location.getRange(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getRange and getSelectionRange are now strictly identical O_o There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove the call of "toLocation" twice to share the location? I don't know why the original purpose of SelectionRange and getRange There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 on removing that. It was implemented according to the spec:
You might break other clients by changing those ranges |
||
|
||
private boolean isDeprecated(IJavaElement element) throws JavaModelException { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Location location = JDTUtils.toLocation(element);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.