From 5fedef4d13e3605afb61a640cbeb95e3f451a373 Mon Sep 17 00:00:00 2001 From: Tiago Bento Date: Fri, 29 Dec 2023 18:24:04 -0500 Subject: [PATCH] WIDs correctly recognized by the BPMN Editor now --- packages/bpmn-vscode-extension/package.json | 2 +- .../bpmn-vscode-extension/webpack.config.js | 6 ++++ .../util/DmnResourceContentFetcher.java | 2 +- ...CodeResourceContentServiceForWorkspaces.ts | 32 ++++++++++++++++--- ...deResourceContentServiceIsomorphicGitFs.ts | 5 --- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/packages/bpmn-vscode-extension/package.json b/packages/bpmn-vscode-extension/package.json index 1b38b8209f9..87b0cc48c40 100644 --- a/packages/bpmn-vscode-extension/package.json +++ b/packages/bpmn-vscode-extension/package.json @@ -22,7 +22,7 @@ "lint": "run-script-if --bool \"$(build-env linters.run)\" --then \"kie-tools--eslint ./src\"", "pack:prod": "vsce package --githubBranch main --no-dependencies -o ./dist/bpmn_vscode_extension_$npm_package_version.vsix", "run:webmode": "pnpm vscode-test-web --browserType=chromium --extensionDevelopmentPath=. --version=stable", - "watch": "webpack" + "watch": "export WEBPACK__sourceMaps=true; WEBPACK__minimize=false; webpack --env dev" }, "dependencies": { "@kie-tools-core/backend": "workspace:*", diff --git a/packages/bpmn-vscode-extension/webpack.config.js b/packages/bpmn-vscode-extension/webpack.config.js index b86a5bec776..c183d9a52f9 100644 --- a/packages/bpmn-vscode-extension/webpack.config.js +++ b/packages/bpmn-vscode-extension/webpack.config.js @@ -33,6 +33,12 @@ const commonConfig = (env) => umdNamedDefine: true, globalObject: "this", }, + plugins: [ + new ProvidePlugin({ + process: require.resolve("process/browser.js"), + Buffer: ["buffer", "Buffer"], + }), + ], externals: { vscode: "commonjs vscode", }, diff --git a/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/main/java/org/kie/workbench/common/stunner/bpmn/client/util/DmnResourceContentFetcher.java b/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/main/java/org/kie/workbench/common/stunner/bpmn/client/util/DmnResourceContentFetcher.java index 87ea1ee3c31..56284c8c047 100644 --- a/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/main/java/org/kie/workbench/common/stunner/bpmn/client/util/DmnResourceContentFetcher.java +++ b/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/main/java/org/kie/workbench/common/stunner/bpmn/client/util/DmnResourceContentFetcher.java @@ -48,7 +48,7 @@ public class DmnResourceContentFetcher { private final DmnLanguageServiceServiceProducer dmnLanguageServiceServiceProducer; private Map fileNames = new HashMap<>(); private List decisions = new ArrayList<>(); - private final static String fileMatcher = "*.dmn"; + private final static String fileMatcher = "**/*.dmn"; @Inject public DmnResourceContentFetcher(final ResourceContentService resourceContentService, diff --git a/packages/vscode-extension/src/workspace/VsCodeResourceContentServiceForWorkspaces.ts b/packages/vscode-extension/src/workspace/VsCodeResourceContentServiceForWorkspaces.ts index 6ae81f6cc3d..61e177d64aa 100644 --- a/packages/vscode-extension/src/workspace/VsCodeResourceContentServiceForWorkspaces.ts +++ b/packages/vscode-extension/src/workspace/VsCodeResourceContentServiceForWorkspaces.ts @@ -67,17 +67,39 @@ export class VsCodeResourceContentServiceForWorkspaces implements ResourceConten console.debug("VS CODE RESOURCE CONTENT API IMPL FOR WORKSPACES: Trying to use isomorphic-git to read dir."); const normalizedPosixPathsRelativeToTheBasePath = await listFiles({ fs: this.isomorphicGitFs, - dir: baseAbsoluteFsPath, + dir: this.args.workspaceRootAbsoluteFsPath, }); console.debug("VS CODE RESOURCE CONTENT API IMPL FOR WORKSPACES: Success on using isomorphic-git!"); const minimatch = new Minimatch(pattern); const regexp = minimatch.makeRe(); // The regexp is ~50x faster than the direct match using glob. + const openFileDirectoryNormalizedPosixPathRelativeToTheWorkspaceRoot = __path.dirname( + getNormalizedPosixPathRelativeToWorkspaceRoot(this.args.document) + ); + const matchingNormalizedPosixPathsRelativeToTheBasePath = normalizedPosixPathsRelativeToTheBasePath.filter( - (p) => - regexp.test( - "/" + p // Adding a leading slash here to make the regex have the same behavior as the glob with **/* pattern. - ) || regexp.test(__path.relative(getNormalizedPosixPathRelativeToWorkspaceRoot(this.args.document), p)) // check on the asset folder for *.{ext} pattern + (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 + regexp.test(__path.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); } catch (error) { diff --git a/packages/vscode-extension/src/workspace/VsCodeResourceContentServiceIsomorphicGitFs.ts b/packages/vscode-extension/src/workspace/VsCodeResourceContentServiceIsomorphicGitFs.ts index e5ac5b8dbc6..798bb1d4c52 100644 --- a/packages/vscode-extension/src/workspace/VsCodeResourceContentServiceIsomorphicGitFs.ts +++ b/packages/vscode-extension/src/workspace/VsCodeResourceContentServiceIsomorphicGitFs.ts @@ -17,7 +17,6 @@ * under the License. */ -import { PromiseFsClient } from "isomorphic-git"; import * as vscode from "vscode"; export class ReadonlyIsomorphicGitFsForVsCodeWorkspaceFolders { @@ -47,7 +46,6 @@ export class ReadonlyIsomorphicGitFsForVsCodeWorkspaceFolders { async readdir(path: string) { const contentPath = vscode.Uri.parse(path); try { - console.debug("vscode.workspace.fs.readDirectory", "path:", contentPath); return vscode.workspace.fs.readDirectory(contentPath); } catch (error) { console.debug("ERROR on vscode.workspace.fs.readDirectory", "error:", error, "path:", contentPath); @@ -57,7 +55,6 @@ export class ReadonlyIsomorphicGitFsForVsCodeWorkspaceFolders { async read(path: string) { const contentPath = vscode.Uri.parse(path); try { - console.debug("vscode.workspace.fs.readFile", "path:", contentPath); const uint8Array = await vscode.workspace.fs.readFile(contentPath); return Buffer.from(uint8Array); } catch (error) { @@ -72,7 +69,6 @@ export class ReadonlyIsomorphicGitFsForVsCodeWorkspaceFolders { async write(path: string, buffer: Buffer) { const contentPath = vscode.Uri.parse(path); try { - console.debug("vscode.workspace.fs.write", "path:", contentPath); return vscode.workspace.fs.writeFile(contentPath, buffer); } catch (error) { console.debug("ERROR on vscode.workspace.fs.write", "error:", error, "path:", contentPath); @@ -82,7 +78,6 @@ export class ReadonlyIsomorphicGitFsForVsCodeWorkspaceFolders { async lstat(path: string) { const contentPath = vscode.Uri.parse(path); try { - console.debug("vscode.workspace.fs.stat", "path:", contentPath); return vscode.workspace.fs.stat(contentPath); } catch (error) { console.debug("ERROR on vscode.workspace.fs.stat", "error:", error, "path:", contentPath);