-
Notifications
You must be signed in to change notification settings - Fork 373
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
Conversation
Position start = new Position(); | ||
Position end = new Position(); | ||
|
||
start.setLine(problem.getSourceLineNumber() - 1);// VSCode is 0-based |
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.
jdt.ls is client agnostic, so we should rather say "clients are expected to be 0-based", or something like that
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.
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) :)
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.
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) { |
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.
in which case are we expected to catch CoreExceptions?
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.
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.
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.
ok please add a comment in the code then
PR looks to be working fine, this is a welcome improvement @yaohaizh! |
So we need to apply #558 before so dead code generates multiline problems? |
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. |
1b99aa9
to
383cc9d
Compare
@@ -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); |
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.
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); |
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.
assertEquals
} | ||
|
||
@Test | ||
public void testRemoveDeadCodeAfterIf() throws Exception { |
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.
this test doesn't check for the range is multi-line, i.e what we're trying to fix in the 1st place
383cc9d
to
00bebde
Compare
Updated the PR. |
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