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



##########
File path: 
ide/csl.api/src/org/netbeans/modules/csl/navigation/GsfStructureProvider.java
##########
@@ -0,0 +1,328 @@
+/*
+ * 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.csl.navigation;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.api.editor.document.LineDocument;
+import org.netbeans.api.editor.document.LineDocumentUtils;
+import org.netbeans.modules.csl.api.StructureItem;
+import org.netbeans.modules.csl.api.StructureScanner;
+import org.netbeans.modules.csl.core.Language;
+import org.netbeans.modules.csl.core.LanguageRegistry;
+import org.netbeans.modules.csl.spi.ParserResult;
+import org.netbeans.modules.parsing.api.ParserManager;
+import org.netbeans.modules.parsing.api.ResultIterator;
+import org.netbeans.modules.parsing.api.Source;
+import org.netbeans.modules.parsing.api.UserTask;
+import org.netbeans.modules.parsing.spi.ParseException;
+import org.netbeans.modules.parsing.spi.Parser;
+import org.netbeans.api.lsp.StructureElement;
+import org.netbeans.modules.csl.api.ElementKind;
+import org.netbeans.modules.csl.api.HtmlFormatter;
+import org.netbeans.modules.csl.api.Modifier;
+import org.netbeans.spi.lsp.StructureProvider;
+
+/**
+ * Implementation of StructureProvider to supply outline view in VSCode
+ * @author Petr Pisl
+ */
+public class GsfStructureProvider implements StructureProvider {
+
+    private static final Logger LOGGER = 
Logger.getLogger(GsfStructureProvider.class.getName());
+    
+    /** The structure element implementation. Some properties are counted 
lazy. 
+     * 
+     */
+    private static class GsfStructureElement implements StructureElement {
+        
+        private final static Set<StructureElement.Tag> DEPRECATED_TAG = 
Collections.singleton(StructureElement.Tag.Deprecated);
+        
+        private final Document doc;         // The children are counted lazily 
and we need the document for it. 
+        private final StructureItem origItem;
+        private List<GsfStructureElement> children;
+        private String signature;
+        private int expandedStartOffset;
+        private int expandedEndOffset;
+        
+
+        public GsfStructureElement(Document doc, StructureItem origItem) {
+            this.doc = doc;
+            this.origItem = origItem;
+            this.signature = null;
+            this.children = null;
+            this.expandedStartOffset = (int)origItem.getPosition();
+            this.expandedEndOffset = (int)origItem.getEndPosition();
+        }
+        
+        @Override
+        public String getName() {
+            return origItem.getName();
+        }
+
+        @Override
+        public int getSelectionStartOffset() {
+            return (int)origItem.getPosition();
+        }
+
+        @Override
+        public int getSelectionEndOffset() {
+            return (int)origItem.getEndPosition();
+        }
+        
+        @Override
+        public int getExpandedStartOffset() {
+            return expandedStartOffset;
+        }
+
+        protected void setExpandedStartOffset(int enclosedStartOffset) {
+            this.expandedStartOffset = enclosedStartOffset;
+        }
+
+        @Override
+        public int getExpandedEndOffset() {
+            return expandedEndOffset;
+        }
+        
+        protected void setExpandedEndOffset(int enclosedEndOffset) {
+            this.expandedEndOffset = enclosedEndOffset;
+        }
+
+        
+        @Override
+        public String getDetail() { 
+            if (signature == null) {
+                createSignature();
+            }
+            return signature;
+        }
+
+        private void createSignature() {
+            NoHtmlFormatter formatter = new NoHtmlFormatter();
+            String s = origItem.getHtml(formatter);
+            signature = s.substring(getName().length()).trim();
+        }
+        
+        @Override
+        public StructureElement.Kind getKind() {
+            switch(origItem.getKind()) {
+                case ATTRIBUTE: return Kind.Property;
+                case CALL: return Kind.Event;
+                case CLASS: return Kind.Class;
+                case CONSTANT: return Kind.Constant;
+                case CONSTRUCTOR: return Kind.Constructor;
+                case DB: return Kind.File;
+                case ERROR: return Kind.Event;
+                case METHOD: return Kind.Method;
+                case FILE: return Kind.File;
+                case FIELD: return Kind.Field;
+                case MODULE: return Kind.Module;
+                case VARIABLE: return Kind.Variable;
+                case GLOBAL: return Kind.Module;
+                case INTERFACE: return Kind.Interface;
+                case KEYWORD: return Kind.Key;
+                case OTHER: return Kind.Object;
+                case PACKAGE: return Kind.Package;
+                case PARAMETER: return Kind.TypeParameter;

Review comment:
       It depends on the language.




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