use of org.eclipse.lsp4j.Diagnostic in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method addCompilerProblem.
private void addCompilerProblem(ICompilerProblem problem, PublishDiagnosticsParams publish) {
if (!flexLibSDKContainsFalconCompiler) {
if (problem.getClass().equals(FontEmbeddingNotSupported.class)) {
//ignore this error because the framework SDK can embed fonts
return;
}
}
Diagnostic diagnostic = new Diagnostic();
DiagnosticSeverity severity = LanguageServerUtils.getDiagnosticSeverityFromCompilerProblem(problem);
diagnostic.setSeverity(severity);
Range range = LanguageServerUtils.getRangeFromSourceLocation(problem);
if (range == null) {
//fall back to an empty range
range = new Range(new Position(), new Position());
}
diagnostic.setRange(range);
diagnostic.setMessage(problem.toString());
try {
Field field = problem.getClass().getDeclaredField("errorCode");
int errorCode = (int) field.get(problem);
diagnostic.setCode(Integer.toString(errorCode));
} catch (Exception e) {
//skip it
}
List<Diagnostic> diagnostics = publish.getDiagnostics();
diagnostics.add(diagnostic);
}
use of org.eclipse.lsp4j.Diagnostic in project sonarlint-core by SonarSource.
the class SonarLintLanguageServer method convert.
static Optional<Diagnostic> convert(Issue issue) {
if (issue.getStartLine() != null) {
Range range = position(issue);
Diagnostic diagnostic = new Diagnostic();
DiagnosticSeverity severity = severity(issue.getSeverity());
diagnostic.setSeverity(severity);
diagnostic.setRange(range);
diagnostic.setCode(issue.getRuleKey());
diagnostic.setMessage(issue.getMessage() + " (" + issue.getRuleKey() + ")");
diagnostic.setSource(SONARLINT_SOURCE);
return Optional.of(diagnostic);
}
return Optional.empty();
}
use of org.eclipse.lsp4j.Diagnostic in project xtext-core by eclipse.
the class CodeActionService method getCodeActions.
@Override
public List<? extends Command> getCodeActions(final Document document, final XtextResource resource, final CodeActionParams params, final CancelIndicator indicator) {
final ArrayList<Command> commands = CollectionLiterals.<Command>newArrayList();
List<Diagnostic> _diagnostics = params.getContext().getDiagnostics();
for (final Diagnostic d : _diagnostics) {
String _code = d.getCode();
if (_code != null) {
switch(_code) {
case TestLanguageValidator.INVALID_NAME:
Command _fixInvalidName = this.fixInvalidName(d, document, resource, params);
commands.add(_fixInvalidName);
break;
case TestLanguageValidator.UNSORTED_MEMBERS:
Command _fixUnsortedMembers = this.fixUnsortedMembers(d, document, resource, params);
commands.add(_fixUnsortedMembers);
break;
}
}
}
return commands;
}
use of org.eclipse.lsp4j.Diagnostic in project eclipse.jdt.ls by eclipse.
the class BuildWorkspaceHandler method publishDiagnostics.
private void publishDiagnostics(List<IMarker> markers) {
Map<IResource, List<IMarker>> map = markers.stream().collect(Collectors.groupingBy(IMarker::getResource));
for (Map.Entry<IResource, List<IMarker>> entry : map.entrySet()) {
IResource resource = entry.getKey();
// ignore problems caused by standalone files
if (JavaLanguageServerPlugin.getProjectsManager().getDefaultProject().equals(resource.getProject())) {
continue;
}
IFile file = resource.getAdapter(IFile.class);
if (file == null) {
continue;
}
IDocument document = null;
String uri = JDTUtils.getFileURI(resource);
if (JavaCore.isJavaLikeFileName(file.getName())) {
ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri);
try {
document = JsonRpcHelpers.toDocument(cu.getBuffer());
} catch (JavaModelException e) {
logException("Failed to publish diagnostics.", e);
}
} else if (projectsManager.isBuildFile(file)) {
document = JsonRpcHelpers.toDocument(file);
}
if (document != null) {
List<Diagnostic> diagnostics = WorkspaceDiagnosticsHandler.toDiagnosticsArray(document, entry.getValue().toArray(new IMarker[0]));
connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), diagnostics));
}
}
}
use of org.eclipse.lsp4j.Diagnostic in project eclipse.jdt.ls by eclipse.
the class WorkspaceDiagnosticsHandler method toDiagnostic.
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;
}
Aggregations