From 8921b0d45bebb615fcd9e19b5174474f1840616f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Jo=C3=A3o=20Motta?= Date: Tue, 9 Jan 2024 18:17:14 -0300 Subject: [PATCH] Fix problems notifications and the *.wid load on windows machines --- .../src/VsCodeKieEditorCustomDocument.ts | 18 +++++++++-- ...CodeResourceContentServiceForWorkspaces.ts | 3 +- .../src/workspace/workspaceRoot.ts | 32 +++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/packages/vscode-extension/src/VsCodeKieEditorCustomDocument.ts b/packages/vscode-extension/src/VsCodeKieEditorCustomDocument.ts index 4787b2a5cc3..4b811c54ecf 100644 --- a/packages/vscode-extension/src/VsCodeKieEditorCustomDocument.ts +++ b/packages/vscode-extension/src/VsCodeKieEditorCustomDocument.ts @@ -35,7 +35,12 @@ import { VsCodeOutputLogger } from "./VsCodeOutputLogger"; import { VsCodeI18n } from "./i18n"; import { VsCodeNotificationsChannelApiImpl } from "./notifications/VsCodeNotificationsChannelApiImpl"; import { executeOnSaveHook } from "./onSaveHook"; -import { getNormalizedPosixPathRelativeToWorkspaceRoot } from "./workspace/workspaceRoot"; +import { + getNormalizedPosixPathRelativeToWorkspaceRoot, + getWorkspaceRoot, + normalizeWindowsWorkspaceRoot, +} from "./workspace/workspaceRoot"; +import * as __path from "path"; export class VsCodeKieEditorCustomDocument implements CustomDocument { private readonly encoder = new TextEncoder(); @@ -93,7 +98,16 @@ export class VsCodeKieEditorCustomDocument implements CustomDocument { try { const notifications = await editor.validate(); - this.vscodeNotifications.setNotifications(this, destination.fsPath, notifications); + this.vscodeNotifications.setNotifications( + this, + __path.posix.normalize( + __path.relative( + normalizeWindowsWorkspaceRoot(getWorkspaceRoot(this).workspaceRootAbsoluteFsPath), + destination.fsPath + ) + ), + notifications + ); } catch (e) { this.vsCodeLogger.warn(`File was not validated: ${e}`); } diff --git a/packages/vscode-extension/src/workspace/VsCodeResourceContentServiceForWorkspaces.ts b/packages/vscode-extension/src/workspace/VsCodeResourceContentServiceForWorkspaces.ts index 4f761a62fcf..16cecb1cdd1 100644 --- a/packages/vscode-extension/src/workspace/VsCodeResourceContentServiceForWorkspaces.ts +++ b/packages/vscode-extension/src/workspace/VsCodeResourceContentServiceForWorkspaces.ts @@ -83,7 +83,8 @@ export class VsCodeResourceContentServiceForWorkspaces implements ResourceConten // 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)); + // the regex doesn't support "\" from Windows paths, requiring to test againts POSIX paths + regexp.test(__path.posix.relative(openFileDirectoryNormalizedPosixPathRelativeToTheWorkspaceRoot, p)); const conformsToSearchType = !opts || diff --git a/packages/vscode-extension/src/workspace/workspaceRoot.ts b/packages/vscode-extension/src/workspace/workspaceRoot.ts index 364e6ba5abf..24f7cca9e83 100644 --- a/packages/vscode-extension/src/workspace/workspaceRoot.ts +++ b/packages/vscode-extension/src/workspace/workspaceRoot.ts @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import * as vscode from "vscode"; import * as __path from "path"; import { KogitoEditorDocument } from "../VsCodeKieEditorController"; @@ -28,3 +47,16 @@ export function getWorkspaceRoot(document: KogitoEditorDocument["document"]): { }; } } + +/** + * The "vscode.workspace.workspaceFolders" returns a POSIX path with a starting "/" on Windows machines + * This function removes the starting "/" and normalizes the path, returning a compatible absolute FS path. + */ + +export function normalizeWindowsWorkspaceRootAbsoluteFsPath(workspaceRootAbsoluteFsPath: string): string { + // The vscode.env.uiKind returns 1 for desktop applications, enabling the usage of the process.platform + if (vscode.env.uiKind === 1 && process.platform === "win32" && workspaceRootAbsoluteFsPath.startsWith("/")) { + return __path.normalize(workspaceRootAbsoluteFsPath.slice(1)); + } + return workspaceRootAbsoluteFsPath; +}