MCPcopy Create free account
hub / github.com/codeaashu/claude-code / getLSPDiagnosticAttachments

Function getLSPDiagnosticAttachments

src/utils/attachments.ts:2883–2935  ·  view source on GitHub ↗

* Get LSP diagnostic attachments from passive LSP servers. * Follows the AsyncHookRegistry pattern for consistent async attachment delivery.

(
  toolUseContext: ToolUseContext,
)

Source from the content-addressed store, hash-verified

2881 * Follows the AsyncHookRegistry pattern for consistent async attachment delivery.
2882 */
2883async function getLSPDiagnosticAttachments(
2884 toolUseContext: ToolUseContext,
2885): Promise<Attachment[]> {
2886 // LSP diagnostics are only useful if the agent has the Bash tool to act on them
2887 if (
2888 !toolUseContext.options.tools.some(t => toolMatchesName(t, BASH_TOOL_NAME))
2889 ) {
2890 return []
2891 }
2892
2893 logForDebugging('LSP Diagnostics: getLSPDiagnosticAttachments called')
2894
2895 try {
2896 const diagnosticSets = checkForLSPDiagnostics()
2897
2898 if (diagnosticSets.length === 0) {
2899 return []
2900 }
2901
2902 logForDebugging(
2903 `LSP Diagnostics: Found ${diagnosticSets.length} pending diagnostic set(s)`,
2904 )
2905
2906 // Convert each diagnostic set to an attachment
2907 const attachments: Attachment[] = diagnosticSets.map(({ files }) => ({
2908 type: 'diagnostics' as const,
2909 files,
2910 isNew: true,
2911 }))
2912
2913 // Clear delivered diagnostics from registry to prevent memory leak
2914 // Follows same pattern as removeDeliveredAsyncHooks
2915 if (diagnosticSets.length > 0) {
2916 clearAllLSPDiagnostics()
2917 logForDebugging(
2918 `LSP Diagnostics: Cleared ${diagnosticSets.length} delivered diagnostic(s) from registry`,
2919 )
2920 }
2921
2922 logForDebugging(
2923 `LSP Diagnostics: Returning ${attachments.length} diagnostic attachment(s)`,
2924 )
2925
2926 return attachments
2927 } catch (error) {
2928 const err = toError(error)
2929 logError(
2930 new Error(`Failed to get LSP diagnostic attachments: ${err.message}`),
2931 )
2932 // Return empty array to allow other attachments to proceed
2933 return []
2934 }
2935}
2936
2937export async function* getAttachmentMessages(
2938 input: string | null,

Callers 1

getAttachmentsFunction · 0.85

Calls 6

toolMatchesNameFunction · 0.85
logForDebuggingFunction · 0.85
checkForLSPDiagnosticsFunction · 0.85
clearAllLSPDiagnosticsFunction · 0.85
toErrorFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected