public static List<Diagnostic> toDiagnosticsArray(IOpenable openable, List<IProblem> problems) { List<Diagnostic> array = new ArrayList<>(problems.size()); for (IProblem problem : problems) { Diagnostic diag = new Diagnostic(); diag.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID); diag.setMessage(problem.getMessage()); diag.setCode(Integer.toString(problem.getID())); diag.setSeverity(convertSeverity(problem)); diag.setRange(convertRange(openable, problem)); array.add(diag); } return array; }
Diagnostic clone(Diagnostic diagnostic) { if (diagnostic == null) { return null; } String code = diagnostic.getCode(); String message = diagnostic.getMessage(); Range range = diagnostic.getRange(); List<DiagnosticRelatedInformation> relatedInformation = diagnostic.getRelatedInformation(); DiagnosticSeverity severity = diagnostic.getSeverity(); String source = diagnostic.getSource(); Diagnostic cloned = new Diagnostic(); cloned.setCode(code); cloned.setMessage(message); cloned.setRange(clone(range)); cloned.setRelatedInformation(cloneDRI(relatedInformation)); cloned.setSeverity(severity); cloned.setSource(source); return cloned; }
public Quickfix(String CODE_ACTION_CMD_ID, Diagnostic diag, QuickfixData<T> data) { super(); this.CODE_ACTION_CMD_ID = CODE_ACTION_CMD_ID; this.range = diag.getRange(); this.diagMsg = diag.getMessage(); this.data = data; }
@Before public void setup() throws IOException { MockitoAnnotations.initMocks(this); Diagnostic d1 = new Diagnostic(); d1.setMessage("Some message"); d1.setSeverity(DiagnosticSeverity.Error); Diagnostic d2 = new Diagnostic(); d2.setMessage("Some other message"); d2.setSeverity(DiagnosticSeverity.Warning); expectedDiagnostics = Sets.newHashSet(new PublishDiagnosticsParams("uri", ImmutableList.of(d1, d2))); expectedReferences.add(new SymbolInformation( "MyClassName", SymbolKind.Class, new Location("uri", Ranges.createRange(1, 1, 9, 9)), "Something")); expectedReferences.add(new SymbolInformation( "MyClassName2", SymbolKind.Class, new Location("uri", Ranges.createRange(1, 1, 9, 9)), "SomethingElse")); Set<SymbolInformation> allReferencesReturned = Sets.newHashSet(expectedReferences); // The reference that will be filtered out allReferencesReturned.add(new SymbolInformation( "MyClassName3", SymbolKind.Class, new Location("uri", Ranges.UNDEFINED_RANGE), "SomethingElse")); when(compilerWrapper.getWorkspaceRoot()).thenReturn(workspace.getRoot().toPath().toUri()); when(compilerWrapper.compile(any())).thenReturn(expectedDiagnostics); when(compilerWrapper.getFilteredSymbols(any())).thenReturn(allReferencesReturned); when(state.getCompilerWrapper()).thenReturn(compilerWrapper); service = new TestWorkspaceService(state); }
public DiagnosticDto(org.eclipse.lsp4j.Diagnostic o) { if (o.getCode() == null) { setCode((java.lang.String)null); } else { java.lang.String codeVal = (java.lang.String)makeDto(o.getCode());; setCode((java.lang.String)codeVal); if (o.getSource() == null) { setSource((java.lang.String)null); } else { java.lang.String sourceVal = (java.lang.String)makeDto(o.getSource());; setSource((java.lang.String)sourceVal); if (o.getMessage() == null) { setMessage((java.lang.String)null); } else { java.lang.String messageVal = (java.lang.String)makeDto(o.getMessage());; setMessage((java.lang.String)messageVal); if (o.getRelatedInformation() == null) { setRelatedInformation((java.util.List<org.eclipse.lsp4j.DiagnosticRelatedInformation>)null); } else { ArrayList<org.eclipse.lsp4j.DiagnosticRelatedInformation> relatedInformationVal= new ArrayList<org.eclipse.lsp4j.DiagnosticRelatedInformation>(); for (org.eclipse.lsp4j.DiagnosticRelatedInformation relatedInformationValX : o.getRelatedInformation()) { org.eclipse.lsp4j.DiagnosticRelatedInformation relatedInformationValY = new DiagnosticRelatedInformationDto(relatedInformationValX); relatedInformationVal.add(relatedInformationValY); if (o.getRange() == null) { setRange((org.eclipse.lsp4j.Range)null); } else {
private Diagnostic createDiagnostic(String message, DiagnosticSeverity severity, String source) { return new Diagnostic(Ranges.UNDEFINED_RANGE, message, severity, source); }
Diagnostic diagnostic = new Diagnostic(range, diag.getMessage()); diagnostic.setSeverity(DiagnosticSeverity.Error); clientDiagnostics.add(diagnostic); });
public static boolean isDiagnosticCovering(Diagnostic diag, TextDocumentInfo doc, String string) { Range rng = diag.getRange(); String actualText = doc.getText(rng); return string.equals(actualText); }
private IProblemLocationCore[] getProblemLocationCores(ICompilationUnit unit, List<Diagnostic> diagnostics) { IProblemLocationCore[] locations = new IProblemLocationCore[diagnostics.size()]; for (int i = 0; i < diagnostics.size(); i++) { Diagnostic diagnostic = diagnostics.get(i); int problemId = getProblemId(diagnostic); int start = DiagnosticsHelper.getStartOffset(unit, diagnostic.getRange()); int end = DiagnosticsHelper.getEndOffset(unit, diagnostic.getRange()); boolean isError = diagnostic.getSeverity() == DiagnosticSeverity.Error; locations[i] = new ProblemLocationCore(start, end - start, problemId, new String[0], isError, IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); } return locations; }
private boolean appliesToContext(CodeActionContext context) { if (context!=null) { return context.getDiagnostics().stream().anyMatch(diag -> this.diagMsg == null || this.diagMsg.equals(diag.getMessage()) ); } return true; } }
private int getProblemId(Diagnostic diagnostic) { int $ = 0; try { $ = Integer.parseInt(diagnostic.getCode()); } catch (NumberFormatException e) { // return 0 } return $; }
public static Condition<Diagnostic> isDiagnosticWithSeverity(DiagnosticSeverity severity) { return new Condition<>( (d) -> d.getSeverity()==severity, "Diagnostic with severity '"+severity+"'" ); }
? "" : message.getMessage(); Diagnostic diag = new Diagnostic( Ranges.UNDEFINED_RANGE, message1, DiagnosticSeverity.Warning, GroovyConstants.GROOVY_COMPILER); diagnosticsByFile.computeIfAbsent(workspaceRoot.toUri(), (ignored) -> Lists.newArrayList()).add(diag); cause.getEndColumn()); uri = Paths.get(cause.getSourceLocator()).toUri(); diagnostic = new Diagnostic( range, cause.getMessage(), DiagnosticSeverity.Error, GroovyConstants.GROOVY_COMPILER); } else { uri = workspaceRoot.toUri(); String message1 = data.toString(); diagnostic = new Diagnostic( Ranges.UNDEFINED_RANGE, message1, DiagnosticSeverity.Error, GroovyConstants.GROOVY_COMPILER);
@Override public int compare(Diagnostic o1, Diagnostic o2) { int diff = compare(o1.getRange().getStart(), o2.getRange().getStart()); if (diff!=0) return diff; diff = compare(o1.getRange().getEnd(), o2.getRange().getEnd()); if (diff!=0) return diff; return o1.getMessage().compareTo(o2.getMessage()); }
public List<CodeAction> getCodeActions(TextDocumentInfo doc, Diagnostic problem) throws Exception { CodeActionContext context = new CodeActionContext(ImmutableList.of(problem)); List<Either<Command, org.eclipse.lsp4j.CodeAction>> actions = getServer().getTextDocumentService().codeAction(new CodeActionParams(doc.getId(), problem.getRange(), context)).get(); return actions.stream() .map(e -> e.getLeft()) .map((command) -> new CodeAction(this, command)) .collect(Collectors.toList()); }
String diagnosticMessage = diagnostic.getMessage(); List<Command> commands = new ArrayList<>(); Position position = params.getRange().getStart();
Editor editor = this; List<Diagnostic> actualProblems = new ArrayList<>(editor.reconcile().stream().filter(d -> { return !ignoredTypes.contains(d.getCode()); }).collect(Collectors.toList())); Collections.sort(actualProblems, PROBLEM_COMPARATOR);
private static Diagnostic toDiagnostic(IDocument document, IMarker marker) { if (marker == null || !marker.exists()) { return null; } Diagnostic d = new Diagnostic(); d.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID); d.setMessage(marker.getAttribute(IMarker.MESSAGE, "")); d.setCode(String.valueOf(marker.getAttribute(IJavaModelMarker.ID, 0))); d.setSeverity(convertSeverity(marker.getAttribute(IMarker.SEVERITY, -1))); d.setRange(convertRange(document, marker)); return d; }
@Test public void testCompile_withDiagnostics() throws IOException { when(compiler.compile(any())).thenReturn(Sets.newHashSet( new PublishDiagnosticsParams("uri", ImmutableList.of( new Diagnostic(Ranges.UNDEFINED_RANGE, "name", DiagnosticSeverity.Error, "groovyc"))))); wrapper.compile(ImmutableSet.of()); // assert parser wasn't called Mockito.verify(parser, Mockito.never()).parseAllSymbols(); }
private String problemSumary(Editor editor, List<Diagnostic> actualProblems) throws Exception { StringBuilder buf = new StringBuilder(); for (Diagnostic p : actualProblems) { buf.append("\n----------------------\n"); String snippet = editor.getText(p.getRange()); buf.append("("+p.getRange().getStart().getLine()+", "+p.getRange().getStart().getCharacter()+")["+snippet+"]:\n"); buf.append(" "+p.getMessage()); } return buf.toString(); }