[Mlir-commits] [mlir] 3c7e467 - [mlir-vscode] Fix processing of files not within the workspace

River Riddle llvmlistbot at llvm.org
Mon Apr 11 15:41:40 PDT 2022


Author: River Riddle
Date: 2022-04-11T15:41:19-07:00
New Revision: 3c7e4674061f0ef38a53ab219ed0c01b1ea937fa

URL: https://github.com/llvm/llvm-project/commit/3c7e4674061f0ef38a53ab219ed0c01b1ea937fa
DIFF: https://github.com/llvm/llvm-project/commit/3c7e4674061f0ef38a53ab219ed0c01b1ea937fa.diff

LOG: [mlir-vscode] Fix processing of files not within the workspace

In a previous commit we added proper support for separate configurations
per workspace folder, but that effectively broke support for processing out-of-workspace
files. Given how useful this is (e.g. when iterating on a test case in /tmp), this
commit refactors server creation to support this again. We support this case using
a "fallback" server that specifically handles files not within the workspace. This uses
the configuration settings for the current workspace itself (not the specific folder).

Differential Revision: https://reviews.llvm.org/D123183

Added: 
    

Modified: 
    mlir/utils/vscode/src/mlirContext.ts

Removed: 
    


################################################################################
diff  --git a/mlir/utils/vscode/src/mlirContext.ts b/mlir/utils/vscode/src/mlirContext.ts
index 521fdf0f260a7..83b1c4b94a252 100644
--- a/mlir/utils/vscode/src/mlirContext.ts
+++ b/mlir/utils/vscode/src/mlirContext.ts
@@ -39,10 +39,9 @@ export class MLIRContext implements vscode.Disposable {
         this.workspaceFolders.push(await this.activateWorkspaceFolder(
             workspaceFolder, outputChannel, warnOnEmptyServerPath));
       }
-    } else {
-      this.workspaceFolders.push(await this.activateWorkspaceFolder(
-          null, outputChannel, warnOnEmptyServerPath));
     }
+    this.workspaceFolders.push(await this.activateWorkspaceFolder(
+        null, outputChannel, warnOnEmptyServerPath));
   }
 
   /**
@@ -130,6 +129,24 @@ export class MLIRContext implements vscode.Disposable {
       selectorPattern = `${workspaceFolder.uri.fsPath}/**/*`;
     }
 
+    // Configure the middleware of the client. This is sort of abused to allow
+    // for defining a "fallback" language server that operates on non-workspace
+    // folders. Workspace folder language servers can properly filter out
+    // documents not within the folder, but we can't effectively filter for
+    // documents outside of the workspace. To support this, and avoid having two
+    // servers targeting the same set of files, we use middleware to inject the
+    // dynamic logic for checking if a document is in the workspace.
+    let middleware = {};
+    if (!workspaceFolder) {
+      middleware = {
+        didOpen : (document, next) => {
+          if (!vscode.workspace.getWorkspaceFolder(document.uri)) {
+            next(document);
+          }
+        }
+      };
+    }
+
     // Configure the client options.
     const clientOptions: vscodelc.LanguageClientOptions = {
       documentSelector : [
@@ -141,7 +158,8 @@ export class MLIRContext implements vscode.Disposable {
         fileEvents : vscode.workspace.createFileSystemWatcher(filePattern)
       },
       outputChannel : outputChannel,
-      workspaceFolder : workspaceFolder
+      workspaceFolder : workspaceFolder,
+      middleware : middleware
     };
 
     // Create the language client and start the client.


        


More information about the Mlir-commits mailing list