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 2020/10/11 21:07:05 UTC

[GitHub] [netbeans] jlahoda opened a new pull request #2445: Adding breadcrumbs for LSP languages.

jlahoda opened a new pull request #2445:
URL: https://github.com/apache/netbeans/pull/2445


   (This is an LSP-only client change.)
   


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


[GitHub] [netbeans] lkishalmi merged pull request #2445: Adding breadcrumbs for LSP languages.

Posted by GitBox <gi...@apache.org>.
lkishalmi merged pull request #2445:
URL: https://github.com/apache/netbeans/pull/2445


   


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


[GitHub] [netbeans] matthiasblaesing commented on a change in pull request #2445: Adding breadcrumbs for LSP languages.

Posted by GitBox <gi...@apache.org>.
matthiasblaesing commented on a change in pull request #2445:
URL: https://github.com/apache/netbeans/pull/2445#discussion_r504927165



##########
File path: ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/BreadcrumbsImpl.java
##########
@@ -0,0 +1,368 @@
+/*
+ * 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.lsp.client.bindings;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Image;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.CharConversionException;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import javax.swing.text.Position;
+import org.eclipse.lsp4j.DocumentSymbol;
+import org.eclipse.lsp4j.DocumentSymbolParams;
+import org.eclipse.lsp4j.SymbolInformation;
+import org.eclipse.lsp4j.TextDocumentIdentifier;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
+import org.netbeans.api.actions.Openable;
+import org.netbeans.editor.SideBarFactory;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.editor.breadcrumbs.spi.BreadcrumbsController;
+import org.netbeans.modules.editor.breadcrumbs.spi.BreadcrumbsElement;
+import org.netbeans.modules.lsp.client.LSPBindings;
+import org.netbeans.modules.lsp.client.LSPBindings.BackgroundTask;
+import org.netbeans.modules.lsp.client.Utils;
+import org.openide.filesystems.FileObject;
+import org.openide.loaders.DataObject;
+import org.openide.loaders.DataObjectNotFoundException;
+import org.openide.util.Exceptions;
+import org.openide.util.ImageUtilities;
+import org.openide.util.Lookup;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.Lookups;
+import org.openide.xml.XMLUtil;
+
+/**
+ *
+ * @author lahvac
+ */
+public class BreadcrumbsImpl implements BackgroundTask {
+
+    private static final RequestProcessor WORKER = new RequestProcessor(BreadcrumbsImpl.class.getName(), 1, false, false);
+    private final JTextComponent comp;
+    private final Document doc;
+    private RootBreadcrumbsElementImpl rootElement;
+
+    public BreadcrumbsImpl(JTextComponent comp) {
+        this.comp = comp;
+        this.doc = comp.getDocument();
+        this.comp.addCaretListener(evt -> {
+            update();
+        });
+    }
+
+    @Override
+    public void run(LSPBindings bindings, FileObject file) {
+        try {
+            //TODO: modified while the query is running?
+            List<Either<SymbolInformation, DocumentSymbol>> symbols = bindings.getTextDocumentService().documentSymbol(new DocumentSymbolParams(new TextDocumentIdentifier(Utils.toURI(file)))).get();
+
+            synchronized (this) {
+                this.rootElement = new RootBreadcrumbsElementImpl(file, doc, symbols.stream().map(this::toDocumentSymbol).collect(Collectors.toList()));
+            }
+
+            SwingUtilities.invokeLater(() -> update());
+        } catch (InterruptedException | ExecutionException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+    }
+
+    private DocumentSymbol toDocumentSymbol(Either<SymbolInformation, DocumentSymbol> variants) {
+        if (variants.isRight()) return variants.getRight();
+
+        SymbolInformation left = variants.getLeft();
+
+        return new DocumentSymbol(left.getName(), left.getKind(), left.getLocation().getRange(), left.getLocation().getRange(), null, Collections.emptyList());

Review comment:
       I would use the shorter constructor, that does not require specifying the last two arguments.

##########
File path: ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/BreadcrumbsImpl.java
##########
@@ -0,0 +1,368 @@
+/*
+ * 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.lsp.client.bindings;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Image;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.CharConversionException;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import javax.swing.text.Position;
+import org.eclipse.lsp4j.DocumentSymbol;
+import org.eclipse.lsp4j.DocumentSymbolParams;
+import org.eclipse.lsp4j.SymbolInformation;
+import org.eclipse.lsp4j.TextDocumentIdentifier;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
+import org.netbeans.api.actions.Openable;
+import org.netbeans.editor.SideBarFactory;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.editor.breadcrumbs.spi.BreadcrumbsController;
+import org.netbeans.modules.editor.breadcrumbs.spi.BreadcrumbsElement;
+import org.netbeans.modules.lsp.client.LSPBindings;
+import org.netbeans.modules.lsp.client.LSPBindings.BackgroundTask;
+import org.netbeans.modules.lsp.client.Utils;
+import org.openide.filesystems.FileObject;
+import org.openide.loaders.DataObject;
+import org.openide.loaders.DataObjectNotFoundException;
+import org.openide.util.Exceptions;
+import org.openide.util.ImageUtilities;
+import org.openide.util.Lookup;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.Lookups;
+import org.openide.xml.XMLUtil;
+
+/**
+ *
+ * @author lahvac
+ */
+public class BreadcrumbsImpl implements BackgroundTask {
+
+    private static final RequestProcessor WORKER = new RequestProcessor(BreadcrumbsImpl.class.getName(), 1, false, false);
+    private final JTextComponent comp;
+    private final Document doc;
+    private RootBreadcrumbsElementImpl rootElement;
+
+    public BreadcrumbsImpl(JTextComponent comp) {
+        this.comp = comp;
+        this.doc = comp.getDocument();
+        this.comp.addCaretListener(evt -> {
+            update();
+        });
+    }
+
+    @Override
+    public void run(LSPBindings bindings, FileObject file) {
+        try {
+            //TODO: modified while the query is running?
+            List<Either<SymbolInformation, DocumentSymbol>> symbols = bindings.getTextDocumentService().documentSymbol(new DocumentSymbolParams(new TextDocumentIdentifier(Utils.toURI(file)))).get();
+
+            synchronized (this) {
+                this.rootElement = new RootBreadcrumbsElementImpl(file, doc, symbols.stream().map(this::toDocumentSymbol).collect(Collectors.toList()));
+            }

Review comment:
       I suggest to reflow this to:
   
   ```java
           try {
               //TODO: modified while the query is running?
               List<Either<SymbolInformation, DocumentSymbol>> symbols = bindings
                   .getTextDocumentService()
                   .documentSymbol(
                       new DocumentSymbolParams(
                           new TextDocumentIdentifier(Utils.toURI(file))
                       )
                   )
                   .get();
   
               synchronized (this) {
                   this.rootElement = new RootBreadcrumbsElementImpl(
                       file,
                       doc,
                       symbols.stream().map(this::toDocumentSymbol).collect(Collectors.toList())
                   );
               }
   
               SwingUtilities.invokeLater(() -> update());
           } catch (InterruptedException | ExecutionException ex) {
               Exceptions.printStackTrace(ex);
           }
   ```




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