JaroslavTulach commented on a change in pull request #3525:
URL: https://github.com/apache/netbeans/pull/3525#discussion_r794659709



##########
File path: ide/api.lsp/src/org/netbeans/api/lsp/StructureElement.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.api.lsp;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * StructureElement is a tree item that shows the structure of the source code.
+ * 
+ * @author Petr Pisl
+ * @since 1.8
+ */
+public interface StructureElement {
+   
+    /**
+     * Kind of the structure element. 
+     */
+    public static enum Kind {
+        File,
+       Module,

Review comment:
       Strange formatting. Space vs. tab? Using 8 spaces would be more 
consistent.

##########
File path: ide/api.lsp/src/org/netbeans/spi/lsp/StructureProvider.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.spi.lsp;
+
+import org.netbeans.api.lsp.StructureElement;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import javax.swing.text.Document;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.spi.editor.mimelookup.MimeLocation;
+
+/**
+ * Interface for building structure of symbols at a given document.
+ * Implementations of the interface should be registered in MimeLookup.
+ * <pre>
+ *
+ *  {@code @MimeRegistration(mimeType = "text/foo", service = 
StructureProvider.class)
+ *   public class FooStructureProvider implements StructureProvider {
+ *     ...
+ *   }
+ *  }
+ * </pre>
+ *
+ * @author Petr Pisl
+ * @since 1.8
+ */
+
+//@MimeLocation(subfolderName = "StructureProviders")
+public interface StructureProvider {
+    
+    /**
+     * Resolves a structure tree of symbols at the given document.
+     *
+     * @param doc document on which to operate.
+     * @return a list of top level structure elements
+     * 
+     * @since 1.8
+     */
+    @NonNull
+    CompletableFuture<List<? extends StructureElement>> getStructure(@NonNull 
Document doc);

Review comment:
       You need a builder like 
[CompletionCollector.Builder](https://bits.netbeans.org/dev/javadoc/org-netbeans-api-lsp/org/netbeans/spi/lsp/CompletionCollector.Builder.html).

##########
File path: ide/api.lsp/src/org/netbeans/api/lsp/StructureElement.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.api.lsp;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * StructureElement is a tree item that shows the structure of the source code.
+ * 
+ * @author Petr Pisl
+ * @since 1.8
+ */
+public interface StructureElement {

Review comment:
       How do you want to evolve this type? You may need to add new getters in 
the future.
   
   I't be better to follow the pattern of 
[Completion](https://bits.netbeans.org/dev/javadoc/org-netbeans-api-lsp/org/netbeans/api/lsp/Completion.html)
 in API and 
   
[CompletionCollector](https://bits.netbeans.org/dev/javadoc/org-netbeans-api-lsp/org/netbeans/spi/lsp/CompletionCollector.html)
 in SPI.
   
   Turn `StructureElement` into `final class`.

##########
File path: 
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
##########
@@ -813,97 +814,61 @@ protected void process(CompilationInfo arg0, Document 
arg1, SchedulerEvent arg2)
     @Override
     public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> 
documentSymbol(DocumentSymbolParams params) {
         return server.openedProjects().thenCompose(projects -> {
-            JavaSource js = getJavaSource(params.getTextDocument().getUri());
-            if (js == null) {
+            List<Either<SymbolInformation, DocumentSymbol>> result = new 
ArrayList<>();
+        
+            String uri = params.getTextDocument().getUri();
+            FileObject file = fromURI(uri);
+            Document doc = server.getOpenedDocuments().getDocument(uri);
+            if (file == null || !(doc instanceof LineDocument)) {
                 return 
CompletableFuture.completedFuture(Collections.emptyList());
             }
-            List<Either<SymbolInformation, DocumentSymbol>> result = new 
ArrayList<>();
-            try {
-                js.runUserActionTask(cc -> {

Review comment:
       Removing this special Java code is a great step at the right direction. 
Thanks.




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

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