org.eclipse.lsp4j.ReferenceContext Java Examples
The following examples show how to use
org.eclipse.lsp4j.ReferenceContext.
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: AbstractReferenceParticipant.java From lemminx with Eclipse Public License 2.0 | 6 votes |
@Override public void findReference(DOMDocument document, Position position, ReferenceContext context, List<Location> locations, CancelChecker cancelChecker) { if (!match(document)) { return; } try { int offset = document.offsetAt(position); DOMNode node = document.findNodeAt(offset); if (node != null) { findReferences(node, position, offset, context, locations, cancelChecker); } } catch (BadLocationException e) { } }
Example #2
Source File: XMLAssert.java From lemminx with Eclipse Public License 2.0 | 6 votes |
public static void testReferencesFor(String value, String fileURI, Location... expected) throws BadLocationException { int offset = value.indexOf('|'); value = value.substring(0, offset) + value.substring(offset + 1); TextDocument document = new TextDocument(value, fileURI != null ? fileURI : "test://test/test.xml"); Position position = document.positionAt(offset); XMLLanguageService xmlLanguageService = new XMLLanguageService(); ContentModelSettings settings = new ContentModelSettings(); settings.setUseCache(false); xmlLanguageService.doSave(new SettingsSaveContext(settings)); DOMDocument xmlDocument = DOMParser.getInstance().parse(document, xmlLanguageService.getResolverExtensionManager()); xmlLanguageService.setDocumentProvider((uri) -> xmlDocument); List<? extends Location> actual = xmlLanguageService.findReferences(xmlDocument, position, new ReferenceContext(), () -> { }); assertLocation(actual, expected); }
Example #3
Source File: ReferencesHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testReference(){ URI uri = project.getFile("src/java/Foo2.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); ReferenceParams param = new ReferenceParams(); param.setPosition(new Position(5,16)); param.setContext(new ReferenceContext(true)); param.setTextDocument( new TextDocumentIdentifier(fileURI)); List<Location> references = handler.findReferences(param, monitor); assertNotNull("findReferences should not return null",references); assertEquals(1, references.size()); Location l = references.get(0); String refereeUri = ResourceUtils.fixURI(project.getFile("src/java/Foo3.java").getRawLocationURI()); assertEquals(refereeUri, l.getUri()); }
Example #4
Source File: XMLReference.java From lemminx with Eclipse Public License 2.0 | 5 votes |
public List<? extends Location> findReferences(DOMDocument document, Position position, ReferenceContext context, CancelChecker cancelChecker) { List<Location> locations = new ArrayList<>(); for (IReferenceParticipant participant : extensionsRegistry.getReferenceParticipants()) { participant.findReference(document, position, context, locations, cancelChecker); } return locations; }
Example #5
Source File: DTDReferenceParticipant.java From lemminx with Eclipse Public License 2.0 | 5 votes |
@Override protected void findReferences(DOMNode node, Position position, int offset, ReferenceContext context, List<Location> locations, CancelChecker cancelChecker) { // DTD reference works only when references is done on an <!ELEMENT name if (!node.isDTDElementDecl()) { return; } DTDElementDecl elementDecl = (DTDElementDecl) node; if (!elementDecl.isInNameParameter(offset)) { return; } DTDUtils.searchDTDOriginElementDecls(elementDecl, (origin, target) -> locations.add(XMLPositionUtility.createLocation(origin)), cancelChecker); }
Example #6
Source File: XSDReferenceParticipant.java From lemminx with Eclipse Public License 2.0 | 5 votes |
@Override protected void findReferences(DOMNode node, Position position, int offset, ReferenceContext context, List<Location> locations, CancelChecker cancelChecker) { DOMAttr attr = node.findAttrAt(offset); if (attr != null) { node = attr; } XSDUtils.searchXSOriginAttributes(node, (origin, target) -> locations.add(XMLPositionUtility.createLocation(origin.getNodeAttrValue())), cancelChecker); }
Example #7
Source File: ImplementationsSearchQuery.java From corrosion with Eclipse Public License 2.0 | 5 votes |
@Override public IStatus run(IProgressMonitor monitor) { startTime = System.currentTimeMillis(); // Cancel last references future if needed. if (references != null) { references.cancel(true); } AbstractTextSearchResult textResult = (AbstractTextSearchResult) getSearchResult(); textResult.removeAll(); try { // Execute LSP "references" service ReferenceParams params = new ReferenceParams(); params.setContext(new ReferenceContext(true)); params.setTextDocument(new TextDocumentIdentifier(info.getFileUri().toString())); params.setPosition(position); info.getInitializedLanguageClient().thenCompose(languageServer -> ((RLSServerInterface) languageServer).implementations(params)).thenAccept(locs -> { // Loop for each LSP Location and convert it to Match search. for (Location loc : locs) { Match match = toMatch(loc); result.addMatch(match); } }); return Status.OK_STATUS; } catch (Exception ex) { return new Status(IStatus.ERROR, LanguageServerPlugin.getDefault().getBundle().getSymbolicName(), ex.getMessage(), ex); } }
Example #8
Source File: ReferencesHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testEmpty(){ ReferenceParams param = new ReferenceParams(); param.setPosition(new Position(1, 1)); param.setContext(new ReferenceContext(false)); param.setTextDocument( new TextDocumentIdentifier("/foo/bar")); List<Location> references = handler.findReferences(param, monitor); assertNotNull(references); assertTrue("references are not empty", references.isEmpty()); }
Example #9
Source File: XMLLanguageService.java From lemminx with Eclipse Public License 2.0 | 4 votes |
public List<? extends Location> findReferences(DOMDocument xmlDocument, Position position, ReferenceContext context, CancelChecker cancelChecker) { return reference.findReferences(xmlDocument, position, context, cancelChecker); }
Example #10
Source File: ReferenceParams.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
public ReferenceParams(@NonNull final TextDocumentIdentifier textDocument, @NonNull final Position position, @NonNull final ReferenceContext context) { super(textDocument, position); this.context = Preconditions.<ReferenceContext>checkNotNull(context, "context"); }
Example #11
Source File: ReferenceParams.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
@Deprecated public ReferenceParams(@NonNull final ReferenceContext context) { this.context = Preconditions.<ReferenceContext>checkNotNull(context, "context"); }
Example #12
Source File: ReferenceParams.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
@Pure @NonNull public ReferenceContext getContext() { return this.context; }
Example #13
Source File: ReferenceParams.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
public void setContext(@NonNull final ReferenceContext context) { this.context = Preconditions.checkNotNull(context, "context"); }
Example #14
Source File: AbstractReferenceParticipant.java From lemminx with Eclipse Public License 2.0 | 2 votes |
/** * Find the references * * @param node * @param position * @param offset * @param locations * @param cancelChecker */ protected abstract void findReferences(DOMNode node, Position position, int offset, ReferenceContext context, List<Location> locations, CancelChecker cancelChecker);
Example #15
Source File: IReferenceParticipant.java From lemminx with Eclipse Public License 2.0 | votes |
void findReference(DOMDocument document, Position position, ReferenceContext context, List<Location> locations, CancelChecker cancelChecker);