lh123 created this revision.
lh123 added reviewers: ilya-biryukov, hokein, sammccall.
lh123 added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay.
Herald added a project: clang.

fixes https://github.com/clangd/clangd/issues/176


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70078

Files:
  clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
  
clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts

Index: clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
===================================================================
--- clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
@@ -84,19 +84,24 @@
           return scopeRanges;
         };
 
+    const fileUri1 = vscode.Uri.parse('file:///file1');
+    const fileUri2 = vscode.Uri.parse('file:///file2');
+    const fileUri1Str = fileUri1.toString();
+    const fileUri2Str = fileUri2.toString();
+
     class MockHighlighter extends semanticHighlighting.Highlighter {
       applicationUriHistory: string[] = [];
       // Override to make the highlighting calls accessible to the test. Also
       // makes the test not depend on visible text editors.
-      applyHighlights(fileUri: string) {
-        this.applicationUriHistory.push(fileUri);
+      applyHighlights(fileUri: vscode.Uri) {
+        this.applicationUriHistory.push(fileUri.toString());
       }
       // Override to make it accessible from the test.
-      getDecorationRanges(fileUri: string) {
+      getDecorationRanges(fileUri: vscode.Uri) {
         return super.getDecorationRanges(fileUri);
       }
       // Override to make tests not depend on visible text editors.
-      getVisibleTextEditorUris() { return [ 'file1', 'file2' ]; }
+      getVisibleTextEditorUris() { return [ fileUri1, fileUri2 ]; }
     }
     const highlighter = new MockHighlighter(scopeTable);
     const tm = new semanticHighlighting.ThemeRuleMatcher([
@@ -104,11 +109,11 @@
       {scope : 'entity.type', foreground : '2'},
     ]);
     // Recolorizes when initialized.
-    highlighter.highlight('file1', []);
-    assert.deepEqual(highlighter.applicationUriHistory, [ 'file1' ]);
+    highlighter.highlight(fileUri1, []);
+    assert.deepEqual(highlighter.applicationUriHistory, [ fileUri1Str ]);
     highlighter.initialize(tm);
     assert.deepEqual(highlighter.applicationUriHistory,
-                     [ 'file1', 'file1', 'file2' ]);
+                     [ fileUri1Str, fileUri1Str, fileUri2Str ]);
     // Groups decorations into the scopes used.
     let highlightingsInLine: semanticHighlighting.SemanticHighlightingLine[] = [
       {
@@ -128,10 +133,10 @@
       },
     ];
 
-    highlighter.highlight('file1', highlightingsInLine);
+    highlighter.highlight(fileUri1, highlightingsInLine);
     assert.deepEqual(highlighter.applicationUriHistory,
-                     [ 'file1', 'file1', 'file2', 'file1' ]);
-    assert.deepEqual(highlighter.getDecorationRanges('file1'),
+                     [ fileUri1Str, fileUri1Str, fileUri2Str, fileUri1Str ]);
+    assert.deepEqual(highlighter.getDecorationRanges(fileUri1),
                      createHighlightingScopeRanges(highlightingsInLine));
     // Keeps state separate between files.
     const highlightingsInLine1:
@@ -141,26 +146,29 @@
         {character : 2, length : 1, scopeIndex : 0},
       ]
     };
-    highlighter.highlight('file2', [ highlightingsInLine1 ]);
-    assert.deepEqual(highlighter.applicationUriHistory,
-                     [ 'file1', 'file1', 'file2', 'file1', 'file2' ]);
-    assert.deepEqual(highlighter.getDecorationRanges('file2'),
+    highlighter.highlight(fileUri2, [ highlightingsInLine1 ]);
+    assert.deepEqual(
+        highlighter.applicationUriHistory,
+        [ fileUri1Str, fileUri1Str, fileUri2Str, fileUri1Str, fileUri2Str ]);
+    assert.deepEqual(highlighter.getDecorationRanges(fileUri2),
                      createHighlightingScopeRanges([ highlightingsInLine1 ]));
     // Does full colorizations.
-    highlighter.highlight('file1', [ highlightingsInLine1 ]);
-    assert.deepEqual(highlighter.applicationUriHistory,
-                     [ 'file1', 'file1', 'file2', 'file1', 'file2', 'file1' ]);
+    highlighter.highlight(fileUri1, [ highlightingsInLine1 ]);
+    assert.deepEqual(highlighter.applicationUriHistory, [
+      fileUri1Str, fileUri1Str, fileUri2Str, fileUri1Str, fileUri2Str,
+      fileUri1Str
+    ]);
     // After the incremental update to line 1, the old highlightings at line 1
     // will no longer exist in the array.
     assert.deepEqual(
-        highlighter.getDecorationRanges('file1'),
+        highlighter.getDecorationRanges(fileUri1),
         createHighlightingScopeRanges(
             [ highlightingsInLine1, ...highlightingsInLine.slice(1) ]));
     // Closing a text document removes all highlightings for the file and no
     // other files.
-    highlighter.removeFileHighlightings('file1');
-    assert.deepEqual(highlighter.getDecorationRanges('file1'), []);
-    assert.deepEqual(highlighter.getDecorationRanges('file2'),
+    highlighter.removeFileHighlightings(fileUri1);
+    assert.deepEqual(highlighter.getDecorationRanges(fileUri1), []);
+    assert.deepEqual(highlighter.getDecorationRanges(fileUri2),
                      createHighlightingScopeRanges([ highlightingsInLine1 ]));
   });
 });
Index: clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
===================================================================
--- clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
@@ -111,10 +111,10 @@
                                                 serverOptions, clientOptions);
   if (getConfig<boolean>('semanticHighlighting')) {
     const semanticHighlightingFeature =
-      new semanticHighlighting.SemanticHighlightingFeature(clangdClient,
-        context);
+        new semanticHighlighting.SemanticHighlightingFeature(clangdClient,
+                                                             context);
     context.subscriptions.push(
-      vscode.Disposable.from(semanticHighlightingFeature));
+        vscode.Disposable.from(semanticHighlightingFeature));
     clangdClient.registerFeature(semanticHighlightingFeature);
   }
   console.log('Clang Language Server is now active!');
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to