Skip to content

Commit d7ba10a

Browse files
Merge pull request #40 from codacy/windsurf-auth
add windsurf support
2 parents 56288f5 + e682f2d commit d7ba10a

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
{
4343
"id": "codacy:mcp",
4444
"name": "Codacy MCP Server",
45-
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && codacy:isCursor",
45+
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && (codacy:isCursor || codacy:isWindsurf)",
4646
"icon": "$(gear)",
4747
"initialSize": 2
4848
},
@@ -84,13 +84,13 @@
8484
},
8585
{
8686
"view": "codacy:mcp",
87-
"contents": "Enable your Cursor AI Chat to talk to Codacy's Cloud API \n[Add Codacy MCP Server](command:codacy.configureMCP)",
88-
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && codacy:isCursor && !codacy:mcpConfigured"
87+
"contents": "Enable your AI Chat to talk to Codacy's Cloud API \n[Add Codacy MCP Server](command:codacy.configureMCP)",
88+
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && (codacy:isCursor || codacy:isWindsurf) && !codacy:mcpConfigured"
8989
},
9090
{
9191
"view": "codacy:mcp",
9292
"contents": "MCP Server is enabled\n[Reset MCP Server](command:codacy.configureMCP.reset)",
93-
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && codacy:isCursor && codacy:mcpConfigured"
93+
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && (codacy:isCursor || codacy:isWindsurf) && codacy:mcpConfigured"
9494
},
9595
{
9696
"view": "codacy:statuses",
@@ -193,21 +193,21 @@
193193
"command": "codacy.configureMCP",
194194
"title": "Configure Codacy MCP Server",
195195
"category": "Codacy commands",
196-
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && codacy:isCursor"
196+
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && (codacy:isCursor || codacy:isWindsurf) && !codacy:mcpConfigured"
197197
},
198198
{
199199
"command": "codacy.configureMCP.reset",
200200
"title": "Reset Codacy MCP Server",
201201
"category": "Codacy commands",
202-
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && codacy:isCursor && codacy:mcpConfigured"
202+
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && (codacy:isCursor || codacy:isWindsurf) && codacy:mcpConfigured"
203203
},
204204
{
205205
"command": "codacy.configureMCP",
206-
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && codacy:isCursor && !codacy:mcpConfigured"
206+
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && (codacy:isCursor || codacy:isWindsurf) && !codacy:mcpConfigured"
207207
},
208208
{
209209
"command": "codacy.configureMCP.reset",
210-
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && codacy:isCursor && codacy:mcpConfigured"
210+
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && (codacy:isCursor || codacy:isWindsurf) && codacy:mcpConfigured"
211211
}
212212
],
213213
"menus": {
@@ -226,11 +226,11 @@
226226
},
227227
{
228228
"command": "codacy.configureMCP",
229-
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && codacy:isCursor && !codacy:mcpConfigured"
229+
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && (codacy:isCursor || codacy:isWindsurf) && !codacy:mcpConfigured"
230230
},
231231
{
232232
"command": "codacy.configureMCP.reset",
233-
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && codacy:isCursor && codacy:mcpConfigured"
233+
"when": "Codacy:RepositoryManagerStateContext != NeedsAuthentication && (codacy:isCursor || codacy:isWindsurf) && codacy:mcpConfigured"
234234
}
235235
],
236236
"view/title": [

src/auth.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ export class AuthUriHandler extends vscode.EventEmitter<vscode.Uri> implements v
2121
}
2222
}
2323

24-
export type IDE = 'vscode' | 'cursor'
24+
export type IDE = 'vscode' | 'cursor' | 'windsurf'
2525

2626
export const detectEditor = (): IDE => {
27-
return vscode.env.appName.toLowerCase().includes('cursor') ? 'cursor' : 'vscode'
27+
const appName = vscode.env.appName.toLowerCase()
28+
if (appName.includes('cursor')) return 'cursor'
29+
if (appName.includes('windsurf')) return 'windsurf'
30+
return 'vscode'
2831
}
2932

3033
export const signIn = async () => {

src/commands/configureMCP.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ import * as os from 'os'
55
import { Config } from '../common/config'
66

77
export function isMCPConfigured(): boolean {
8+
const isCursor = vscode.env.appName.toLowerCase().includes('cursor')
89
try {
9-
const mcpPath = path.join(os.homedir(), '.cursor', 'mcp.json')
10-
if (!fs.existsSync(mcpPath)) {
10+
const cursorMcpPath = path.join(os.homedir(), '.cursor', 'mcp.json')
11+
const windsurfMcpPath = path.join(os.homedir(), '.codeium', 'windsurf', 'mcp_config.json')
12+
13+
const ideConfigFile = isCursor ? cursorMcpPath : windsurfMcpPath
14+
if (!fs.existsSync(ideConfigFile)) {
1115
return false
1216
}
1317

14-
const config = JSON.parse(fs.readFileSync(mcpPath, 'utf8'))
18+
const config = JSON.parse(fs.readFileSync(ideConfigFile, 'utf8'))
1519
return config?.mcpServers?.codacy !== undefined
1620
} catch (error) {
1721
// If there's any error reading or parsing the file, assume it's not configured
@@ -20,6 +24,7 @@ export function isMCPConfigured(): boolean {
2024
}
2125

2226
export async function configureMCP() {
27+
const isCursor = vscode.env.appName.toLowerCase().includes('cursor')
2328
try {
2429
const apiToken = Config.apiToken
2530

@@ -28,12 +33,13 @@ export async function configureMCP() {
2833
}
2934

3035
// Create .cursor directory if it doesn't exist
31-
const cursorDir = path.join(os.homedir(), '.cursor')
32-
if (!fs.existsSync(cursorDir)) {
33-
fs.mkdirSync(cursorDir)
36+
const ideDir = isCursor ? path.join(os.homedir(), '.cursor') : path.join(os.homedir(), '.codeium', 'windsurf')
37+
38+
if (!fs.existsSync(ideDir)) {
39+
fs.mkdirSync(ideDir)
3440
}
3541

36-
const mcpPath = path.join(cursorDir, 'mcp.json')
42+
const mcpPath = path.join(ideDir, isCursor ? 'mcp.json' : 'mcp_config.json')
3743

3844
// Prepare the Codacy server configuration
3945
const codacyServer = {

src/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ export async function activate(context: vscode.ExtensionContext) {
9494
'codacy:isCursor',
9595
vscode.env.appName.toLowerCase().includes('cursor')
9696
)
97+
await vscode.commands.executeCommand(
98+
'setContext',
99+
'codacy:isWindsurf',
100+
vscode.env.appName.toLowerCase().includes('windsurf')
101+
)
97102

98103
Config.init(context)
99104

0 commit comments

Comments
 (0)