Skip to content

Commit b3ec120

Browse files
committed
Add read/write access tags to call hierarchy and find references
Fix issue eclipse-lsp4j#951. Implement LSP specification proposal microsoft/language-server-protocol#2226
1 parent 687d3a4 commit b3ec120

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import org.eclipse.lsp4j.jsonrpc.validation.NonNull
4040
import org.eclipse.lsp4j.jsonrpc.ProtocolDeprecated
4141
import org.eclipse.lsp4j.jsonrpc.ProtocolDraft
4242
import org.eclipse.lsp4j.jsonrpc.ProtocolSince
43+
import java.util.Collections
4344

4445
@JsonRpcData
4546
class DynamicRegistrationCapabilities {
@@ -848,6 +849,17 @@ class SignatureHelpCapabilities extends DynamicRegistrationCapabilities {
848849
*/
849850
@JsonRpcData
850851
class ReferencesCapabilities extends DynamicRegistrationCapabilities {
852+
853+
/**
854+
* <p>Determines whether the client supports and prefers {@link Reference} items instead
855+
* of {@link Location} items. If this value is missing, the server assumes that the
856+
* client accepts Location items as defined in earlier versions of the protocol.</p>
857+
*
858+
* <p>This is an LSP <b>proposal</b>. See <a href="https://github.com/microsoft/language-server-protocol/pull/2226">PR</a></p>
859+
*/
860+
@ProtocolDraft
861+
Boolean referenceItemsSupport;
862+
851863
new() {
852864
}
853865

@@ -1695,6 +1707,16 @@ class TypeHierarchyRegistrationOptions extends AbstractTextDocumentRegistrationA
16951707
@ProtocolSince("3.16.0")
16961708
@JsonRpcData
16971709
class CallHierarchyCapabilities extends DynamicRegistrationCapabilities {
1710+
1711+
/**
1712+
* <p>Determines whether the client supports reference tags. If the value is missing,
1713+
* the server assumes that the client does not support reference tags.</p>
1714+
*
1715+
* <p>This is an LSP <b>proposal</b>. See <a href="https://github.com/microsoft/language-server-protocol/pull/2226">PR</a></p>
1716+
*/
1717+
@ProtocolDraft
1718+
Boolean referenceTagsSupport;
1719+
16981720
new() {
16991721
}
17001722

@@ -5287,6 +5309,42 @@ class Location {
52875309
}
52885310
}
52895311

5312+
/**
5313+
* <p>Represents a reference to a symbol and describes the kind of reference, e.g. read or write access,
5314+
* in addition to its location in a resource.</p>
5315+
*
5316+
* <p>This is an LSP <b>proposal</b>. See <a href="https://github.com/microsoft/language-server-protocol/pull/2226">PR</a></p>
5317+
*/
5318+
@ProtocolDraft
5319+
@JsonRpcData
5320+
class Reference {
5321+
@NonNull
5322+
Location location
5323+
5324+
@NonNull
5325+
List<ReferenceTag> referenceTags
5326+
5327+
new() {
5328+
}
5329+
5330+
new(@NonNull Location location) {
5331+
this(location, Collections.emptyList())
5332+
}
5333+
5334+
new(@NonNull String uri, @NonNull Range range) {
5335+
this(new Location(uri, range), Collections.emptyList())
5336+
}
5337+
5338+
new(@NonNull String uri, @NonNull Range range, @NonNull List<ReferenceTag> referenceTags) {
5339+
this(new Location(uri, range), referenceTags)
5340+
}
5341+
5342+
new(@NonNull Location location, @NonNull List<ReferenceTag> referenceTags) {
5343+
this.location = Preconditions.checkNotNull(location, 'location')
5344+
this.referenceTags = Preconditions.checkNotNull(referenceTags, 'referenceTags')
5345+
}
5346+
}
5347+
52905348
/**
52915349
* Represents a link between a source and a target location.
52925350
*/
@@ -8950,6 +9008,14 @@ class CallHierarchyItem {
89509008
* Tags for this item.
89519009
*/
89529010
List<SymbolTag> tags
9011+
9012+
/**
9013+
* <p>Reference tags for this item.</p>
9014+
*
9015+
* <p>This is an LSP <b>proposal</b>. See <a href="https://github.com/microsoft/language-server-protocol/pull/2226">PR</a></p>
9016+
*/
9017+
@ProtocolDraft
9018+
List<ReferenceTag> referenceTags
89539019

89549020
/**
89559021
* The resource identifier of this item.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/******************************************************************************
2+
* Copyright (c) 2026 Advantest Europe GmbH and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
******************************************************************************/
12+
13+
package org.eclipse.lsp4j;
14+
15+
import org.eclipse.lsp4j.jsonrpc.ProtocolDraft;
16+
17+
18+
/**
19+
* <p>Reference tags represent additional details in CallHierarchyItems and References to adapt their rendering.</p>
20+
*
21+
* <p>This is an LSP <b>proposal</b>. See <a href="https://github.com/microsoft/language-server-protocol/pull/2226">PR</a></p>
22+
*/
23+
@ProtocolDraft
24+
public enum ReferenceTag {
25+
26+
/**
27+
* Render a CallHierarchyItem or Reference as read access, e.g. in a call hierarchy.
28+
*/
29+
Read(1),
30+
31+
/**
32+
* Render a CallHierarchyItem or Reference as write access, e.g. in a call hierarchy.
33+
*/
34+
Write(2);
35+
36+
37+
private final int value;
38+
39+
ReferenceTag(int value) {
40+
this.value = value;
41+
}
42+
43+
public int getValue() {
44+
return value;
45+
}
46+
47+
public static ReferenceTag forValue(int value) {
48+
ReferenceTag[] allValues = ReferenceTag.values();
49+
if (value < 1 || value > allValues.length)
50+
throw new IllegalArgumentException("Illegal enum value: " + value);
51+
return allValues[value - 1];
52+
}
53+
}

org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/services/TextDocumentService.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import org.eclipse.lsp4j.PrepareRenameParams;
7474
import org.eclipse.lsp4j.PrepareRenameResult;
7575
import org.eclipse.lsp4j.Range;
76+
import org.eclipse.lsp4j.Reference;
7677
import org.eclipse.lsp4j.ReferenceParams;
7778
import org.eclipse.lsp4j.RenameParams;
7879
import org.eclipse.lsp4j.SelectionRange;
@@ -220,6 +221,22 @@ default CompletableFuture<Either<List<? extends Location>, List<? extends Locati
220221
default CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
221222
throw new UnsupportedOperationException();
222223
}
224+
225+
/**
226+
* <p>The references request is sent from the client to the server to resolve
227+
* project-wide references for the symbol denoted by the given text document
228+
* position.</p>
229+
*
230+
* Registration Options: {@link org.eclipse.lsp4j.ReferenceRegistrationOptions}
231+
*
232+
* <p>This is an LSP <b>proposal</b>. See <a href="https://github.com/microsoft/language-server-protocol/pull/2226">PR</a>
233+
* This method is planned to replace {@link #references(ReferenceParams)} and could be renamed to 'references' in future.</p>
234+
*/
235+
// TODO introduce this new method (avoid a breaking change) or replace #references(ReferenceParams)?
236+
@JsonRequest
237+
default CompletableFuture<Either<List<Location>,List<Reference>>> referencesWithTags(ReferenceParams params) {
238+
throw new UnsupportedOperationException();
239+
}
223240

224241
/**
225242
* The document highlight request is sent from the client to the server to

0 commit comments

Comments
 (0)