Skip to content

Commit 1a0c445

Browse files
authored
fix: WSL detection (#84)
1 parent 3c33cfb commit 1a0c445

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

.codacy/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
*.yaml
33

44
# tools-config folder
5-
tools-configs
5+
tools-configs/
6+
logs/
67

src/commands/configureMCP.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,24 @@ export async function createRules(repository?: Repository) {
174174
}
175175
}
176176

177+
/**
178+
* Detects if the current environment is running in Windows Subsystem for Linux (WSL)
179+
* @returns boolean indicating if the current environment is WSL
180+
*/
181+
export function isRunningInWsl(): boolean {
182+
if (os.platform() !== 'linux') {
183+
return false
184+
}
185+
186+
try {
187+
const osReleaseContent = fs.readFileSync('/proc/version', 'utf8')
188+
return osReleaseContent.toLowerCase().includes('microsoft') || osReleaseContent.toLowerCase().includes('wsl')
189+
} catch {
190+
// If we can't read the file, assume it's not WSL
191+
return false
192+
}
193+
}
194+
177195
function getCurrentIDE(): string {
178196
const isCursor = vscode.env.appName.toLowerCase().includes('cursor')
179197
const isWindsurf = vscode.env.appName.toLowerCase().includes('windsurf')
@@ -204,16 +222,12 @@ function getCorrectMcpConfig(): {
204222
// Get platform-specific VS Code settings directory
205223
let vsCodeSettingsPath: string
206224

207-
switch (process.platform) {
208-
case 'darwin': // macOS
209-
vsCodeSettingsPath = path.join(os.homedir(), 'Library', 'Application Support', 'Code', 'User')
210-
break
211-
case 'win32': // Windows
212-
vsCodeSettingsPath = path.join(os.homedir(), 'AppData', 'Roaming', 'Code', 'User')
213-
break
214-
default: // Linux and others
215-
vsCodeSettingsPath = path.join(os.homedir(), '.config', 'Code', 'User')
216-
break
225+
if (process.platform === 'win32' || isRunningInWsl()) {
226+
vsCodeSettingsPath = path.join(os.homedir(), 'AppData', 'Roaming', 'Code', 'User')
227+
} else if (process.platform === 'darwin') {
228+
vsCodeSettingsPath = path.join(os.homedir(), 'Library', 'Application Support', 'Code', 'User')
229+
} /* Linux */ else {
230+
vsCodeSettingsPath = path.join(os.homedir(), '.config', 'Code', 'User')
217231
}
218232

219233
return {

0 commit comments

Comments
 (0)