Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move findReferences in LSPEclipseUtils #282

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions org.eclipse.lsp4e/src/org/eclipse/lsp4e/LSPEclipseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.eclipse.jface.text.RewriteSessionEditProcessor;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.lsp4e.operations.references.LSSearchQuery;
import org.eclipse.lsp4e.refactoring.CreateFileChange;
import org.eclipse.lsp4e.refactoring.DeleteExternalFile;
import org.eclipse.lsp4e.refactoring.LSPTextChange;
Expand Down Expand Up @@ -99,15 +100,18 @@
import org.eclipse.lsp4j.WorkspaceEdit;
import org.eclipse.lsp4j.WorkspaceFolder;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.DocumentChange;
import org.eclipse.ltk.core.refactoring.PerformChangeOperation;
import org.eclipse.ltk.core.refactoring.RefactoringCore;
import org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange;
import org.eclipse.mylyn.wikitext.markdown.MarkdownLanguage;
import org.eclipse.mylyn.wikitext.parser.MarkupParser;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.RGBA;
import org.eclipse.swt.widgets.Display;
import org.eclipse.text.edits.MalformedTreeException;
import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.ReplaceEdit;
Expand Down Expand Up @@ -1132,4 +1136,32 @@ public static boolean hasCapability(Either<Boolean, ? extends Object> eitherCapa
}
}

/**
* Execute Eclipse Search UI to search LSP references from the given document and
* offset.
*
* @param document
* the document.
* @param offset
* the offset.
* @param display
* the display to use to execute the search.
*/
public static void searchLSPReferences(@NonNull IDocument document, int offset, Display display) {
LanguageServiceAccessor
.getLanguageServers(document,
capabilities -> hasCapability(capabilities.getReferencesProvider())) //
.thenAcceptAsync(languageServers -> {
if (languageServers.isEmpty()) {
return;
}
LanguageServer ls = languageServers.get(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize you are just moving the code, but is the general pattern not to loop over all LSs, why take here just the first one?

try {
LSSearchQuery query = new LSSearchQuery(document, offset, ls);
display.asyncExec(() -> NewSearchUI.runQueryInBackground(query));
} catch (BadLocationException e) {
LanguageServerPlugin.logError(e);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.lsp4e.LSPEclipseUtils;
import org.eclipse.lsp4e.LanguageServerPlugin;
import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4e.ui.UI;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.texteditor.ITextEditor;
Expand All @@ -51,18 +48,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection sel = editor.getSelectionProvider().getSelection();
if (sel instanceof ITextSelection textSelection) {
int offset = ((ITextSelection) sel).getOffset();
LanguageServiceAccessor.getLanguageServers(document, capabilities -> LSPEclipseUtils.hasCapability(capabilities.getReferencesProvider())).thenAcceptAsync(languageServers -> {
if (languageServers.isEmpty()) {
return;
}
LanguageServer ls = languageServers.get(0);
try {
LSSearchQuery query = new LSSearchQuery(document, offset, ls);
HandlerUtil.getActiveShell(event).getDisplay().asyncExec(() -> NewSearchUI.runQueryInBackground(query));
} catch (BadLocationException e) {
LanguageServerPlugin.logError(e);
}
});
LSPEclipseUtils.searchLSPReferences(document, offset, HandlerUtil.getActiveShell(event).getDisplay());
}
}
return null;
Expand Down