Skip to content

Latest commit

 

History

History
374 lines (288 loc) · 8.87 KB

File metadata and controls

374 lines (288 loc) · 8.87 KB

Code Navigation 구현 가이드

완료된 작업 요약

HighReview에 IntelliJ 수준의 코드 네비게이션 기능이 구현되었습니다.

1. 백엔드 인프라 ✅

다중 언어 LSP 서비스

위치: /apps/cli/src/services/LSPService.ts

지원 언어:

  • TypeScript/JavaScript: typescript-language-server
  • Ruby: solargraph
  • Java: jdtls

특징:

  • WebSocket 기반 통신
  • 자동 프로세스 관리
  • 오류 처리 및 복구
  • 설치 상태 확인 API

프로젝트 인덱싱 시스템

위치: /apps/cli/src/services/ProjectIndexService.ts

기능:

  • TypeScript, Ruby, Java 파일에서 심볼 자동 추출
  • SQLite 데이터베이스에 캐싱
  • PR/브랜치별 인덱스 관리
  • 커밋 해시 기반 자동 갱신
  • 빠른 심볼 검색 (< 50ms)

인덱싱되는 심볼:

  • 클래스, 인터페이스
  • 함수, 메소드
  • 변수, 상수
  • 타입 정의

API 엔드포인트

위치: /apps/cli/src/routes/

LSP 관련:

  • GET /api/lsp/check?language=typescript - 언어 서버 상태 확인
  • GET /api/lsp/check-all - 모든 언어 서버 상태
  • WebSocket /lsp?workspaceRoot=X&language=Y - LSP 통신

인덱싱 관련:

  • POST /api/index/start - 인덱싱 시작
  • GET /api/index/status - 인덱스 상태 확인
  • GET /api/index/search?query=X - 심볼 검색
  • GET /api/index/file-symbols - 파일 내 심볼 조회

2. 프론트엔드 통합 ✅

LSP 클라이언트

위치: /apps/web/src/utils/lsp.ts

기능:

  • 다중 언어 클라이언트 동시 연결
  • 자동 언어 감지
  • 설치된 서버만 자동 시작
  • 연결 상태 관리

Indexed Symbols API

위치: /apps/web/src/utils/indexedSymbols.ts

제공 기능:

  • searchSymbols() - 심볼 이름으로 검색
  • getFileSymbols() - 파일 내 모든 심볼 조회
  • findDefinition() - 정의 찾기
  • findUsages() - 사용처 찾기
  • findTestFile() - 테스트 파일 찾기
  • findSourceFile() - 소스 파일 찾기

UI 컴포넌트

위치: /apps/web/src/components/LanguageServerStatus.tsx

표시 정보:

  • 언어 서버 설치 상태
  • 설치 명령어
  • 자동 새로고침
  • 확장/축소 가능

3. 자동 인덱싱 ✅

위치: /apps/cli/src/routes/pr.routes.ts:218-221

PR checkout 시 자동으로 백그라운드에서 프로젝트 인덱싱이 시작됩니다.

// 자동 인덱싱 시작 (non-blocking)
indexService.indexProject(worktreePath, branch).catch((error) => {
  console.error('[PR Setup] Failed to index project:', error);
});

설치 및 설정

1. Language Server 설치

TypeScript (필수)

npm install -g typescript-language-server typescript

Ruby (선택)

gem install solargraph

Java (선택)

Eclipse JDT Language Server 다운로드: https://download.eclipse.org/jdtls/milestones/?d

2. 설치 확인

# 서버 실행 (apps/cli 디렉토리에서)
npm run dev

# 다른 터미널에서 상태 확인
curl http://localhost:8765/api/lsp/check-all

예상 결과:

{
  "servers": {
    "typescript": {
      "installed": true,
      "instructions": "npm install -g typescript-language-server typescript"
    },
    "ruby": {
      "installed": true,
      "instructions": "gem install solargraph"
    },
    "java": {
      "installed": false,
      "instructions": "Download from: https://download.eclipse.org/jdtls/milestones/?d"
    }
  },
  "allInstalled": false
}

사용 방법

1. PR 리뷰 시작

  1. PR 상세 페이지에서 "Start Review" 클릭
  2. AI Review 옵션 선택 (선택사항)
  3. 백그라운드에서 자동으로:
    • 워크트리 생성
    • 프로젝트 인덱싱 시작 (30초~2분)
    • LSP 클라이언트 연결

2. 코드 네비게이션 사용

브라우저 콘솔에서 확인

// LSP 클라이언트 상태
console.log('[LSP Client] typescript WebSocket connected');
console.log('[LSP Client] ruby WebSocket connected');

// 인덱싱 상태
console.log('[Index] Starting indexing for /path/to/worktree (branch-name)');
console.log('[Index] Found 523 symbols');
console.log('[Index] Indexing completed in 1234ms');

Monaco Editor에서 사용

