You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by vi...@apache.org on 2022/05/10 13:32:42 UTC

[netbeans] branch master updated: lsp.client honors mime-type fonts and colors. Let the lsp.client module acknoledge whatever font-colors have been registered for a given mimme-type. As a performance plus, the lookup of FontsAndColors is moved out of the loop over the tokens.getData() list.

This is an automated email from the ASF dual-hosted git repository.

vieiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new e647625f73 lsp.client honors mime-type fonts and colors. Let the lsp.client module acknoledge whatever font-colors have been registered for a given mimme-type. As a performance plus, the lookup of FontsAndColors is moved out of the loop over the tokens.getData() list.
     new 793a135e98 Merge pull request #4057 from vieiro/feature/lsp-coloring-threading
e647625f73 is described below

commit e647625f735c267f69622db7ff8011ede351900e
Author: Antonio Vieiro <vi...@apache.org>
AuthorDate: Sat Apr 30 19:15:36 2022 +0200

    lsp.client honors mime-type fonts and colors.
    Let the lsp.client module acknoledge whatever font-colors have been registered for a given mimme-type.
    As a performance plus, the lookup of FontsAndColors is moved out of the loop over the tokens.getData() list.
---
 .../lsp/client/bindings/SemanticHighlight.java     | 28 +++++++++++++++-------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/SemanticHighlight.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/SemanticHighlight.java
index d63113f201..a121a1e1bf 100644
--- a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/SemanticHighlight.java
+++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/SemanticHighlight.java
@@ -25,6 +25,8 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import javax.swing.text.AttributeSet;
 import javax.swing.text.Document;
 import javax.swing.text.JTextComponent;
@@ -46,6 +48,7 @@ import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
 import org.netbeans.spi.editor.highlighting.ZOrder;
 import org.netbeans.spi.editor.highlighting.support.OffsetsBag;
 import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
 import org.openide.util.Exceptions;
 
 /**
@@ -54,6 +57,8 @@ import org.openide.util.Exceptions;
  */
 public class SemanticHighlight implements BackgroundTask {
 
+    private static final Logger LOG = Logger.getLogger(SemanticHighlight.class.getName());
+
     private final Document doc;
 
     public SemanticHighlight(JTextComponent c) {
@@ -71,6 +76,13 @@ public class SemanticHighlight implements BackgroundTask {
             SemanticTokensParams params = new SemanticTokensParams(new TextDocumentIdentifier(Utils.toURI(file)));
             SemanticTokens tokens = bindings.getTextDocumentService().semanticTokensFull(params).get();
             List<Integer> data = tokens.getData();
+            String mimeType = FileUtil.getMIMEType(file);
+            // Find mime-type specific FontColorSettings ...
+            FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
+            if (fcs == null) {
+                // ... or fall-back to "text/textmate" FontColorSettings...
+                fcs = MimeLookup.getLookup("text/textmate").lookup(FontColorSettings.class);
+            }
             int lastLine = 0;
             int lastColumn = 0;
             int offset = 0;
@@ -88,7 +100,7 @@ public class SemanticHighlight implements BackgroundTask {
                 if (data.get(i + 2).intValue() <= 0) {
                     continue; //XXX!
                 }
-                AttributeSet tokenHighlight = tokenHighlight(bindings, data.get(i + 3).intValue(), data.get(i + 4).intValue());
+                AttributeSet tokenHighlight = fcs == null ? EMPTY : tokenHighlight(bindings, fcs, data.get(i + 3).intValue(), data.get(i + 4).intValue());
                 target.addHighlight(offset, offset + data.get(i + 2).intValue(), tokenHighlight);
             }
             getBag(doc).setHighlights(target);
@@ -99,7 +111,8 @@ public class SemanticHighlight implements BackgroundTask {
 
     private final Map<Integer, Map<Integer, AttributeSet>> tokenId2Highlight = new HashMap<>();
 
-    private AttributeSet tokenHighlight(LSPBindings bindings, int tokenId, int modifiers) {
+    private AttributeSet tokenHighlight(final LSPBindings bindings, final FontColorSettings fcs, int tokenId, int modifiers) {
+        assert fcs != null;
         return tokenId2Highlight.computeIfAbsent(tokenId, s -> new HashMap<>())
                                 .computeIfAbsent(modifiers, mods -> {
             SemanticTokensLegend legend = bindings.getInitResult().getCapabilities().getSemanticTokensProvider().getLegend();
@@ -120,15 +133,12 @@ public class SemanticHighlight implements BackgroundTask {
                 }
                 mods &= ~mod;
             }
-            FontColorSettings fcs = MimeLookup.getLookup("text/textmate").lookup(FontColorSettings.class);
 
-            if (fcs == null) {
-                return EMPTY;
+            String colorSet = "mod-" + tokenName + (isDeclaration ? "-declaration" : "");
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.log(Level.FINE, "LSP Semantic coloring. token kind: {0}", colorSet);
             }
-
-            assert fcs != null;
-
-            AttributeSet colors = fcs.getTokenFontColors("mod-" + tokenName + (isDeclaration ? "-declaration" : ""));
+            AttributeSet colors = fcs.getTokenFontColors(colorSet);
             AttributeSet statik = isStatic ? fcs.getTokenFontColors("mod-static") : null;
 
             if (colors != null && statik != null) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

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