本文整理汇总了Java中org.eclipse.lsp4j.Diagnostic类的典型用法代码示例。如果您正苦于以下问题:Java Diagnostic类的具体用法?Java Diagnostic怎么用?Java Diagnostic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Diagnostic类属于org.eclipse.lsp4j包,在下文中一共展示了Diagnostic类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: convert
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
static Optional<Diagnostic> convert(javax.tools.Diagnostic<? extends JavaFileObject> error) {
if (error.getStartPosition() != javax.tools.Diagnostic.NOPOS) {
Range range = position(error);
Diagnostic diagnostic = new Diagnostic();
DiagnosticSeverity severity = severity(error.getKind());
diagnostic.setSeverity(severity);
diagnostic.setRange(range);
diagnostic.setCode(error.getCode());
diagnostic.setMessage(error.getMessage(null));
return Optional.of(diagnostic);
} else {
LOG.warning("Skipped " + error.getMessage(Locale.getDefault()));
return Optional.empty();
}
}
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:19,代码来源:Lints.java
示例2: position
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
private static Range position(javax.tools.Diagnostic<? extends JavaFileObject> error) {
if (error instanceof ClientCodeWrapper.DiagnosticSourceUnwrapper)
error = ((ClientCodeWrapper.DiagnosticSourceUnwrapper) error).d;
JCDiagnostic diagnostic = (JCDiagnostic) error;
DiagnosticSource source = diagnostic.getDiagnosticSource();
long start = error.getStartPosition(), end = error.getEndPosition();
if (end == start) end = start + 1;
return new Range(
new Position(
source.getLineNumber((int) start) - 1,
source.getColumnNumber((int) start, true) - 1),
new Position(
source.getLineNumber((int) end) - 1,
source.getColumnNumber((int) end, true) - 1));
}
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:19,代码来源:Lints.java
示例3: checkFileNameMatchesModule
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
private static void checkFileNameMatchesModule(final MixinDefinition def,
final String fileName,
final List<Diagnostic> diagnostics) {
String moduleName = fileName;
if (moduleName.contains(".")) {
moduleName = moduleName.substring(0, moduleName.indexOf("."));
}
if (!moduleName.equals(def.getName().getString())) {
diagnostics.add(new Diagnostic(
toRange(def.getNameSourceSection()),
"Module name '" + def.getName().getString() + "' does not match file name '"
+ fileName
+ "'.",
DiagnosticSeverity.Information, LINT_NAME));
}
}
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:19,代码来源:SomLint.java
示例4: loadWorkspaceAndLint
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
private void loadWorkspaceAndLint(final File workspace) {
Map<String, List<Diagnostic>> allDiagnostics = new HashMap<>();
loadFolder(workspace, allDiagnostics);
for (Entry<String, List<Diagnostic>> e : allDiagnostics.entrySet()) {
try {
lintSends(e.getKey(), e.getValue());
} catch (URISyntaxException ex) {
/*
* at this point, there is nothing to be done anymore,
* would have been problematic earlier
*/
}
reportDiagnostics(e.getValue(), e.getKey());
}
}
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:18,代码来源:SomAdapter.java
示例5: loadFolder
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
private void loadFolder(final File folder,
final Map<String, List<Diagnostic>> allDiagnostics) {
for (File f : folder.listFiles()) {
if (f.isDirectory()) {
loadFolder(f, allDiagnostics);
} else if (f.getName().endsWith(FILE_ENDING)) {
try {
byte[] content = Files.readAllBytes(f.toPath());
String str = new String(content, StandardCharsets.UTF_8);
String uri = f.toURI().toString();
List<Diagnostic> diagnostics = parse(str, uri);
allDiagnostics.put(uri, diagnostics);
} catch (IOException | URISyntaxException e) {
// if loading fails, we don't do anything, just move on to the next file
}
}
}
}
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:19,代码来源:SomAdapter.java
示例6: assertNewProblemReported
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
private void assertNewProblemReported(ExpectedProblemReport... expectedReports) {
List<PublishDiagnosticsParams> diags = getClientRequests("publishDiagnostics");
assertEquals(expectedReports.length, diags.size());
for (int i = 0; i < expectedReports.length; i++) {
PublishDiagnosticsParams diag = diags.get(i);
ExpectedProblemReport expected = expectedReports[i];
assertEquals(JDTUtils.toURI(expected.cu), diag.getUri());
if (expected.problemCount != diag.getDiagnostics().size()) {
String message = "";
for (Diagnostic d : diag.getDiagnostics()) {
message += d.getMessage() + ", ";
}
assertEquals(message, expected.problemCount, diag.getDiagnostics().size());
}
}
diags.clear();
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:DocumentLifeCycleHandlerTest.java
示例7: testMavenMarkers
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
@Test
public void testMavenMarkers() throws Exception {
String msg1 = "Some dependency is missing";
IMarker m1 = createMavenMarker(IMarker.SEVERITY_ERROR, msg1, 2, 95, 100);
IDocument d = mock(IDocument.class);
when(d.getLineOffset(1)).thenReturn(90);
List<Diagnostic> diags = handler.toDiagnosticsArray(d, new IMarker[]{m1, null});
assertEquals(1, diags.size());
Range r;
Diagnostic d1 = diags.get(0);
assertEquals(msg1, d1.getMessage());
assertEquals(DiagnosticSeverity.Error, d1.getSeverity());
r = d1.getRange();
assertEquals(1, r.getStart().getLine());
assertEquals(95, r.getStart().getCharacter());
assertEquals(1, r.getEnd().getLine());
assertEquals(100, r.getEnd().getCharacter());
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:WorkspaceDiagnosticsHandlerTest.java
示例8: testInitializeBuildWithError
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
@Test
public void testInitializeBuildWithError() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Test {");
_builder.newLine();
_builder.append(" ");
_builder.append("NonExisting foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
this.writeFile("MyType1.testlang", _builder);
this.initialize();
Diagnostic _head = IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values()));
String _message = null;
if (_head!=null) {
_message=_head.getMessage();
}
this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.", _message);
Assert.assertEquals(1, IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getRange().getStart().getLine());
Assert.assertEquals(4, IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getRange().getStart().getCharacter());
Assert.assertEquals(1, IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getRange().getEnd().getLine());
Assert.assertEquals(15, IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getRange().getEnd().getCharacter());
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:24,代码来源:ServerTest.java
示例9: getCodeActions
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
@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;
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:22,代码来源:CodeActionService.java
示例10: getDiagnostics
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
protected Map<String, List<Diagnostic>> getDiagnostics() {
try {
final Function1<CancelIndicator, HashMap<String, List<Diagnostic>>> _function = (CancelIndicator it) -> {
final HashMap<String, List<Diagnostic>> result = CollectionLiterals.<String, List<Diagnostic>>newHashMap();
final Function1<Pair<String, Object>, Object> _function_1 = (Pair<String, Object> it_1) -> {
return it_1.getValue();
};
Iterable<PublishDiagnosticsParams> _filter = Iterables.<PublishDiagnosticsParams>filter(ListExtensions.<Pair<String, Object>, Object>map(this.notifications, _function_1), PublishDiagnosticsParams.class);
for (final PublishDiagnosticsParams diagnostic : _filter) {
result.put(diagnostic.getUri(), diagnostic.getDiagnostics());
}
return result;
};
return this.languageServer.getRequestManager().<HashMap<String, List<Diagnostic>>>runRead(_function).get();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:AbstractLanguageServerTest.java
示例11: processDiagnostics
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
public void processDiagnostics(ExtendedPublishDiagnosticsParams diagnosticsMessage) {
EditorPartPresenter openedEditor =
editorAgent.getOpenedEditor(new Path(diagnosticsMessage.getParams().getUri()));
// TODO add markers
if (openedEditor == null) {
return;
}
if (openedEditor instanceof TextEditor) {
TextEditorConfiguration editorConfiguration = ((TextEditor) openedEditor).getConfiguration();
AnnotationModel annotationModel = editorConfiguration.getAnnotationModel();
if (annotationModel != null && annotationModel instanceof DiagnosticCollector) {
DiagnosticCollector collector = (DiagnosticCollector) annotationModel;
String languageServerId = diagnosticsMessage.getLanguageServerId();
collector.beginReporting(languageServerId);
try {
for (Diagnostic diagnostic : diagnosticsMessage.getParams().getDiagnostics()) {
collector.acceptDiagnostic(languageServerId, diagnostic);
}
} finally {
collector.endReporting(languageServerId);
}
}
}
}
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:PublishDiagnosticsProcessor.java
示例12: codeActionsFor
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
private Stream<Command> codeActionsFor(Diagnostic diagnostic) {
if (diagnostic.getCode().equals("compiler.err.cant.resolve.location")) {
return cannotFindSymbolClassName(diagnostic.getMessage())
.map(Stream::of)
.orElseGet(Stream::empty)
.flatMap(this::addImportActions);
} else return Stream.empty();
}
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:9,代码来源:CodeActions.java
示例13: severity
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
private static DiagnosticSeverity severity(javax.tools.Diagnostic.Kind kind) {
switch (kind) {
case ERROR:
return DiagnosticSeverity.Error;
case WARNING:
case MANDATORY_WARNING:
return DiagnosticSeverity.Warning;
case NOTE:
case OTHER:
default:
return DiagnosticSeverity.Information;
}
}
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:14,代码来源:Lints.java
示例14: parseDocument
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
private void parseDocument(final String documentUri, final String text) {
try {
List<Diagnostic> diagnostics = som.parse(text, documentUri);
som.lintSends(documentUri, diagnostics);
som.reportDiagnostics(diagnostics, documentUri);
} catch (URISyntaxException ex) {
ex.printStackTrace(ServerLauncher.errWriter());
}
}
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:10,代码来源:SomLanguageServer.java
示例15: checkModuleName
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
public static void checkModuleName(final String filepath, final MixinDefinition def,
final List<Diagnostic> diagnostics) {
File f = new File(filepath);
String name = f.getName();
checkFileEnding(name, diagnostics);
checkFileNameMatchesModule(def, name, diagnostics);
}
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:9,代码来源:SomLint.java
示例16: checkSends
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
public static void checkSends(final Map<String, SomStructures> structuralProbes,
final SomStructures newProbe, final List<Diagnostic> diagnostics) {
Collection<SomStructures> probes;
synchronized (structuralProbes) {
probes = new ArrayList<>(structuralProbes.values());
}
List<Call> calls = newProbe.getCalls();
for (Call c : calls) {
if (newProbe.defines(c.selector)) {
continue;
}
boolean defined = false;
for (SomStructures p : probes) {
if (p.defines(c.selector)) {
defined = true;
break;
}
}
if (!defined) {
Range r = new Range(pos(c.sections[0].getStartLine(), c.sections[0].getStartColumn()),
pos(c.sections[c.sections.length - 1].getEndLine(),
c.sections[c.sections.length - 1].getEndColumn() + 1));
diagnostics.add(new Diagnostic(r,
"No " + c.selector.getString() + " defined. Might cause run time error.",
DiagnosticSeverity.Warning, LINT_NAME));
}
}
}
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:32,代码来源:SomLint.java
示例17: lintSends
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
public void lintSends(final String docUri, final List<Diagnostic> diagnostics)
throws URISyntaxException {
SomStructures probe;
synchronized (structuralProbes) {
probe = structuralProbes.get(docUriToNormalizedPath(docUri));
}
SomLint.checkSends(structuralProbes, probe, diagnostics);
}
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:9,代码来源:SomAdapter.java
示例18: toDiagnostics
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
private List<Diagnostic> toDiagnostics(final ParseError e,
final List<Diagnostic> diagnostics) {
Diagnostic d = new Diagnostic();
d.setSeverity(DiagnosticSeverity.Error);
SourceCoordinate coord = e.getSourceCoordinate();
d.setRange(toRangeMax(coord));
d.setMessage(e.getMessage());
d.setSource("Parser");
diagnostics.add(d);
return diagnostics;
}
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:14,代码来源:SomAdapter.java
示例19: reportDiagnostics
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
public void reportDiagnostics(final List<Diagnostic> diagnostics,
final String documentUri) {
if (diagnostics != null) {
PublishDiagnosticsParams result = new PublishDiagnosticsParams();
result.setDiagnostics(diagnostics);
result.setUri(documentUri);
client.publishDiagnostics(result);
}
}
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:10,代码来源:SomAdapter.java
示例20: publishDiagnostics
import org.eclipse.lsp4j.Diagnostic; //导入依赖的package包/类
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));
}
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:33,代码来源:BuildWorkspaceHandler.java
注:本文中的org.eclipse.lsp4j.Diagnostic类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论