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

Code cleanup #1006

Merged
merged 9 commits into from
May 21, 2024
Merged

Code cleanup #1006

merged 9 commits into from
May 21, 2024

Conversation

sebthom
Copy link
Contributor

@sebthom sebthom commented May 21, 2024

No description provided.

import org.eclipse.lsp4e.LSPEclipseUtils;
import org.eclipse.lsp4j.Location;
import org.eclipse.search.ui.text.Match;

public class URIMatch extends Match {

public final @NonNull Location location;
public static URIMatch create(final Location location) throws BadLocationException, URISyntaxException {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's wrong with sticking to a constructor here?

Copy link
Contributor Author

@sebthom sebthom May 21, 2024

Choose a reason for hiding this comment

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

The problem is that the first invocation in a constructor needs to be a super() call, that's why the current implementation parses the URI three times instead of once and then reusing the uri object to construct arguments for the parent constructor. which is very inefficient.

That is what we have currently:

public URIMatch(@NonNull Location location) throws BadLocationException {
	super(
		URI.create(location.getUri()),
		LSPEclipseUtils.toOffset(location.getRange().getStart(), LSPEclipseUtils.getDocument(URI.create(location.getUri()))),
		LSPEclipseUtils.toOffset(location.getRange().getEnd(),  LSPEclipseUtils.getDocument(URI.create(location.getUri()))) - LSPEclipseUtils.toOffset(location.getRange().getStart(), LSPEclipseUtils.getDocument(URI.create(location.getUri()))));
	this.location = location;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, thanks. Can't wait for https://openjdk.org/jeps/447 ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, thanks. Can't wait for openjdk.org/jeps/447 ;)

Me too!

@mickaelistria mickaelistria merged commit a27b7a9 into eclipse-lsp4e:main May 21, 2024
7 checks passed
@sebthom sebthom deleted the refact2 branch June 28, 2024 20:22
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