Community
Participate
Working Groups
When you parse code and build a ModuleDeclaration (AST node) you could add DefaultProblem to IProblemReporter. If this DefaultProblem has just a line position and no offsetposition, The SourceModuleDocumentProvider does not manage it. (so the editor error annotation is not correctly positionned) The problem is in org.eclipse.dltk.internal.ui.editor.SourceModuleDocumentProvider.SourceModuleAnnotationModel.createPositionFromProblem(IProblem). a fix could be : ---------------- protected Position createPositionFromProblem(IProblem problem) { int start = problem.getSourceStart(); int end = problem.getSourceEnd(); if (start > end) { end = start + end; start = end - start; end = end - start; } if (start == -1 && end == -1) { // marker line number is 1-based int line = problem.getSourceLineNumber(); if (line > 0 && fDocument != null) { try { start = fDocument.getLineOffset(line - 1); end = start; } catch (BadLocationException x) { } } } if (start > -1 && end > -1) return new Position(start, end - start); return null; } Inspired by org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel.createPositionFromMarker(IMarker) I would like to implement a workarround by extending the SourceModuleDocumentProvider but it's impossible because this is a singleton which is used everywhere ...
pushed on gerrit : https://git.eclipse.org/r/#/c/36413/
Simon, can you tell me how I can have a DefaultProblem with only line position? So I can test your patch.
On AbstractSourceParser.parse, you create a DefaultProblem with just line position (no offset) and marker will be not placed at the right line in editor. If you have the code of LDT, you could just remove the workarround in LuaSourceParser line 160 // -- TODO ECLIPSE 411238 // -- we must calculate offset because DLTK does not support 'line' positioning if (problem.getSourceEnd() < 0) { try { final int line = problem.getSourceLineNumber(); final Document document = new Document(source); int endLineOffset = document.getLineOffset(line) + document.getLineLength(line) - 1; problem.setSourceStart(fixer.getCharacterPosition(problem.getSourceStart())); problem.setSourceEnd(endLineOffset); } catch (BadLocationException e) { Activator.logWarning("Unable to retrive error offset", e); //$NON-NLS-1$ } } else { // Handle encoding shifts problem.setSourceStart(fixer.getCharacterPosition(problem.getSourceStart())); problem.setSourceEnd(fixer.getCharacterPosition(problem.getSourceEnd())); } As it was said in the gerrit review, the code seems a bit strange, it was inspired from org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel.createPositionFromMarker(IMarker) and maybe it would be rewrite in clearer way.
(In reply to Simon Bernard from comment #3) > On AbstractSourceParser.parse, you create a DefaultProblem with just line > position (no offset) and marker will be not placed at the right line in > editor. I don't really understand how to create the default problem. However I've tried the remove the workaround from LuaSourceParser and apply the suggested patch in DLTK. In this case I get a double marker. I am not sure that this is exactly the effect you are looking for. I will attach screenshot.
Created attachment 252482 [details] double marker
The editor merges resource markers and temporary problems from editor contents. If marker and temporary problem cover the same range (and have the same message), then 1 marker is displayed. So, my guess in this case they are not treated identical.
* 1 problem annotation is displayed.
(In reply to Kaloyan Raev from comment #4) > I don't really understand how to create the default problem. I mean by modifying the code (hardcoding) but removing the workaround works well too. For the duplicate marker problem, it's clearly not what it was expected :p. If you remove the workaround and you sysout the line in error line 130: String cleanedSource = sourceValidator.getCleanedSource(); System.out.println(sourceValidator.getLineIndex()); if (!valid) module.setProblem(sourceValidator.getLineIndex(), -1, -1, -1, sourceValidator.getErrorMessage()); You should see that the annotation is at the right line. But not the marker which is at line n+1. in org.eclipse.dltk.compiler.problem.ProblemCollector.createMarkers(IResource, IProblemFactory, IProblemSeverityTranslator) I see LINE_NUMBER attibutes is set with problem.getSourceLineNumber() + 1. This seems strange... If I remove the +1 there no more duplicate annotation. (but remove a +1 like that is a bit creepy oO)