org.eclipse.lsp4j.DocumentHighlightKind Java Examples
The following examples show how to use
org.eclipse.lsp4j.DocumentHighlightKind.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocumentHighlightHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private DocumentHighlight convertToHighlight(ITypeRoot unit, OccurrenceLocation occurrence) throws JavaModelException { DocumentHighlight h = new DocumentHighlight(); if ((occurrence.getFlags() | IOccurrencesFinder.F_WRITE_OCCURRENCE) == IOccurrencesFinder.F_WRITE_OCCURRENCE) { h.setKind(DocumentHighlightKind.Write); } else if ((occurrence.getFlags() | IOccurrencesFinder.F_READ_OCCURRENCE) == IOccurrencesFinder.F_READ_OCCURRENCE) { h.setKind(DocumentHighlightKind.Read); } int[] loc = JsonRpcHelpers.toLine(unit.getBuffer(), occurrence.getOffset()); int[] endLoc = JsonRpcHelpers.toLine(unit.getBuffer(), occurrence.getOffset() + occurrence.getLength()); h.setRange(new Range( new Position(loc[0], loc[1]), new Position(endLoc[0],endLoc[1]) )); return h; }
Example #2
Source File: DocumentHighlightComparatorTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void withNull() { List<? extends DocumentHighlight> input = sort( Lists.newArrayList(null, newHighlight(DocumentHighlightKind.Text, newRange(1, 1, 1, 1)), newHighlight(DocumentHighlightKind.Write, newRange(1, 1, 1, 1)), newHighlight(DocumentHighlightKind.Read, newRange(1, 1, 1, 1)))); assertEquals(1, input.get(0).getRange().getStart().getLine()); assertEquals(1, input.get(0).getRange().getStart().getCharacter()); assertEquals(1, input.get(0).getRange().getEnd().getLine()); assertEquals(1, input.get(0).getRange().getEnd().getCharacter()); assertEquals(DocumentHighlightKind.Text, input.get(0).getKind()); assertEquals(1, input.get(1).getRange().getStart().getLine()); assertEquals(1, input.get(1).getRange().getStart().getCharacter()); assertEquals(1, input.get(1).getRange().getEnd().getLine()); assertEquals(1, input.get(1).getRange().getEnd().getCharacter()); assertEquals(DocumentHighlightKind.Read, input.get(1).getKind()); assertEquals(1, input.get(2).getRange().getStart().getLine()); assertEquals(1, input.get(2).getRange().getStart().getCharacter()); assertEquals(1, input.get(2).getRange().getEnd().getLine()); assertEquals(1, input.get(2).getRange().getEnd().getCharacter()); assertEquals(DocumentHighlightKind.Write, input.get(2).getKind()); assertNull(IterableExtensions.last(input)); }
Example #3
Source File: ServerTest.java From netbeans with Apache License 2.0 | 5 votes |
private void assertHighlights(List<? extends DocumentHighlight> highlights, String... expected) { Set<String> stringHighlights = new HashSet<>(); for (DocumentHighlight h : highlights) { DocumentHighlightKind kind = h.getKind(); stringHighlights.add((kind != null ? kind.name() : "<none>") + ":" + h.getRange().getStart().getLine() + ":" + h.getRange().getStart().getCharacter() + "-" + h.getRange().getEnd().getLine() + ":" + h.getRange().getEnd().getCharacter()); } assertEquals(new HashSet<>(Arrays.asList(expected)), stringHighlights); }
Example #4
Source File: ITextRegionTransformer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public DocumentHighlight apply(final Document document, final ITextRegion region, final DocumentHighlightKind kind) { Preconditions.checkNotNull(document, "document"); Preconditions.checkNotNull(region, "region"); Preconditions.checkNotNull(kind, "kind"); final int offset = region.getOffset(); final Position start = document.getPosition(offset); final Position end = document.getPosition(offset + region.getLength()); return new DocumentHighlight(new Range(start, end), kind); }
Example #5
Source File: DocumentHighlightHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testDocumentHighlightHandler() throws Exception { String uri = ClassFileUtil.getURI(project, "org.sample.Highlight"); TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri); TextDocumentPositionParams params = new TextDocumentPositionParams(identifier, new Position(5, 10)); List<? extends DocumentHighlight> highlights = handler.documentHighlight(params, monitor); assertEquals(4, highlights.size()); assertHighlight(highlights.get(0), 5, 9, 15, DocumentHighlightKind.Write); assertHighlight(highlights.get(1), 6, 2, 8, DocumentHighlightKind.Read); assertHighlight(highlights.get(2), 7, 2, 8, DocumentHighlightKind.Write); assertHighlight(highlights.get(3), 8, 2, 8, DocumentHighlightKind.Read); }
Example #6
Source File: DocumentHighlightComparatorTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void withoutNull() { List<? extends DocumentHighlight> input = sort( Lists.newArrayList(newHighlight(DocumentHighlightKind.Text, newRange(2, 2, 2, 2)), newHighlight(DocumentHighlightKind.Text, newRange(1, 1, 1, 1)), newHighlight(DocumentHighlightKind.Write, newRange(2, 2, 2, 2)), newHighlight(DocumentHighlightKind.Write, newRange(1, 1, 1, 1)), newHighlight(DocumentHighlightKind.Read, newRange(2, 2, 2, 2)), newHighlight(DocumentHighlightKind.Read, newRange(1, 1, 1, 1)))); assertEquals(1, input.get(0).getRange().getStart().getLine()); assertEquals(1, input.get(0).getRange().getStart().getCharacter()); assertEquals(1, input.get(0).getRange().getEnd().getLine()); assertEquals(1, input.get(0).getRange().getEnd().getCharacter()); assertEquals(DocumentHighlightKind.Text, input.get(0).getKind()); assertEquals(1, input.get(1).getRange().getStart().getLine()); assertEquals(1, input.get(1).getRange().getStart().getCharacter()); assertEquals(1, input.get(1).getRange().getEnd().getLine()); assertEquals(1, input.get(1).getRange().getEnd().getCharacter()); assertEquals(DocumentHighlightKind.Read, input.get(1).getKind()); assertEquals(1, input.get(2).getRange().getStart().getLine()); assertEquals(1, input.get(2).getRange().getStart().getCharacter()); assertEquals(1, input.get(2).getRange().getEnd().getLine()); assertEquals(1, input.get(2).getRange().getEnd().getCharacter()); assertEquals(DocumentHighlightKind.Write, input.get(2).getKind()); assertEquals(2, input.get(3).getRange().getStart().getLine()); assertEquals(2, input.get(3).getRange().getStart().getCharacter()); assertEquals(2, input.get(3).getRange().getEnd().getLine()); assertEquals(2, input.get(3).getRange().getEnd().getCharacter()); assertEquals(DocumentHighlightKind.Text, input.get(3).getKind()); assertEquals(2, input.get(4).getRange().getStart().getLine()); assertEquals(2, input.get(4).getRange().getStart().getCharacter()); assertEquals(2, input.get(4).getRange().getEnd().getLine()); assertEquals(2, input.get(4).getRange().getEnd().getCharacter()); assertEquals(DocumentHighlightKind.Read, input.get(4).getKind()); assertEquals(2, input.get(5).getRange().getStart().getLine()); assertEquals(2, input.get(5).getRange().getStart().getCharacter()); assertEquals(2, input.get(5).getRange().getEnd().getLine()); assertEquals(2, input.get(5).getRange().getEnd().getCharacter()); assertEquals(DocumentHighlightKind.Write, input.get(5).getKind()); }
Example #7
Source File: XMLHighlighting.java From lemminx with Eclipse Public License 2.0 | 5 votes |
private static void fillHighlightsList(Range startTagRange, Range endTagRange, List<DocumentHighlight> result) { if (startTagRange != null) { result.add(new DocumentHighlight(startTagRange, DocumentHighlightKind.Read)); } if (endTagRange != null) { result.add(new DocumentHighlight(endTagRange, DocumentHighlightKind.Read)); } }
Example #8
Source File: AbstractLanguageServerTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected String _toExpectation(final DocumentHighlight it) { String _xblockexpression = null; { StringConcatenation _builder = new StringConcatenation(); { Range _range = it.getRange(); boolean _tripleEquals = (_range == null); if (_tripleEquals) { _builder.append("[NaN, NaN]:[NaN, NaN]"); } else { String _expectation = this.toExpectation(it.getRange()); _builder.append(_expectation); } } final String rangeString = _builder.toString(); StringConcatenation _builder_1 = new StringConcatenation(); { DocumentHighlightKind _kind = it.getKind(); boolean _tripleEquals_1 = (_kind == null); if (_tripleEquals_1) { _builder_1.append("NaN"); } else { String _expectation_1 = this.toExpectation(it.getKind()); _builder_1.append(_expectation_1); } } _builder_1.append(" "); _builder_1.append(rangeString); _xblockexpression = _builder_1.toString(); } return _xblockexpression; }
Example #9
Source File: DocumentHighlightComparatorTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
private DocumentHighlight newHighlight(DocumentHighlightKind kind, Range range) { return new DocumentHighlight(range, kind); }
Example #10
Source File: DocumentHighlight.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
/** * The highlight kind, default is {@link DocumentHighlightKind#Text}. */ public void setKind(final DocumentHighlightKind kind) { this.kind = kind; }
Example #11
Source File: DocumentHighlight.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
/** * The highlight kind, default is {@link DocumentHighlightKind#Text}. */ @Pure public DocumentHighlightKind getKind() { return this.kind; }
Example #12
Source File: DocumentHighlight.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
public DocumentHighlight(@NonNull final Range range, final DocumentHighlightKind kind) { this(range); this.kind = kind; }
Example #13
Source File: AbstractLanguageServerTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected String toExpectation(final Object it) { if (it instanceof Integer) { return _toExpectation((Integer)it); } else if (it instanceof List) { return _toExpectation((List<?>)it); } else if (it instanceof DocumentHighlightKind) { return _toExpectation((DocumentHighlightKind)it); } else if (it instanceof String) { return _toExpectation((String)it); } else if (it instanceof VersionedTextDocumentIdentifier) { return _toExpectation((VersionedTextDocumentIdentifier)it); } else if (it instanceof Pair) { return _toExpectation((Pair<SemanticHighlightingInformation, List<List<String>>>)it); } else if (it == null) { return _toExpectation((Void)null); } else if (it instanceof Map) { return _toExpectation((Map<Object, Object>)it); } else if (it instanceof CodeAction) { return _toExpectation((CodeAction)it); } else if (it instanceof CodeLens) { return _toExpectation((CodeLens)it); } else if (it instanceof Command) { return _toExpectation((Command)it); } else if (it instanceof CompletionItem) { return _toExpectation((CompletionItem)it); } else if (it instanceof DocumentHighlight) { return _toExpectation((DocumentHighlight)it); } else if (it instanceof DocumentSymbol) { return _toExpectation((DocumentSymbol)it); } else if (it instanceof Hover) { return _toExpectation((Hover)it); } else if (it instanceof Location) { return _toExpectation((Location)it); } else if (it instanceof MarkupContent) { return _toExpectation((MarkupContent)it); } else if (it instanceof Position) { return _toExpectation((Position)it); } else if (it instanceof Range) { return _toExpectation((Range)it); } else if (it instanceof ResourceOperation) { return _toExpectation((ResourceOperation)it); } else if (it instanceof SignatureHelp) { return _toExpectation((SignatureHelp)it); } else if (it instanceof SymbolInformation) { return _toExpectation((SymbolInformation)it); } else if (it instanceof TextDocumentEdit) { return _toExpectation((TextDocumentEdit)it); } else if (it instanceof TextEdit) { return _toExpectation((TextEdit)it); } else if (it instanceof WorkspaceEdit) { return _toExpectation((WorkspaceEdit)it); } else if (it instanceof Either) { return _toExpectation((Either<?, ?>)it); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it).toString()); } }
Example #14
Source File: AbstractLanguageServerTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected String _toExpectation(final DocumentHighlightKind kind) { return kind.toString().substring(0, 1).toUpperCase(); }
Example #15
Source File: CompletionTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override protected String toExpectation(final Object it) { if (it instanceof Integer) { return _toExpectation((Integer)it); } else if (it instanceof List) { return _toExpectation((List<?>)it); } else if (it instanceof DocumentHighlightKind) { return _toExpectation((DocumentHighlightKind)it); } else if (it instanceof String) { return _toExpectation((String)it); } else if (it instanceof VersionedTextDocumentIdentifier) { return _toExpectation((VersionedTextDocumentIdentifier)it); } else if (it instanceof Pair) { return _toExpectation((Pair<SemanticHighlightingInformation, List<List<String>>>)it); } else if (it == null) { return _toExpectation((Void)null); } else if (it instanceof Map) { return _toExpectation((Map<Object, Object>)it); } else if (it instanceof CodeAction) { return _toExpectation((CodeAction)it); } else if (it instanceof CodeLens) { return _toExpectation((CodeLens)it); } else if (it instanceof Command) { return _toExpectation((Command)it); } else if (it instanceof CompletionItem) { return _toExpectation((CompletionItem)it); } else if (it instanceof DocumentHighlight) { return _toExpectation((DocumentHighlight)it); } else if (it instanceof DocumentSymbol) { return _toExpectation((DocumentSymbol)it); } else if (it instanceof Hover) { return _toExpectation((Hover)it); } else if (it instanceof Location) { return _toExpectation((Location)it); } else if (it instanceof MarkupContent) { return _toExpectation((MarkupContent)it); } else if (it instanceof Position) { return _toExpectation((Position)it); } else if (it instanceof Range) { return _toExpectation((Range)it); } else if (it instanceof ResourceOperation) { return _toExpectation((ResourceOperation)it); } else if (it instanceof SignatureHelp) { return _toExpectation((SignatureHelp)it); } else if (it instanceof SymbolInformation) { return _toExpectation((SymbolInformation)it); } else if (it instanceof TextDocumentEdit) { return _toExpectation((TextDocumentEdit)it); } else if (it instanceof TextEdit) { return _toExpectation((TextEdit)it); } else if (it instanceof WorkspaceEdit) { return _toExpectation((WorkspaceEdit)it); } else if (it instanceof Either) { return _toExpectation((Either<?, ?>)it); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it).toString()); } }
Example #16
Source File: DocumentHighlightHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private void assertHighlight(DocumentHighlight highlight, int expectedLine, int expectedStart, int expectedEnd, DocumentHighlightKind expectedKind) { Lsp4jAssertions.assertRange(expectedLine, expectedStart, expectedEnd, highlight.getRange()); assertEquals(expectedKind, highlight.getKind()); }
Example #17
Source File: XMLAssert.java From lemminx with Eclipse Public License 2.0 | 4 votes |
public static DocumentHighlight hl(Range range, DocumentHighlightKind kind) { return new DocumentHighlight(range, kind); }
Example #18
Source File: XMLAssert.java From lemminx with Eclipse Public License 2.0 | 4 votes |
public static DocumentHighlight hl(Range range) { return hl(range, DocumentHighlightKind.Read); }
Example #19
Source File: DTDHighlightingParticipant.java From lemminx with Eclipse Public License 2.0 | 4 votes |
@Override public void findDocumentHighlights(DOMNode node, Position position, int offset, List<DocumentHighlight> highlights, CancelChecker cancelChecker) { boolean findReferences = false; DTDDeclParameter parameter = null; DTDElementDecl elementDecl = null; if (node.isDTDElementDecl()) { elementDecl = (DTDElementDecl) node; if (elementDecl.isInNameParameter(offset)) { // <!ELEMENT na|me --> here cursor is in the name of <!ELEMENT // we must find all references from the <!ELEMENT which defines the name findReferences = true; parameter = elementDecl.getNameParameter(); } else { // <!ELEMENT name (chi|ld --> here cursor is in the child element // we must find only the <!ELEMENT child parameter = elementDecl.getParameterAt(offset); } } else if (node.isDTDAttListDecl()) { DTDAttlistDecl attlistDecl = (DTDAttlistDecl) node; if (attlistDecl.isInNameParameter(offset)) { // <!ATTLIST na|me --> here cusror is in the name of <!ATTLIST // we must find only the <!ELEMENT name parameter = attlistDecl.getNameParameter(); } } if (parameter == null) { return; } if (findReferences) { // case with <!ELEMENT na|me // highlight <!ELEMENT na|me DTDDeclParameter originNode = parameter; highlights.add( new DocumentHighlight(XMLPositionUtility.createRange(originNode), DocumentHighlightKind.Write)); // highlight all references of na|me in ATTLIST and child of <!ELEMENT DTDUtils.searchDTDOriginElementDecls(elementDecl, (origin, target) -> { highlights .add(new DocumentHighlight(XMLPositionUtility.createRange(origin), DocumentHighlightKind.Read)); }, cancelChecker); } else { // case with // - <!ELEMENT name (chi|ld // - <!ATTLIST na|me // highlight <!ELEMENT name (chi|ld or <!ATTLIST na|me DTDDeclParameter targetNode = parameter; highlights .add(new DocumentHighlight(XMLPositionUtility.createRange(targetNode), DocumentHighlightKind.Read)); // highlight the target <!ELEMENT nam|e DTDUtils.searchDTDTargetElementDecl(parameter, true, targetName -> { highlights.add( new DocumentHighlight(XMLPositionUtility.createRange(targetName), DocumentHighlightKind.Write)); }); } }
Example #20
Source File: ITextRegionTransformer.java From xtext-core with Eclipse Public License 2.0 | 2 votes |
/** * Transforms the {@link ITextRegion text region} argument into a * {@link DocumentHighlight document highlight} instance by calculating the * proper position from the document. The given kind will be used to * distinguish between {@link DocumentHighlightKind#Read read}, * {@link DocumentHighlightKind#Write write} and ordinary * {@link DocumentHighlightKind#Text text} occurrences. * * <p> * This conversion is required to transform the Xtext specific document * relative offsets into language server specific line relative offsets. * * @param document * the document that contains the text content. Cannot be * {@code null}. * @param region * the text region that has to be converted. Cannot be * {@code null}. * @param kind * the document highlight kind. Cannot be {@code null}. * * @return * with a new transformed {@link DocumentHighlight document * highlight} instance. */ DocumentHighlight apply(final Document document, final ITextRegion region, final DocumentHighlightKind kind);