Skip to content

Commit ca215c4

Browse files
committed
Add fix for looking at sub dirs for .sln or .slnx files
1 parent d4d77d3 commit ca215c4

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/info.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,28 @@ export function projectInfo(cwd: string) : ProjectInfo {
1616
: null
1717
if (config) return config
1818

19-
const parentDir = path.dirname(cwd)
19+
// Search for .sln or .slnx file by walking up the directory tree
2020
let slnDir = ''
21-
let sln = fs.readdirSync(cwd).find(f => f.endsWith(".sln") || f.endsWith(".slnx"))
22-
if (sln) {
23-
slnDir = cwd
24-
} else {
25-
sln = fs.readdirSync(parentDir).find(f => f.endsWith(".sln") || f.endsWith(".slnx"))
26-
if (sln) {
27-
slnDir = parentDir
21+
let sln = ''
22+
let currentDir = cwd
23+
const root = path.parse(currentDir).root
24+
25+
while (currentDir !== root) {
26+
try {
27+
const found = fs.readdirSync(currentDir).find(f => f.endsWith(".sln") || f.endsWith(".slnx"))
28+
if (found) {
29+
sln = found
30+
slnDir = currentDir
31+
break
32+
}
33+
} catch (e) {
34+
// ignore permission errors
2835
}
36+
const parentDir = path.dirname(currentDir)
37+
if (parentDir === currentDir) break // reached root
38+
currentDir = parentDir
2939
}
40+
3041
if (!sln) {
3142
return null
3243
}

0 commit comments

Comments
 (0)