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 09:20:59 UTC

[GitHub] [netbeans] dbalek opened a new pull request, #4187: LSP: Open type command added.

dbalek opened a new pull request, #4187:
URL: https://github.com/apache/netbeans/pull/4187

   Open type command added.
   


-- 
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


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

Posted by GitBox <gi...@apache.org>.
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


[GitHub] [netbeans] dbalek merged pull request #4187: LSP: Open type command added.

Posted by GitBox <gi...@apache.org>.
dbalek merged PR #4187:
URL: https://github.com/apache/netbeans/pull/4187


-- 
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


[GitHub] [netbeans] graemerocher commented on pull request #4187: LSP: Open type command added.

Posted by GitBox <gi...@apache.org>.
graemerocher commented on PR #4187:
URL: https://github.com/apache/netbeans/pull/4187#issuecomment-1144668768

   Can we add a keyboard shortcut? IntelliJ differentiates this with two: CMD+SHIFT+O (open any type) or CMD+O (open types only in current project)


-- 
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


[GitHub] [netbeans] dbalek commented on pull request #4187: LSP: Open type command added.

Posted by GitBox <gi...@apache.org>.
dbalek commented on PR #4187:
URL: https://github.com/apache/netbeans/pull/4187#issuecomment-1147243044

   > Can we add a keyboard shortcut? IntelliJ differentiates this with two: CMD+SHIFT+O (open any type) or CMD+O (open types only in current project)
   I would rather leave the action without an explicitly assigned shortcut. It is more and more difficult to find free reasonable shortcuts similar on Mac, Linux and Win (almost all "nice" shortcuts are taken). It is IMHO better to let user to assign reasonable shortcuts he/she is used to use for these actions than assign the strange shortcuts just because their key combinations are free.
   
   


-- 
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