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

Add command to list Java projects #1238

Merged
merged 3 commits into from
Jul 28, 2021
Merged

Add command to list Java projects #1238

merged 3 commits into from
Jul 28, 2021

Conversation

jdneo
Copy link
Member

@jdneo jdneo commented Jul 27, 2021

No description provided.

@jdneo jdneo requested a review from Eskibear July 27, 2021 09:22
throws JavaModelException {
final String displayName;
final String fullName;
if (element instanceof IPackageFragment && ((IPackageFragment) element).isDefaultPackage()) {
displayName = DEFAULT_PACKAGE_NAME;
fullName = DEFAULT_PACKAGE_NAME;
fullName = "";
Copy link
Member

Choose a reason for hiding this comment

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

is empty string working?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes default package's element name is empty.

While here I should get the fullName in just one call, no need to handle separately, will update it.

final ISourceRange nameRange = ((ISourceReference) element).getNameRange();
if (SourceRange.isAvailable(sourceRange) && SourceRange.isAvailable(nameRange)) {
return JDTUtils.toRange(element.getOpenable(), nameRange.getOffset(),
sourceRange.getLength() - nameRange.getOffset() + sourceRange.getOffset());
Copy link
Member

Choose a reason for hiding this comment

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

sourceRange.getLength() - nameRange.getOffset() + sourceRange.getOffset() equals to nameRange.getLength()?

can you briefly explain?

Copy link
Member Author

Choose a reason for hiding this comment

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

sourceRange contains JavaDocs, so (nameRange.getOffset() - sourceRange.getOffset()) equals to the length of JavaDoc, I'll add a comment for it.

return Collections.emptyList();
}
final List<IJavaProject> javaProjects = new LinkedList<>();
for (final IJavaProject project : ProjectUtils.getJavaProjects()) {
Copy link
Member

Choose a reason for hiding this comment

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

Among ProjectUtils.getJavaProjects(), what else are you going to filter together with default project?

Copy link
Member Author

Choose a reason for hiding this comment

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

No other projects so far. All the projects that can be seen in user's workspaces should be listed

Copy link
Member

Choose a reason for hiding this comment

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

Just curious about if we can simply remove default project, and skip the "prefix checking"?

Copy link
Member

Choose a reason for hiding this comment

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

prefix checking it totally fine with me, just curious about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, that's a good point. As far as I know, currently we could have default project, visible project and invisible project. It seems that we can just remove the default project and put other Java projects into the list.

Copy link
Member

@Eskibear Eskibear left a comment

Choose a reason for hiding this comment

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

Overall the list projects part LGTM. But I remember JDTLS also has similar utility, is it exposed?

@jdneo
Copy link
Member Author

jdneo commented Jul 27, 2021

JDTLS has a utility to get all Java projects (ProjectUtils.getJavaProjects()), which I've used here

@jdneo jdneo merged commit 93f01d7 into cs/1.0.0-feature Jul 28, 2021
@jdneo jdneo deleted the cs/loadProject branch July 28, 2021 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants