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

Fix the end range of the diagnostics. #567

Merged
merged 4 commits into from
Feb 27, 2018

Conversation

yaohaizh
Copy link
Contributor

Fix the issue mentioned here: microsoft/vscode#43878

The end range is always be the same line as the start, which should not be the correct behavior. As this issue will cause multiple lines problems cannot be detected in the VSCode.

@fbricon @gorkem

Position start = new Position();
Position end = new Position();

start.setLine(problem.getSourceLineNumber() - 1);// VSCode is 0-based
Copy link
Contributor

Choose a reason for hiding this comment

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

jdt.ls is client agnostic, so we should rather say "clients are expected to be 0-based", or something like that

Copy link
Contributor

Choose a reason for hiding this comment

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

Unless I'm missing something, the protocol is 0-based

A range in a text document expressed as (zero-based) start and end positions.

Clients are usually 1-based (users count from 1) :)

Copy link
Contributor

@fbricon fbricon left a comment

Choose a reason for hiding this comment

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

Can you please add some unit tests?

private static Range convertRange(IOpenable openable, IProblem problem) {
try {
return JDTUtils.toRange(openable, problem.getSourceStart(), problem.getSourceEnd() - problem.getSourceStart() + 1);
} catch (CoreException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

in which case are we expected to catch CoreExceptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When try to access the Buffer of the IOpenable obect, it will throw JavaModelException. In this case, just use the previous behavior, which only based on the information of IProblem.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok please add a comment in the code then

@fbricon
Copy link
Contributor

fbricon commented Feb 22, 2018

PR looks to be working fine, this is a welcome improvement @yaohaizh!
Can you please add some unit tests showing multi-line ranges in action?

@fbricon fbricon added this to the End February 2018 milestone Feb 22, 2018
@yaohaizh
Copy link
Contributor Author

@fbricon For multiple line IProblems, there are some cases from this PR: #558 For current code actions, I didn't find any problems across multiple lines.

@fbricon
Copy link
Contributor

fbricon commented Feb 23, 2018

So we need to apply #558 before so dead code generates multiline problems?

@yaohaizh
Copy link
Contributor Author

yaohaizh commented Feb 23, 2018

Right, we need fix this one for dead code on VSCode. Otherwise, the VSCode cannot detect the code actions correctly. But other client might have different behavior for multiple-line IProblem.
See the logged bug: microsoft/vscode#43878

@@ -117,15 +117,28 @@ public void testUnimplementedMethods() throws Exception {
ICompilationUnit cu = pack1.createCompilationUnit("F.java", buf.toString(), false, null);
openDocument(cu, cu.getSource(), 1);

buf = new StringBuilder();
List<Command> commands = getCodeActions(cu);
assertTrue(commands.size() == 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

never ever use assertTrue when assertEquals can do the job, you lose important diagnostic informations, i.e what was the actual value received.

buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);

List<Command> commands = getCodeActions(cu);
assertTrue(commands.size() == 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

assertEquals

}

@Test
public void testRemoveDeadCodeAfterIf() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

this test doesn't check for the range is multi-line, i.e what we're trying to fix in the 1st place

@yaohaizh
Copy link
Contributor Author

Updated the PR.

@fbricon fbricon merged commit 174c50a into eclipse-jdtls:master Feb 27, 2018
tsmaeder pushed a commit to bdshadow/eclipse.jdt.ls that referenced this pull request Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants