( mcpClients: MCPServerConnection[], onAtMentioned: (atMentioned: IDEAtMentioned) => void, )
| 31 | * with MCP client notification handlers, |
| 32 | */ |
| 33 | export function useIdeAtMentioned( |
| 34 | mcpClients: MCPServerConnection[], |
| 35 | onAtMentioned: (atMentioned: IDEAtMentioned) => void, |
| 36 | ): void { |
| 37 | const ideClientRef = useRef<ConnectedMCPServer | undefined>(undefined) |
| 38 | |
| 39 | useEffect(() => { |
| 40 | // Find the IDE client from the MCP clients list |
| 41 | const ideClient = getConnectedIdeClient(mcpClients) |
| 42 | |
| 43 | if (ideClientRef.current !== ideClient) { |
| 44 | ideClientRef.current = ideClient |
| 45 | } |
| 46 | |
| 47 | // If we found a connected IDE client, register our handler |
| 48 | if (ideClient) { |
| 49 | ideClient.client.setNotificationHandler( |
| 50 | AtMentionedSchema(), |
| 51 | notification => { |
| 52 | if (ideClientRef.current !== ideClient) { |
| 53 | return |
| 54 | } |
| 55 | try { |
| 56 | const data = notification.params |
| 57 | // Adjust line numbers to be 1-based instead of 0-based |
| 58 | const lineStart = |
| 59 | data.lineStart !== undefined ? data.lineStart + 1 : undefined |
| 60 | const lineEnd = |
| 61 | data.lineEnd !== undefined ? data.lineEnd + 1 : undefined |
| 62 | onAtMentioned({ |
| 63 | filePath: data.filePath, |
| 64 | lineStart: lineStart, |
| 65 | lineEnd: lineEnd, |
| 66 | }) |
| 67 | } catch (error) { |
| 68 | logError(error as Error) |
| 69 | } |
| 70 | }, |
| 71 | ) |
| 72 | } |
| 73 | |
| 74 | // No cleanup needed as MCP clients manage their own lifecycle |
| 75 | }, [mcpClients, onAtMentioned]) |
| 76 | } |
| 77 |
no test coverage detected