You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/06/02 10:02:38 UTC

[GitHub] [netbeans] sdedic commented on a diff in pull request #4187: LSP: Open type command added.

sdedic commented on code in PR #4187:
URL: https://github.com/apache/netbeans/pull/4187#discussion_r887784512


##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/QuickOpen.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.lsp.server.protocol;
+
+import com.google.gson.Gson;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import javax.lang.model.element.TypeElement;
+import org.eclipse.lsp4j.CodeAction;
+import org.eclipse.lsp4j.CodeActionParams;
+import org.eclipse.lsp4j.MessageParams;
+import org.eclipse.lsp4j.MessageType;
+import org.eclipse.lsp4j.Position;
+import org.eclipse.lsp4j.Range;
+import org.eclipse.lsp4j.ShowDocumentParams;
+import org.netbeans.api.java.project.JavaProjectConstants;
+import org.netbeans.api.java.source.ClassIndex;
+import org.netbeans.api.java.source.ClasspathInfo;
+import org.netbeans.api.java.source.ElementHandle;
+import org.netbeans.api.java.source.ui.ElementOpen;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectUtils;
+import org.netbeans.api.project.SourceGroup;
+import org.netbeans.modules.java.lsp.server.LspServerState;
+import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.parsing.api.ResultIterator;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.URLMapper;
+import org.openide.util.Lookup;
+import org.openide.util.NbBundle;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author Dusan Balek
+ */
+@ServiceProvider(service = CodeActionsProvider.class)
+public class QuickOpen extends CodeActionsProvider {
+
+    public static final String QUICK_OPEN =  "java.quick.open"; // NOI18N
+    public static final String DEFAULT_PKG =  "<default package>"; // NOI18N
+    private final Gson gson = new Gson();
+
+    @Override
+    public Set<String> getCommands() {
+        return Collections.singleton(QUICK_OPEN);
+    }
+
+    @NbBundle.Messages({
+        "DN_SelectType=Select type to open",
+        "DN_NoTypeFound=No type found in openend projects"
+    })
+    @Override
+    public CompletableFuture<Object> processCommand(NbCodeLanguageClient client, String command, List<Object> arguments) {
+        LspServerState server = Lookup.getDefault().lookup(LspServerState.class);
+        if (server != null) {
+            return server.openedProjects().thenCompose(prjs -> {
+                ArrayList<QuickPickItem> items = new ArrayList<>();
+                for (Project prj : prjs) {
+                    for (SourceGroup sg : ProjectUtils.getSources(prj).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
+                        FileObject root = sg.getRootFolder();
+                        for (ElementHandle<TypeElement> type : ClasspathInfo.create(root).getClassIndex().getDeclaredTypes("", ClassIndex.NameKind.PREFIX, EnumSet.of(ClassIndex.SearchScope.SOURCE))) {
+                            String qualifiedName = type.getQualifiedName();
+                            int idx = qualifiedName.lastIndexOf('.');
+                            String name = idx < 0 ? qualifiedName : qualifiedName.substring(idx + 1);
+                            String pkgName = idx < 0 ? DEFAULT_PKG : qualifiedName.substring(0, idx);
+                            items.add(new QuickPickItem(name, pkgName + " : " + root.toURI().toString(), null, false, new ElementData(type)));

Review Comment:
   Wow, this will be performance - marvellous for transfer & client processing in projects like Micronaut :)) but we can only use the UI that  Microsoft has allowed for us.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists