From 76cbc8b724ca2399e9d57e346501f08a07bf7101 Mon Sep 17 00:00:00 2001 From: val Date: Tue, 2 Jul 2024 13:58:38 +0400 Subject: [PATCH] Fix - path handling on Windows --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/fileDecorationProvider.ts | 29 +++++++++++++++-------------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ed762d..a05e590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,3 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix: empty decoration errors in last vscode builds - Bump dependencies + +### [1.1.3] - 2024-07-02 + +- Fix: Import/Export marked files from scope file on Windows systems. diff --git a/package.json b/package.json index 5a830dd..488f7a1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "markfiles", "displayName": "Mark Files", "description": "An extension that allows you to mark files in the file explorer", - "version": "1.1.2", + "version": "1.1.3", "publisher": "vquelque", "engines": { "vscode": "^1.76.0" diff --git a/src/fileDecorationProvider.ts b/src/fileDecorationProvider.ts index f5ece6f..dea5d94 100644 --- a/src/fileDecorationProvider.ts +++ b/src/fileDecorationProvider.ts @@ -1,20 +1,20 @@ import path = require("path"); +import { existsSync, writeFile } from "fs"; +import ignore from "ignore"; import { - Uri, CancellationToken, - FileDecorationProvider, - FileDecoration, - EventEmitter, Event, - workspace, - ThemeColor, + EventEmitter, + FileDecoration, + FileDecorationProvider, FileType, + ThemeColor, + Uri, window, + workspace, } from "vscode"; -import { asyncReadFile } from "./utils"; -import { existsSync, writeFile } from "fs"; -import ignore from "ignore"; import { getStorage, printChannelOutput } from "./extension"; +import { asyncReadFile } from "./utils"; export class DecorationProvider implements FileDecorationProvider { private readonly _onDidChangeFileDecorations: EventEmitter = @@ -62,7 +62,7 @@ export class DecorationProvider implements FileDecorationProvider { case FileType.Directory: { // recurse const files = (await workspace.fs.readDirectory(uri)).map((tu) => - Uri.parse(`${uri}/${tu[0]}`), + Uri.file(`${uri}/${tu[0]}`), ); return this.markOrUnmarkFiles(files); } @@ -123,7 +123,7 @@ export class DecorationProvider implements FileDecorationProvider { .map((uri) => path.relative(projectRootUri, uri.fsPath)) .filter((relPath) => ig.ignores(relPath)) .map((relPath) => Uri.file(path.resolve(projectRootUri, relPath))); - printChannelOutput(`Loaded patterns from ${scopeUri}`); + printChannelOutput(`Loaded patterns from ${scopeUri}`); this.markOrUnmarkFiles(markedAbsPath); } @@ -150,9 +150,10 @@ export class DecorationProvider implements FileDecorationProvider { const markedFilesByWS = Array.from(this.markedFiles).reduce<{ [key: string]: string[]; }>((acc: { [key: string]: string[] }, uri: string) => { - const workspaceFolder = workspace.getWorkspaceFolder(Uri.parse(uri)); + const workspaceFolder = workspace.getWorkspaceFolder(Uri.file(uri)); if (workspaceFolder) { - const relativePath = path.relative(workspaceFolder.uri.fsPath, uri); //use relative URIs in the scope file + const relativePath = path.relative(workspaceFolder.uri.fsPath, uri).replace(/\\/g, '/'); //use relative URIs in the scope file - use forward slash even on windows because of globs + if (!acc[workspaceFolder.uri.fsPath]) { acc[workspaceFolder.uri.fsPath] = [relativePath]; } else { @@ -231,7 +232,7 @@ export class DecorationProvider implements FileDecorationProvider { const scopeFilesByProjectRootsURIs: { [scopeUri: string]: string } = {}; //iterate over all opened workspace folders const rootFolders = workspace.workspaceFolders?.map( - (folder) => folder.uri.path, + (folder) => folder.uri.fsPath, ); if (!rootFolders) { return {};