jlahoda commented on a change in pull request #2324:
URL: https://github.com/apache/netbeans/pull/2324#discussion_r489166021



##########
File path: 
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/workspace/WorkspaceServiceImpl.java
##########
@@ -18,23 +18,215 @@
  */
 package org.netbeans.modules.java.lsp.server.workspace;
 
+import com.sun.source.util.TreePath;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.TypeElement;
 import org.eclipse.lsp4j.DidChangeConfigurationParams;
 import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
+import org.eclipse.lsp4j.Location;
 import org.eclipse.lsp4j.SymbolInformation;
 import org.eclipse.lsp4j.WorkspaceSymbolParams;
 import org.eclipse.lsp4j.services.WorkspaceService;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.annotations.common.NullAllowed;
+import org.netbeans.api.java.source.ClasspathInfo;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.api.java.source.ElementHandle;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.java.source.JavaSource.Phase;
+import org.netbeans.api.java.source.SourceUtils;
+import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider;
+import org.netbeans.modules.java.source.ui.JavaSymbolProvider.ResultHandler;
+import org.netbeans.modules.java.source.usages.ClassIndexImpl;
+import org.netbeans.modules.parsing.lucene.support.Queries;
+import org.netbeans.spi.jumpto.type.SearchType;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Pair;
+import org.openide.util.RequestProcessor;
 
 /**
  *
  * @author lahvac
  */
 public class WorkspaceServiceImpl implements WorkspaceService {
 
+    private static final RequestProcessor WORKER = new 
RequestProcessor(WorkspaceServiceImpl.class.getName(), 1, false, false);
+
     @Override
-    public CompletableFuture<List<? extends SymbolInformation>> 
symbol(WorkspaceSymbolParams arg0) {
-        throw new UnsupportedOperationException("Not supported yet.");
+    public CompletableFuture<List<? extends SymbolInformation>> 
symbol(WorkspaceSymbolParams params) {
+        String query = params.getQuery();
+        if (query.isEmpty()) {
+            //cannot query "all":
+            return CompletableFuture.completedFuture(Collections.emptyList());
+        }
+        System.err.println("query=" + query);
+        boolean exact = false;
+        if (query.endsWith(" ")) {
+            query = query.substring(0, query.length() - 1);
+            exact = true;
+        }
+        String queryFin = query;
+        boolean exactFin = exact;
+        AtomicBoolean cancel = new AtomicBoolean();
+        CompletableFuture<List<? extends SymbolInformation>> result = new 
CompletableFuture<List<? extends SymbolInformation>>() {
+            @Override
+            public boolean cancel(boolean mayInterruptIfRunning) {
+                cancel.set(mayInterruptIfRunning);
+                return super.cancel(mayInterruptIfRunning);
+            }
+        };
+        WORKER.post(() -> {
+            try {
+                List<SymbolInformation> symbols = new ArrayList<>();
+                ResultHandler handler = new ResultHandler() {
+                    @Override
+                    public void setHighlightText(String text) {
+                    }
+
+                    private Map<ElementHandle<TypeElement>, List<String>> 
type2Idents;
+
+                    @Override
+                    public void runRoot(FileObject root, ClassIndexImpl ci, 
Exec exec) throws IOException, InterruptedException {
+                        ClasspathInfo cpInfo = ClasspathInfo.create(root);
+                        try {
+                            type2Idents = new HashMap<>();
+                            exec.run();
+                            Map<FileObject, Map<ElementHandle<TypeElement>, 
List<String>>> sources = new HashMap<>();
+                            for (Entry<ElementHandle<TypeElement>, 
List<String>> e : type2Idents.entrySet()) {
+                                FileObject sourceFile = 
SourceUtils.getFile(e.getKey(), cpInfo);
+                                sources.computeIfAbsent(sourceFile, s -> new 
HashMap<>())
+                                       .put(e.getKey(), e.getValue());
+                            }
+                            if (!sources.isEmpty()) {
+                                JavaSource.create(cpInfo, sources.keySet())
+                                          .runUserActionTask(cc -> {
+                                              if 
(Phase.ELEMENTS_RESOLVED.compareTo(cc.toPhase(Phase.ELEMENTS_RESOLVED))> 0) {
+                                                  return ;
+                                              }
+                                              for 
(Entry<ElementHandle<TypeElement>, List<String>> e : 
sources.get(cc.getFileObject()).entrySet()) {
+                                                  TypeElement te = 
e.getKey().resolve(cc);
+
+                                                  for (String ident : 
e.getValue()) {

Review comment:
       Could, but no.




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to