jomarko commented on code in PR #3371:
URL: 
https://github.com/apache/incubator-kie-tools/pull/3371#discussion_r2627808850


##########
packages/vscode-extension/src/workspace/VsCodeResourceContentServiceForWorkspaces.ts:
##########
@@ -73,48 +74,118 @@ export class VsCodeResourceContentServiceForWorkspaces 
implements ResourceConten
 
       const minimatch = new Minimatch(pattern);
       const regexp = minimatch.makeRe(); // The regexp is ~50x faster than the 
direct match using glob.
+      // e.g. src/main/resources/com/my/module
       const openFileDirectoryNormalizedPosixPathRelativeToTheWorkspaceRoot = 
__path.dirname(
         getNormalizedPosixPathRelativeToWorkspaceRoot(this.args.document)
       );
 
-      const matchingNormalizedPosixPathsRelativeToTheBasePath = 
normalizedPosixPathsRelativeToTheBasePath.filter(
-        (p) => {
-          const matchesPattern =
-            // Adding a leading slash here to make the regex have the same 
behavior as the glob with **/* pattern.
-            regexp.test("/" + p) ||
-            // check on the asset folder for *.{ext} pattern
-            // the regex doesn't support "\" from Windows paths, requiring to 
test againts POSIX paths
-            
regexp.test(__path.posix.relative(openFileDirectoryNormalizedPosixPathRelativeToTheWorkspaceRoot,
 p));
-
-          const conformsToSearchType =
-            !opts ||
-            opts.type === SearchType.TRAVERSAL ||
-            (opts.type === SearchType.ASSET_FOLDER &&
-              __path
-                .join(baseAbsoluteFsPath, toFsPath(p))
-                .startsWith(
-                  __path.join(
-                    baseAbsoluteFsPath,
-                    
toFsPath(openFileDirectoryNormalizedPosixPathRelativeToTheWorkspaceRoot)
-                  )
-                ));
-
-          return matchesPattern && conformsToSearchType;
-        }
-      );
-      return new ResourcesList(pattern, 
matchingNormalizedPosixPathsRelativeToTheBasePath);
+      gitNormalizedPosixPathsRelativeToTheBasePath = 
normalizedPosixPathsRelativeToTheBasePath.filter((p) => {
+        const matchesPattern =
+          // Adding a leading slash here to make the regex have the same 
behavior as the glob with **/* pattern.
+          regexp.test("/" + p) ||
+          // check on the asset folder for *.{ext} pattern
+          // the regex doesn't support "\" from Windows paths, requiring to 
test against POSIX paths
+          // relative to `this.args.document`, e.g. 
../../../src/main/java/com/my/module/MyClass.java
+          
regexp.test(__path.posix.relative(openFileDirectoryNormalizedPosixPathRelativeToTheWorkspaceRoot,
 p));
+
+        const conformsToSearchType =
+          !opts ||
+          opts.type === SearchType.TRAVERSAL ||
+          (opts.type === SearchType.ASSET_FOLDER &&
+            __path
+              .join(baseAbsoluteFsPath, toFsPath(p))
+              .startsWith(
+                __path.join(
+                  baseAbsoluteFsPath,
+                  
toFsPath(openFileDirectoryNormalizedPosixPathRelativeToTheWorkspaceRoot)
+                )
+              ));
+
+        return matchesPattern && conformsToSearchType;
+      });
     } catch (error) {
       console.debug(
-        "VS CODE RESOURCE CONTENT API IMPL FOR WORKSPACES: Failed to use 
isomorphic-git to read dir. Falling back to vscode's API.",
+        "VS CODE RESOURCE CONTENT API IMPL FOR WORKSPACES: Failed to use 
isomorphic-git to read dir. Falling back to VS Code API.",
         error
       );
-      const relativePattern = new RelativePattern(baseAbsoluteFsPath, pattern);
-      const files = await vscode.workspace.findFiles(relativePattern);
-      const normalizedPosixPathsRelativeToTheWorkspaceRoot = files.map((uri) =>
-        vscode.workspace.asRelativePath(uri, false)
-      );
-      return new ResourcesList(pattern, 
normalizedPosixPathsRelativeToTheWorkspaceRoot);
     }
+
+    // Normalize incoming pattern to POSIX for VS Code globbing
+    const posixPattern = pattern.replace(/\\/g, "/");
+    const { staticPrefix, remainingGlob } = 
this.splitStaticPrefix(posixPattern);
+
+    let theMostSpecificFolder = baseAbsoluteFsPath;
+    const globRelativeToBase = remainingGlob || posixPattern;
+
+    // In case of ASSET_FOLDER we are done, see baseAbsoluteFsPath creation
+    if (opts?.type !== SearchType.ASSET_FOLDER) {
+      theMostSpecificFolder = staticPrefix ? __path.join(baseAbsoluteFsPath, 
staticPrefix) : baseAbsoluteFsPath;
+    }
+
+    const relativePattern = new RelativePattern(theMostSpecificFolder, 
globRelativeToBase);

Review Comment:
   logic and names changed



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

Reply via email to