mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-22 00:05:51 +00:00
style: 完成所有文件的lint
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
import * as React from 'react'
|
||||
import { useInterval } from 'usehooks-ts'
|
||||
import { getIsRemoteMode, getIsScrollDraining } from '../../bootstrap/state.js'
|
||||
import { useNotifications } from '../../context/notifications.js'
|
||||
import { Text } from '@anthropic/ink'
|
||||
import {
|
||||
getInitializationStatus,
|
||||
getLspServerManager,
|
||||
} from '../../services/lsp/manager.js'
|
||||
import { useSetAppState } from '../../state/AppState.js'
|
||||
import { logForDebugging } from '../../utils/debug.js'
|
||||
import { isEnvTruthy } from '../../utils/envUtils.js'
|
||||
import * as React from 'react';
|
||||
import { useInterval } from 'usehooks-ts';
|
||||
import { getIsRemoteMode, getIsScrollDraining } from '../../bootstrap/state.js';
|
||||
import { useNotifications } from '../../context/notifications.js';
|
||||
import { Text } from '@anthropic/ink';
|
||||
import { getInitializationStatus, getLspServerManager } from '../../services/lsp/manager.js';
|
||||
import { useSetAppState } from '../../state/AppState.js';
|
||||
import { logForDebugging } from '../../utils/debug.js';
|
||||
import { isEnvTruthy } from '../../utils/envUtils.js';
|
||||
|
||||
const LSP_POLL_INTERVAL_MS = 5000
|
||||
const LSP_POLL_INTERVAL_MS = 5000;
|
||||
|
||||
/**
|
||||
* Hook that polls LSP status and shows a notification when:
|
||||
@@ -23,27 +20,25 @@ const LSP_POLL_INTERVAL_MS = 5000
|
||||
* Only active when ENABLE_LSP_TOOL is set.
|
||||
*/
|
||||
export function useLspInitializationNotification(): void {
|
||||
const { addNotification } = useNotifications()
|
||||
const setAppState = useSetAppState()
|
||||
const { addNotification } = useNotifications();
|
||||
const setAppState = useSetAppState();
|
||||
// Lazy initializer — eager form re-evaluates isEnvTruthy on every REPL
|
||||
// render (the arg expression runs even though useState ignores it after
|
||||
// mount). Showed up as 7.2s isEnvTruthy self-time during PageUp spam
|
||||
// after #24498 swapped cheap !!process.env.X for isEnvTruthy().
|
||||
const [shouldPoll, setShouldPoll] = React.useState(() =>
|
||||
isEnvTruthy("true"),
|
||||
)
|
||||
const [shouldPoll, setShouldPoll] = React.useState(() => isEnvTruthy('true'));
|
||||
// Track which errors we've already notified about to avoid duplicates
|
||||
const notifiedErrorsRef = React.useRef<Set<string>>(new Set())
|
||||
const notifiedErrorsRef = React.useRef<Set<string>>(new Set());
|
||||
|
||||
const addError = React.useCallback(
|
||||
(source: string, errorMessage: string) => {
|
||||
const errorKey = `${source}:${errorMessage}`
|
||||
const errorKey = `${source}:${errorMessage}`;
|
||||
if (notifiedErrorsRef.current.has(errorKey)) {
|
||||
return // Already notified
|
||||
return; // Already notified
|
||||
}
|
||||
notifiedErrorsRef.current.add(errorKey)
|
||||
notifiedErrorsRef.current.add(errorKey);
|
||||
|
||||
logForDebugging(`LSP error: ${source} - ${errorMessage}`)
|
||||
logForDebugging(`LSP error: ${source} - ${errorMessage}`);
|
||||
|
||||
// Add error to appState.plugins.errors
|
||||
setAppState(prev => {
|
||||
@@ -51,15 +46,15 @@ export function useLspInitializationNotification(): void {
|
||||
const existingKeys = new Set(
|
||||
prev.plugins.errors.map(e => {
|
||||
if (e.type === 'generic-error') {
|
||||
return `generic-error:${e.source}:${e.error}`
|
||||
return `generic-error:${e.source}:${e.error}`;
|
||||
}
|
||||
return `${e.type}:${e.source}`
|
||||
return `${e.type}:${e.source}`;
|
||||
}),
|
||||
)
|
||||
);
|
||||
|
||||
const stateErrorKey = `generic-error:${source}:${errorMessage}`
|
||||
const stateErrorKey = `generic-error:${source}:${errorMessage}`;
|
||||
if (existingKeys.has(stateErrorKey)) {
|
||||
return prev
|
||||
return prev;
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -75,13 +70,11 @@ export function useLspInitializationNotification(): void {
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
// Show notification - extract plugin name from source like "plugin:typescript-lsp:typescript"
|
||||
const displayName = source.startsWith('plugin:')
|
||||
? (source.split(':')[1] ?? source)
|
||||
: source
|
||||
const displayName = source.startsWith('plugin:') ? (source.split(':')[1] ?? source) : source;
|
||||
|
||||
addNotification({
|
||||
key: `lsp-error-${source}`,
|
||||
@@ -93,49 +86,49 @@ export function useLspInitializationNotification(): void {
|
||||
),
|
||||
priority: 'medium',
|
||||
timeoutMs: 8000,
|
||||
})
|
||||
});
|
||||
},
|
||||
[addNotification, setAppState],
|
||||
)
|
||||
);
|
||||
|
||||
const poll = React.useCallback(() => {
|
||||
if (getIsRemoteMode()) return
|
||||
if (getIsRemoteMode()) return;
|
||||
// Skip during scroll drain — iterating all LSP servers + setAppState
|
||||
// competes for the event loop with scroll frames. Next interval picks up.
|
||||
if (getIsScrollDraining()) return
|
||||
if (getIsScrollDraining()) return;
|
||||
|
||||
const status = getInitializationStatus()
|
||||
const status = getInitializationStatus();
|
||||
|
||||
// Check manager initialization status
|
||||
if (status.status === 'failed') {
|
||||
addError('lsp-manager', status.error.message)
|
||||
setShouldPoll(false)
|
||||
return
|
||||
addError('lsp-manager', status.error.message);
|
||||
setShouldPoll(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (status.status === 'pending' || status.status === 'not-started') {
|
||||
// Still initializing, continue polling
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
// Manager initialized successfully - check for server errors
|
||||
const manager = getLspServerManager()
|
||||
const manager = getLspServerManager();
|
||||
if (manager) {
|
||||
const servers = manager.getAllServers()
|
||||
const servers = manager.getAllServers();
|
||||
for (const [serverName, server] of servers) {
|
||||
if (server.state === 'error' && server.lastError) {
|
||||
addError(serverName, server.lastError.message)
|
||||
addError(serverName, server.lastError.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Continue polling to detect future server errors
|
||||
}, [addError])
|
||||
}, [addError]);
|
||||
|
||||
useInterval(poll, shouldPoll ? LSP_POLL_INTERVAL_MS : null)
|
||||
useInterval(poll, shouldPoll ? LSP_POLL_INTERVAL_MS : null);
|
||||
|
||||
// Initial poll on mount
|
||||
React.useEffect(() => {
|
||||
if (getIsRemoteMode() || !shouldPoll) return
|
||||
poll()
|
||||
}, [poll, shouldPoll])
|
||||
if (getIsRemoteMode() || !shouldPoll) return;
|
||||
poll();
|
||||
}, [poll, shouldPoll]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user