Skip to content

Commit

Permalink
Fix problems notifications and the *.wid load on windows machines
Browse files Browse the repository at this point in the history
  • Loading branch information
ljmotta committed Jan 9, 2024
1 parent 7c55d46 commit 8921b0d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
18 changes: 16 additions & 2 deletions packages/vscode-extension/src/VsCodeKieEditorCustomDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
32 changes: 32 additions & 0 deletions packages/vscode-extension/src/workspace/workspaceRoot.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
}

0 comments on commit 8921b0d

Please sign in to comment.