Skip to content

Commit 9b96c3c

Browse files
committed
fix: do not crash when there is a symlink folder in the workspace
Fixes #600
1 parent 3a2d94d commit 9b96c3c

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ class VitestExtension {
128128
files,
129129
)
130130
}
131+
132+
this.testController.items.forEach((item) => {
133+
item.busy = false
134+
})
131135
}
132136
catch (err) {
133137
this.testTree.reset([])

src/testTree.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,30 @@ export class TestTree extends vscode.Disposable {
8282
return files
8383
}
8484

85+
getSymlinkFolder(uri: vscode.Uri) {
86+
const stats = lstatSync(uri.fsPath)
87+
if (stats.isSymbolicLink()) {
88+
const actualPath = readlinkSync(uri.fsPath)
89+
const dir = dirname(uri.fsPath)
90+
const id = resolve(dir, actualPath)
91+
return vscode.Uri.file(id)
92+
}
93+
return uri
94+
}
95+
8596
// in cases where there is only a single workspace, we don't show it as a folder
8697
// this inline folder is required for "createFolderItem" to properly resolve the parent,
8798
// otherwise it will go into an infinite loop
8899
getOrCreateInlineFolderItem(folderUri: vscode.Uri) {
89-
let id = normalize(folderUri.fsPath)
100+
const symlinkUri = this.getSymlinkFolder(folderUri)
101+
const id = normalize(symlinkUri.fsPath)
90102
const cached = this.folderItems.get(id)
91103
if (cached)
92104
return cached
93-
const stats = lstatSync(folderUri.fsPath)
94-
if (stats.isSymbolicLink()) {
95-
const actualPath = readlinkSync(folderUri.fsPath)
96-
const dir = dirname(folderUri.fsPath)
97-
id = resolve(dir, actualPath)
98-
folderUri = vscode.Uri.file(id)
99-
}
100-
const cachedSymlink = this.folderItems.get(id)
101-
if (cachedSymlink)
102-
return cachedSymlink
103105
const item: vscode.TestItem = {
104-
id: folderUri.toString(),
106+
id: symlinkUri.toString(),
105107
children: this.controller.items,
106-
uri: folderUri,
108+
uri: symlinkUri,
107109
label: '<root>',
108110
canResolveChildren: false,
109111
busy: false,
@@ -114,17 +116,28 @@ export class TestTree extends vscode.Disposable {
114116
}
115117
TestFolder.register(item)
116118
this.folderItems.set(id, item)
119+
120+
if (symlinkUri !== folderUri) {
121+
const originalId = normalize(folderUri.fsPath)
122+
this.folderItems.set(originalId, item)
123+
}
117124
return item
118125
}
119126

120127
getOrCreateWorkspaceFolderItem(folderUri: vscode.Uri) {
121-
const folderId = normalize(folderUri.fsPath)
128+
const symlinkUri = this.getSymlinkFolder(folderUri)
129+
const folderId = normalize(symlinkUri.fsPath)
122130
const cached = this.folderItems.get(folderId)
123131
if (cached)
124132
return cached
125133

126-
const folderItem = this._createFolderItem(folderUri)
134+
const folderItem = this._createFolderItem(symlinkUri)
127135
this.folderItems.set(folderId, folderItem)
136+
// if item is symlink, also store it in the symlink location
137+
if (symlinkUri !== folderUri) {
138+
const originalId = normalize(folderUri.fsPath)
139+
this.folderItems.set(originalId, folderItem)
140+
}
128141
return folderItem
129142
}
130143

0 commit comments

Comments
 (0)