현재 구현된 우클릭 메뉴:

  • Go to Definition (F12) - LSP 기반
  • Go to Type Definition - LSP 기반
  • Find All References (Shift+F12) - LSP 기반
  • Go to Implementations - LSP 기반
  • Go to Usage - 첫 번째 참조로 이동
  • Go to Super Method - 상위 메소드로 이동
  • Go to Test - 테스트 파일로 이동

3. 심볼 검색 (API)

# 프로젝트에서 'User' 클래스 찾기
curl "http://localhost:8765/api/index/search?projectPath=/path/to/worktree&branch=feature-branch&query=User"

# 파일 내 모든 심볼 조회
curl "http://localhost:8765/api/index/file-symbols?projectPath=/path/to/worktree&branch=feature-branch&filePath=app/models/user.rb"

성능 특성

인덱싱 속도

  • 소규모 프로젝트 (100개 파일): ~2-5초
  • 중규모 프로젝트 (1000개 파일): ~15-30초
  • 대규모 프로젝트 (10000개 파일): ~2-5분

검색 속도

  • 심볼 검색: < 50ms
  • 파일 내 심볼 조회: < 10ms
  • 사용처 찾기: < 100ms

캐싱

  • PR/브랜치별 캐싱
  • 커밋 해시 기반 자동 갱신
  • 재방문 시 즉시 사용 가능

아키텍처

데이터 흐름

PR Checkout
    ↓
Worktree 생성
    ↓
자동 인덱싱 시작 (백그라운드)
    ↓
├─ Git ls-files로 소스 파일 목록 조회
├─ 각 파일 파싱 (TypeScript/Ruby/Java)
├─ 심볼 추출 (클래스, 함수, 메소드 등)
└─ SQLite에 저장
    ↓
인덱스 완료
    ↓
사용자가 코드 네비게이션 사용
    ↓
├─ LSP 기반: Language Server에 요청
└─ Index 기반: SQLite 쿼리
    ↓
결과 표시

하이브리드 접근

  1. LSP 우선: 설치된 경우 LSP 사용 (가장 정확)
  2. Index 폴백: LSP 없을 때 인덱스 사용 (빠름)
  3. 동시 사용: LSP + Index 병행으로 최고 성능

디버깅

LSP 연결 문제

# Language Server 실행 테스트
typescript-language-server --stdio
solargraph stdio

# 포트 확인
lsof -i :8765

# WebSocket 연결 테스트
wscat -c ws://localhost:8765/lsp?workspaceRoot=/path&language=typescript

인덱싱 문제

# SQLite에서 인덱스 확인
sqlite3 ~/.highreview/highreview.db

-- 인덱스 상태 조회
SELECT * FROM project_indexes;

-- 심볼 개수 확인
SELECT language, COUNT(*) FROM indexed_symbols GROUP BY language;

-- 특정 파일의 심볼 조회
SELECT * FROM indexed_symbols WHERE file_path = 'app/models/user.rb';

브라우저 콘솔 로그

// LSP 상태
localStorage.getItem('lsp-status')

// 모든 LSP 로그 보기
console.log('[LSP]')

// 인덱싱 로그 보기
console.log('[Index]')

알려진 제한사항

  1. LSP 연결: 첫 연결 시 5-10초 소요
  2. 인덱싱 지연: 대규모 프로젝트는 최대 5분
  3. 메모리 사용: 10k+ 파일 프로젝트는 500MB+ 사용
  4. Ruby 정확도: Solargraph는 Rails 매직 메소드 일부 인식 못함
  5. Java 설정: JDTLS는 추가 설정 필요할 수 있음

향후 개선 사항

단기 (1-2주)

  • 진행 상황 표시 UI
  • 인덱싱 취소 기능
  • 심볼 검색 UI (Cmd+P 스타일)
  • 파일 변경 시 증분 인덱싱

중기 (1개월)

  • 타입 정보 인덱싱
  • 호출 그래프 생성
  • 의존성 분석
  • 코드 메트릭스

장기 (3개월+)

  • AI 기반 심볼 추천
  • 리팩토링 제안
  • 아키텍처 시각화
  • 실시간 협업 커서

문제 해결

"Language server not installed"

# 설치 확인
which typescript-language-server
which solargraph
which jdtls

# 재설치
npm install -g typescript-language-server typescript
gem install solargraph

"WebSocket connection failed"

# 서버 재시작
cd apps/cli
npm run dev

# 포트 충돌 확인
lsof -i :8765

"Indexing stuck"

# 로그 확인
tail -f /path/to/server.log

# 인덱스 초기화
rm ~/.highreview/highreview.db

"Symbol not found"

# 재인덱싱 트리거
curl -X POST http://localhost:8765/api/index/start \
  -H "Content-Type: application/json" \
  -d '{"projectPath":"/path/to/worktree","branch":"feature"}'

참고 자료

지원

문제 발생 시:

  1. 브라우저 콘솔 로그 확인
  2. 서버 로그 확인
  3. GitHub Issues에 로그와 함께 보고

구현 완료일: 2026-01-28 버전: 1.0.0 담당자: Claude Sonnet 4.5