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 2021/05/24 12:59:28 UTC

[GitHub] [netbeans] sdedic commented on a change in pull request #2971: LSP: Get project source roots, classpath, and packages commands added.

sdedic commented on a change in pull request #2971:
URL: https://github.com/apache/netbeans/pull/2971#discussion_r637925107



##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java
##########
@@ -136,6 +138,81 @@
                 progressOfCompilation.checkStatus();
                 return progressOfCompilation.getFinishFuture();
             }
+            case Server.JAVA_GET_PROJECT_SOURCE_ROOTS: {
+                String uri = ((JsonPrimitive) params.getArguments().get(0)).getAsString();
+                String type = params.getArguments().size() > 1 ? ((JsonPrimitive) params.getArguments().get(1)).getAsString() : JavaProjectConstants.SOURCES_TYPE_JAVA;
+                FileObject file;
+                try {
+                    file = URLMapper.findFileObject(new URL(uri));
+                } catch (MalformedURLException ex) {
+                    Exceptions.printStackTrace(ex);
+                    return CompletableFuture.completedFuture(Collections.emptyList());
+                }
+                if (file == null) {
+                    return CompletableFuture.completedFuture(Collections.emptyList());
+                }
+                return server.asyncOpenFileOwner(file).thenApply(project -> {
+                    List<String> roots = new ArrayList<>();
+                    if (project != null) {
+                        for(SourceGroup sourceGroup : ProjectUtils.getSources(project).getSourceGroups(type)) {
+                            roots.add(Utils.toUri(sourceGroup.getRootFolder()));
+                        }
+                    }
+                    return roots;
+                });
+            }
+            case Server.JAVA_GET_PROJECT_CLASSPATH: {
+                String uri = ((JsonPrimitive) params.getArguments().get(0)).getAsString();
+                ClasspathInfo.PathKind kind = params.getArguments().size() > 1 ? ClasspathInfo.PathKind.valueOf(((JsonPrimitive) params.getArguments().get(1)).getAsString()) : ClasspathInfo.PathKind.COMPILE;
+                FileObject file;
+                try {
+                    file = URLMapper.findFileObject(new URL(uri));
+                } catch (MalformedURLException ex) {
+                    Exceptions.printStackTrace(ex);
+                    return CompletableFuture.completedFuture(Collections.emptyList());
+                }
+                if (file == null) {
+                    return CompletableFuture.completedFuture(Collections.emptyList());
+                }
+                return server.asyncOpenFileOwner(file).thenApply(project -> {
+                    HashSet<FileObject> roots = new HashSet<>();
+                    if (project != null) {
+                        for(SourceGroup sourceGroup : ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
+                            for (FileObject root : ClasspathInfo.create(sourceGroup.getRootFolder()).getClassPath(kind).getRoots()) {
+                                roots.add(root);
+                            }
+                        }
+                    }
+                    return roots.stream().map(fo -> Utils.toUri(fo)).collect(Collectors.toList());
+                });
+            }
+            case Server.JAVA_GET_PROJECT_PACKAGES: {
+                String uri = ((JsonPrimitive) params.getArguments().get(0)).getAsString();

Review comment:
       Nitpick: I have a vague feeling that all three code blocks could be factored out to a common method like
   ```
   CompletableFuture<List<?>> collectFromGroups(String uri, String groupType, Function<SourceGroup, Object>)
   ```
   




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

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