Skip to content

Commit

Permalink
XML custom client commands
Browse files Browse the repository at this point in the history
  • Loading branch information
azerr committed Nov 7, 2022
1 parent f002ea8 commit 1351aed
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
3 changes: 2 additions & 1 deletion org.eclipse.wildwebdeveloper.xml/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Require-Bundle: org.eclipse.tm4e.registry;bundle-version="0.3.0",
org.eclipse.core.net;bundle-version="1.3.0",
org.eclipse.lsp4j.jsonrpc,
org.eclipse.text,
org.eclipse.jface.text;bundle-version="3.20.100"
org.eclipse.jface.text;bundle-version="3.20.100",
org.eclipse.ui.workbench.texteditor;bundle-version="3.16.600"
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.eclipse.wildwebdeveloper.xml.internal.Activator
Export-Package: org.eclipse.wildwebdeveloper.xml;x-friends:="org.eclipse.m2e.editor.lemminx"
13 changes: 13 additions & 0 deletions org.eclipse.wildwebdeveloper.xml/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,17 @@
class="org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceInitializer">
</initializer>
</extension>

<extension
point="org.eclipse.ui.handlers">
<handler
class="org.eclipse.wildwebdeveloper.xml.internal.commands.OpenUriHandler"
commandId="xml.open.uri">
</handler>
<handler
class="org.eclipse.wildwebdeveloper.xml.internal.commands.FindReferencesHandler"
commandId="xml.show.references">
</handler>
</extension>

</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -160,7 +161,24 @@ public String toString() {

@Override
public Object getInitializationOptions(URI rootUri) {
return mergeCustomInitializationOptions(extensionJarRegistry.getInitiatizationOptions());
Map<String, Object> initializationOptions = new HashMap<>();
Map<String, Object> settings = mergeCustomInitializationOptions(
extensionJarRegistry.getInitiatizationOptions());
initializationOptions.put(SETTINGS_KEY, settings.get(SETTINGS_KEY));
Object extendedClientCapabilities = createExtendedClientCapabilities();
initializationOptions.put("extendedClientCapabilities", extendedClientCapabilities);
return initializationOptions;
}

private Object createExtendedClientCapabilities() {
Map<String, Object> extendedClientCapabilities = new HashMap<>();
Map<String, Object> codeLens = new HashMap<>();
extendedClientCapabilities.put("codeLens", codeLens);
Map<String, Object> codeLensKind = new HashMap<>();
codeLens.put("codeLensKind", codeLensKind);
List<String> valueSet = Arrays.asList("references", "open.uri");
codeLensKind.put("valueSet", valueSet);
return extendedClientCapabilities;
}

private static Map<String, Object> mergeCustomInitializationOptions(Map<String, Object> defaults) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.eclipse.wildwebdeveloper.xml.internal.commands;

import java.util.Map;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.lsp4e.LSPEclipseUtils;
import org.eclipse.lsp4e.command.LSPCommandHandler;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.Position;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.wildwebdeveloper.xml.internal.Activator;

public class FindReferencesHandler extends LSPCommandHandler {

@Override
public Object execute(ExecutionEvent event, Command command, IPath path) throws ExecutionException {
IEditorPart part = HandlerUtil.getActiveEditor(event);
if (part instanceof ITextEditor editor) {
IDocument document = LSPEclipseUtils.getDocument(editor);
if (document == null) {
return null;
}
try {
Map<String, Object> position = (Map<String, Object>) command.getArguments().get(1);
int line = ((Number) position.get("line")).intValue();
int character = ((Number) position.get("character")).intValue();
int offset = LSPEclipseUtils.toOffset(new Position(line, character), document);
LSPEclipseUtils.searchLSPReferences(document, offset, HandlerUtil.getActiveShell(event).getDisplay());
} catch (BadLocationException e) {
Activator.getDefault().getLog().error("Error while getting offset for references", e);
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.eclipse.wildwebdeveloper.xml.internal.commands;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.lsp4e.command.LSPCommandHandler;
import org.eclipse.lsp4j.Command;

public class OpenUriHandler extends LSPCommandHandler {

@Override
public Object execute(ExecutionEvent event, Command command, IPath path) throws ExecutionException {
// TODO Auto-generated method stub
return null;
}

}

0 comments on commit 1351aed

Please sign in to comment.