Skip to content

Commit ec22af5

Browse files
committed
Add support for Windows
1 parent 58f6626 commit ec22af5

3 files changed

Lines changed: 34 additions & 13 deletions

File tree

src/persistence/serialization/deserializer.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import * as vscode from 'vscode';
44
import { CommentReaction, CommentThread, Range } from 'vscode';
55
import { NoteComment } from '../../models/noteComment';
66
import { commentController } from '../../controllers/comments';
7-
import { relativePathtoFull } from '../../utils';
7+
import { isWindows, pathToWin32, relativePathToFull } from '../../utils';
88
import { Resource } from '../../reactions/resource';
99

1010
export class Deserializer {
1111
static deserializeReaction(reaction: any): CommentReaction {
12+
let iconPath = relativePathToFull(reaction.iconPath, Resource.extensionPath);
13+
if (isWindows()) {
14+
iconPath = pathToWin32(iconPath);
15+
}
1216
return {
1317
count: reaction.count,
14-
iconPath: relativePathtoFull(reaction.iconPath, Resource.extensionPath),
18+
iconPath: iconPath,
1519
label: reaction.label,
1620
authorHasReacted: false,
1721
};
@@ -42,8 +46,12 @@ export class Deserializer {
4246
}
4347

4448
static deserializeThread(thread: any): CommentThread {
49+
let uri = relativePathToFull(thread.uri);
50+
if (isWindows()) {
51+
uri = pathToWin32(uri);
52+
}
4553
const newThread = commentController.createCommentThread(
46-
vscode.Uri.file(relativePathtoFull(thread.uri)),
54+
vscode.Uri.file(uri),
4755
this.deserializeRange(thread.range),
4856
[],
4957
);

src/persistence/serialization/serializer.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
'use strict';
22

33
import { Comment, CommentReaction, CommentThread, Range } from 'vscode';
4-
import { fullPathtoRelative } from '../../utils';
4+
import { fullPathToRelative, isWindows, pathToPosix, pathToWin32 } from '../../utils';
55
import { Resource } from '../../reactions/resource';
66

77
export class Serializer {
88
static serializeReaction(reaction: CommentReaction) {
9+
let iconPath = fullPathToRelative(
10+
typeof reaction.iconPath === 'string'
11+
? reaction.iconPath
12+
: reaction.iconPath.fsPath,
13+
Resource.extensionPath,
14+
);
15+
if (isWindows()) {
16+
iconPath = pathToPosix(iconPath);
17+
}
918
return {
1019
count: reaction.count,
11-
iconPath: fullPathtoRelative(
12-
typeof reaction.iconPath === 'string'
13-
? reaction.iconPath
14-
: reaction.iconPath.fsPath,
15-
Resource.extensionPath,
16-
),
20+
iconPath: iconPath,
1721
label: reaction.label,
1822
};
1923
}
@@ -45,9 +49,13 @@ export class Serializer {
4549
thread.comments.forEach((comment) => {
4650
serializedComments.push(this.serializeComment(comment));
4751
});
52+
let uri = fullPathToRelative(thread.uri.path);
53+
if (isWindows()) {
54+
uri = pathToPosix(uri);
55+
}
4856
return {
4957
range: this.serializeRange(thread.range),
50-
uri: fullPathtoRelative(thread.uri.path),
58+
uri: uri,
5159
comments: serializedComments,
5260
id: thread.contextValue,
5361
};

src/utils/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
import * as vscode from 'vscode';
44
import * as path from 'path';
5+
import { platform } from 'os';
6+
7+
export const isWindows = () => {
8+
return platform() === 'win32';
9+
};
510

611
export const pathToPosix = (aPath: string) => {
712
return aPath.split(path.sep).join(path.posix.sep);
@@ -19,14 +24,14 @@ export const getWorkspacePath = () => {
1924
}
2025
};
2126

22-
export const relativePathtoFull = (aPath: string, basePath?: string) => {
27+
export const relativePathToFull = (aPath: string, basePath?: string) => {
2328
if (basePath) {
2429
return path.join(basePath, aPath);
2530
}
2631
return path.join(getWorkspacePath(), aPath);
2732
};
2833

29-
export const fullPathtoRelative = (aPath: string, basePath?: string) => {
34+
export const fullPathToRelative = (aPath: string, basePath?: string) => {
3035
if (basePath) {
3136
return path.relative(basePath, aPath);
3237
}

0 commit comments

Comments
 (0)