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


##########
packages/kie-editors-standalone/src/bpmn/index.ts:
##########
@@ -88,7 +88,7 @@ export function open(args: {
     stateControl,
     {
       normalizedPosixPathRelativeToTheWorkspaceRoot: "", // FIXME: 
https://github.com/apache/incubator-kie-issues/issues/811
-      fileName: "", // FIXME: 
https://github.com/apache/incubator-kie-issues/issues/811
+      fileName: "default", // FIXME: 
https://github.com/apache/incubator-kie-issues/issues/811

Review Comment:
   Why setting it to `default`? Could you please add a comment?



##########
packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-kogito-runtime/src/main/java/org/kie/workbench/common/stunner/kogito/client/services/WorkItemDefinitionStandaloneClientService.java:
##########
@@ -93,24 +94,34 @@ public WorkItemDefinitionRegistry getRegistry() {
 
     @Override
     public Promise<Collection<WorkItemDefinition>> call(final Metadata input) {
-        return loader;
+        return allWorkItemsLoader(input.getPath());
     }
 
     @PreDestroy
     public void destroy() {
         registry.clear();
-        loader = null;
     }
 
-    private Promise<Collection<WorkItemDefinition>> allWorkItemsLoader() {
+
+    private Promise<Collection<WorkItemDefinition>> allWorkItemsLoader(Path 
openedDiagramPath) {
+
+        final int lastSlashIndex = openedDiagramPath != null ? 
openedDiagramPath.toURI().lastIndexOf('/') : -1;
+        final String directoryPath = (lastSlashIndex != -1) 

Review Comment:
   I believe we should use a better name pattern to refertence paths as we have 
for the multiplying architecture with 
`normalizedPosixPathRelativeToTheWorkspaceRoot`. For this case, it is a path 
relative to the workspace, or it is a path relative to the BPMN?
   
   
   



##########
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);
+
+    const vscodeFoundFiles = await vscode.workspace.findFiles(relativePattern);
+    const vscodeNormalizedPosixPathsRelativeToTheBasePath = 
vscodeFoundFiles.map((uri) =>

Review Comment:
   as `vscode.workspace.findFiles` returns a `Thenable` I believe we can inline 
this variable.



##########
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:
   I'm not sure for what `theMostSpecificFolder` stands for, could you please 
give a more descriptive name?



##########
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);
+
+    const vscodeFoundFiles = await vscode.workspace.findFiles(relativePattern);
+    const vscodeNormalizedPosixPathsRelativeToTheBasePath = 
vscodeFoundFiles.map((uri) =>

Review Comment:
   ```suggestion
       const vscodeNormalizedPosixPathsRelativeToTheBasePath = (await 
vscode.workspace.findFiles(relativePattern)).map((uri) =>
   ```



##########
packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-kogito-runtime/src/main/java/org/kie/workbench/common/stunner/kogito/client/services/WorkItemDefinitionStandaloneClientService.java:
##########
@@ -158,7 +169,7 @@ private Promise<Collection<WorkItemDefinition>> 
presetWorkItemsLoader(final Coll
     private Promise<Collection<WorkItemDefinition>> workItemsLoader(final 
String path,
                                                                     final 
Collection<WorkItemDefinition> loaded) {
         int lastDirIndex = path.lastIndexOf('/');
-        final String directory = (lastDirIndex >= 0) ? path.substring(0, 
lastDirIndex) + "/" : path;
+        final String directory = (lastDirIndex >= 0) ? path.substring(0, 
lastDirIndex) + "/" : "";

Review Comment:
   Same comment as above.



##########
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:
   ```suggestion
   
       // In case of ASSET_FOLDER we are done, see baseAbsoluteFsPath creation
       const theMostSpecificFolder = opts?.type !== SearchType.ASSET_FOLDER && 
staticPrefix ? __path.join(baseAbsoluteFsPath, staticPrefix) : 
baseAbsoluteFsPath;
   
       const relativePattern = new RelativePattern(theMostSpecificFolder, 
remainingGlob || posixPattern);
   ```



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