use of org.eclipse.lsp4j.Diagnostic in project sts4 by spring-projects.
the class ConcourseEditorTest method violatedPropertyConstraintsAreWarnings.
@Test
public void violatedPropertyConstraintsAreWarnings() throws Exception {
Editor editor;
editor = harness.newEditor("jobs:\n" + "- name: blah");
Diagnostic problem = editor.assertProblems("-^ name: blah|'plan' is required").get(0);
assertEquals(DiagnosticSeverity.Warning, problem.getSeverity());
editor = harness.newEditor("jobs:\n" + "- name: do-stuff\n" + " plan:\n" + " - task: foo");
problem = editor.assertProblems("-^ task: foo|One of [config, file] is required").get(0);
assertEquals(DiagnosticSeverity.Warning, problem.getSeverity());
editor = harness.newEditor("jobs:\n" + "- name: do-stuff\n" + " plan:\n" + " - task: foo\n" + " config: {}\n" + " file: path/to/file");
{
List<Diagnostic> problems = editor.assertProblems("config|One of [image_resource, rootfs_uri, image]", "config|Only one of [config, file]", "config|[platform, run] are required", "file|Only one of [config, file]");
// All of the problems in this example are property contraint violations! So all should be warnings.
for (Diagnostic diagnostic : problems) {
assertEquals(DiagnosticSeverity.Warning, diagnostic.getSeverity());
}
}
}
use of org.eclipse.lsp4j.Diagnostic in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method checkFilePathForSyntaxProblems.
private void checkFilePathForSyntaxProblems(Path path) {
URI uri = path.toUri();
PublishDiagnosticsParams publish = new PublishDiagnosticsParams();
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
publish.setDiagnostics(diagnostics);
publish.setUri(uri.toString());
codeProblemTracker.trackFileWithProblems(uri);
ASParser parser = null;
Reader reader = getReaderForPath(path);
if (reader != null) {
StreamingASTokenizer tokenizer = StreamingASTokenizer.createForRepairingASTokenizer(reader, uri.toString(), null);
ASToken[] tokens = tokenizer.getTokens(reader);
if (tokenizer.hasTokenizationProblems()) {
for (ICompilerProblem problem : tokenizer.getTokenizationProblems()) {
addCompilerProblem(problem, publish);
}
}
RepairingTokenBuffer buffer = new RepairingTokenBuffer(tokens);
Workspace workspace = new Workspace();
workspace.endRequest();
parser = new ASParser(workspace, buffer);
FileNode node = new FileNode(workspace);
try {
parser.file(node);
} catch (Exception e) {
parser = null;
System.err.println("Failed to parse file (" + path.toString() + "): " + e);
e.printStackTrace();
}
//if an error occurred above, parser will be null
if (parser != null) {
for (ICompilerProblem problem : parser.getSyntaxProblems()) {
addCompilerProblem(problem, publish);
}
}
}
Diagnostic diagnostic = createDiagnosticWithoutRange();
diagnostic.setSeverity(DiagnosticSeverity.Information);
if (reader == null) {
//the file does not exist
diagnostic.setSeverity(DiagnosticSeverity.Error);
diagnostic.setMessage("File not found: " + path.toAbsolutePath().toString() + ". Error checking disabled.");
} else if (parser == null) {
//something terrible happened, and this is the best we can do
diagnostic.setSeverity(DiagnosticSeverity.Error);
diagnostic.setMessage("A fatal error occurred while checking for simple syntax problems.");
} else if (currentProjectOptions == null) {
//something went wrong while attempting to load and parse the
//project configuration.
diagnostic.setMessage("Failed to load project configuration options. Error checking disabled, except for simple syntax problems.");
} else {
//we loaded and parsed the project configuration, so something went
//wrong while checking for errors.
diagnostic.setMessage("A fatal error occurred while checking for errors. Error checking disabled, except for simple syntax problems.");
}
diagnostics.add(diagnostic);
codeProblemTracker.cleanUpStaleProblems();
if (languageClient != null) {
languageClient.publishDiagnostics(publish);
}
}
use of org.eclipse.lsp4j.Diagnostic in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method codeAction.
/**
* Can be used to "quick fix" an error or warning.
*/
@Override
public CompletableFuture<List<? extends Command>> codeAction(CodeActionParams params) {
List<? extends Diagnostic> diagnostics = params.getContext().getDiagnostics();
TextDocumentIdentifier textDocument = params.getTextDocument();
Path path = LanguageServerUtils.getPathFromLanguageServerURI(textDocument.getUri());
if (path == null || !sourceByPath.containsKey(path)) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
ArrayList<Command> commands = new ArrayList<>();
for (Diagnostic diagnostic : diagnostics) {
//I don't know why this can be null
String code = diagnostic.getCode();
if (code == null) {
continue;
}
switch(code) {
case //AccessUndefinedPropertyProblem
"1120":
{
//see if there's anything we can import
createCodeActionsForImport(diagnostic, commands);
break;
}
case //UnknownTypeProblem
"1046":
{
//see if there's anything we can import
createCodeActionsForImport(diagnostic, commands);
break;
}
case //InaccessiblePropertyReferenceProblem
"1178":
{
//see if there's anything we can import
createCodeActionsForImport(diagnostic, commands);
break;
}
case //CallUndefinedMethodProblem
"1180":
{
//see if there's anything we can import
createCodeActionsForImport(diagnostic, commands);
break;
}
}
}
return CompletableFuture.completedFuture(commands);
}
use of org.eclipse.lsp4j.Diagnostic in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method createDiagnosticWithoutRange.
private Diagnostic createDiagnosticWithoutRange() {
Diagnostic diagnostic = new Diagnostic();
Range range = new Range();
range.setStart(new Position());
range.setEnd(new Position());
diagnostic.setRange(range);
return diagnostic;
}
use of org.eclipse.lsp4j.Diagnostic in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method checkCompilationUnitForAllProblems.
private PublishDiagnosticsParams checkCompilationUnitForAllProblems(ICompilationUnit unit) {
URI uri = Paths.get(unit.getAbsoluteFilename()).toUri();
PublishDiagnosticsParams publish = new PublishDiagnosticsParams();
publish.setDiagnostics(new ArrayList<>());
publish.setUri(uri.toString());
codeProblemTracker.trackFileWithProblems(uri);
ArrayList<ICompilerProblem> problems = new ArrayList<>();
try {
unit.waitForBuildFinish(problems, ITarget.TargetType.SWF);
for (ICompilerProblem problem : problems) {
addCompilerProblem(problem, publish);
}
} catch (Exception e) {
System.err.println("Exception during waitForBuildFinish(): " + e);
e.printStackTrace();
Diagnostic diagnostic = createDiagnosticWithoutRange();
diagnostic.setSeverity(DiagnosticSeverity.Error);
diagnostic.setMessage("A fatal error occurred while checking a file for problems: " + unit.getAbsoluteFilename());
publish.getDiagnostics().add(diagnostic);
}
return publish;
}
Aggregations