forked from eclipse-lsp4e/lsp4e
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIMarkerAttributeComputer.java
More file actions
57 lines (52 loc) · 2.02 KB
/
IMarkerAttributeComputer.java
File metadata and controls
57 lines (52 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*******************************************************************************
* Copyright (c) 2016, 2017 Red Hat Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Rubén Porras Campo (Avaloq) - extracted to separate file
*******************************************************************************/
package org.eclipse.lsp4e;
import java.util.Map;
import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.text.IDocument;
import org.eclipse.lsp4e.internal.NullSafetyHelper;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
/**
* An interface that allows adding custom attributes to a
* {@link org.eclipse.core.resources.IMarker}.
*
*/
public interface IMarkerAttributeComputer {
/**
* Adds new attributes to a marker for the given document, diagnostic and
* resource.
*
* @param diagnostic
* the {@link Diagnostic} to me mapped to a marker
* @param document
* the {@link IDocument} attached to the given resource
* @param resource
* the {@link IResource} that contains the document
* @param attributes
* the map with the attributes for the marker, where the
* implementation can add attributes
*/
void addMarkerAttributesForDiagnostic(Diagnostic diagnostic, @Nullable IDocument document,
IResource resource, Map<String, Object> attributes);
/**
* Computes a string to be used as Marker message.
*/
default String computeMarkerMessage(Diagnostic diagnostic) {
final Either<String, Integer> code = diagnostic.getCode();
String messageText = NullSafetyHelper.defaultIfNull(diagnostic.getMessage().getLeft(), ""); //$NON-NLS-1$
return code == null //
? messageText
: messageText + " [" + code.get() + "]"; //$NON-NLS-1$//$NON-NLS-2$
}
}