mirror of
https://github.com/zilliztech/claude-context.git
synced 2025-10-06 01:10:02 +03:00
refactor import path to code-context
Signed-off-by: ChengZi <chen.zhang@zilliz.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { CodeIndexer, MilvusVectorDatabase, MilvusRestfulVectorDatabase, AstCodeSplitter, LangChainCodeSplitter } from '@code-indexer/core';
|
||||
import { CodeIndexer, MilvusVectorDatabase, MilvusRestfulVectorDatabase, AstCodeSplitter, LangChainCodeSplitter } from '@zilliz/code-context-core';
|
||||
import * as path from 'path';
|
||||
|
||||
// Try to load .env file
|
||||
|
||||
@@ -21,9 +21,9 @@ import {
|
||||
ListToolsRequestSchema,
|
||||
CallToolRequestSchema
|
||||
} from "@modelcontextprotocol/sdk/types.js";
|
||||
import { CodeIndexer, SemanticSearchResult } from "@code-indexer/core";
|
||||
import { OpenAIEmbedding, VoyageAIEmbedding, GeminiEmbedding, OllamaEmbedding } from "@code-indexer/core";
|
||||
import { MilvusVectorDatabase } from "@code-indexer/core";
|
||||
import { CodeIndexer, SemanticSearchResult } from "@zilliz/code-context-core";
|
||||
import { OpenAIEmbedding, VoyageAIEmbedding, GeminiEmbedding, OllamaEmbedding } from "@zilliz/code-context-core";
|
||||
import { MilvusVectorDatabase } from "@zilliz/code-context-core";
|
||||
import * as path from "path";
|
||||
import * as fs from "fs";
|
||||
import * as os from "os";
|
||||
@@ -430,7 +430,7 @@ class CodeIndexerMcpServer {
|
||||
}
|
||||
|
||||
// Initialize file synchronizer with proper ignore patterns
|
||||
const { FileSynchronizer } = await import("@code-indexer/core");
|
||||
const { FileSynchronizer } = await import("@zilliz/code-context-core");
|
||||
const ignorePatterns = this.codeIndexer['ignorePatterns'] || [];
|
||||
console.log(`[INDEX] Using ignore patterns: ${ignorePatterns.join(', ')}`);
|
||||
const synchronizer = new FileSynchronizer(absolutePath, ignorePatterns);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { CodeIndexer } from '@code-indexer/core';
|
||||
import { CodeIndexer } from '@zilliz/code-context-core';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as crypto from 'crypto';
|
||||
@@ -118,7 +118,7 @@ export class IndexCommand {
|
||||
|
||||
// Initialize file synchronizer
|
||||
progress.report({ increment: 0, message: 'Initializing file synchronizer...' });
|
||||
const { FileSynchronizer } = await import("@code-indexer/core");
|
||||
const { FileSynchronizer } = await import("@zilliz/code-context-core");
|
||||
const synchronizer = new FileSynchronizer(selectedFolder.uri.fsPath, this.codeIndexer['ignorePatterns'] || []);
|
||||
await synchronizer.initialize();
|
||||
// Store synchronizer in the indexer's internal map using the same collection name generation logic
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { CodeIndexer, SearchQuery, SemanticSearchResult } from '@code-indexer/core';
|
||||
import { CodeIndexer, SearchQuery, SemanticSearchResult } from '@zilliz/code-context-core';
|
||||
import * as path from 'path';
|
||||
|
||||
export class SearchCommand {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { CodeIndexer } from '@code-indexer/core';
|
||||
import { CodeIndexer } from '@zilliz/code-context-core';
|
||||
import * as fs from 'fs';
|
||||
|
||||
export class SyncCommand {
|
||||
@@ -43,7 +43,7 @@ export class SyncCommand {
|
||||
}
|
||||
|
||||
console.log(`[SYNC] Starting sync for current workspace: ${codebasePath}`);
|
||||
|
||||
|
||||
this.isSyncing = true;
|
||||
|
||||
try {
|
||||
@@ -75,7 +75,7 @@ export class SyncCommand {
|
||||
|
||||
if (syncStats) {
|
||||
const totalChanges = syncStats.added + syncStats.removed + syncStats.modified;
|
||||
|
||||
|
||||
if (totalChanges > 0) {
|
||||
vscode.window.showInformationMessage(
|
||||
`✅ Sync complete!\n\nAdded: ${syncStats.added}, Removed: ${syncStats.removed}, Modified: ${syncStats.modified} files.`
|
||||
@@ -101,9 +101,9 @@ export class SyncCommand {
|
||||
*/
|
||||
async startAutoSync(intervalMinutes: number = 5): Promise<vscode.Disposable> {
|
||||
console.log(`[AUTO-SYNC] Starting auto-sync with ${intervalMinutes} minute interval`);
|
||||
|
||||
|
||||
const intervalMs = intervalMinutes * 60 * 1000;
|
||||
|
||||
|
||||
const interval = setInterval(async () => {
|
||||
try {
|
||||
console.log('[AUTO-SYNC] Running periodic sync...');
|
||||
@@ -144,17 +144,17 @@ export class SyncCommand {
|
||||
}
|
||||
|
||||
console.log(`[AUTO-SYNC] Starting silent sync for: ${codebasePath}`);
|
||||
|
||||
|
||||
this.isSyncing = true;
|
||||
|
||||
try {
|
||||
const syncStats = await this.codeIndexer.reindexByChange(codebasePath);
|
||||
|
||||
|
||||
const totalChanges = syncStats.added + syncStats.removed + syncStats.modified;
|
||||
|
||||
|
||||
if (totalChanges > 0) {
|
||||
console.log(`[AUTO-SYNC] Silent sync complete for '${codebasePath}'. Added: ${syncStats.added}, Removed: ${syncStats.removed}, Modified: ${syncStats.modified}`);
|
||||
|
||||
|
||||
// Show a subtle notification for auto-sync changes
|
||||
vscode.window.showInformationMessage(
|
||||
`🔄 Index auto-updated: ${totalChanges} file changes detected`,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { OpenAIEmbedding, OpenAIEmbeddingConfig, VoyageAIEmbedding, VoyageAIEmbeddingConfig, OllamaEmbedding, OllamaEmbeddingConfig, GeminiEmbedding, GeminiEmbeddingConfig, MilvusConfig, SplitterType, SplitterConfig, AstCodeSplitter, LangChainCodeSplitter } from '@code-indexer/core';
|
||||
import { OpenAIEmbedding, OpenAIEmbeddingConfig, VoyageAIEmbedding, VoyageAIEmbeddingConfig, OllamaEmbedding, OllamaEmbeddingConfig, GeminiEmbedding, GeminiEmbeddingConfig, MilvusConfig, SplitterType, SplitterConfig, AstCodeSplitter, LangChainCodeSplitter } from '@zilliz/code-context-core';
|
||||
|
||||
// Simplified Milvus configuration interface for frontend
|
||||
export interface MilvusWebConfig {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { SearchCommand } from './commands/searchCommand';
|
||||
import { IndexCommand } from './commands/indexCommand';
|
||||
import { SyncCommand } from './commands/syncCommand';
|
||||
import { ConfigManager } from './config/configManager';
|
||||
import { CodeIndexer, OpenAIEmbedding, VoyageAIEmbedding, GeminiEmbedding, MilvusRestfulVectorDatabase, AstCodeSplitter, LangChainCodeSplitter, SplitterType } from '@code-indexer/core';
|
||||
import { CodeIndexer, OpenAIEmbedding, VoyageAIEmbedding, GeminiEmbedding, MilvusRestfulVectorDatabase, AstCodeSplitter, LangChainCodeSplitter, SplitterType } from '@zilliz/code-context-core';
|
||||
|
||||
let semanticSearchProvider: SemanticSearchViewProvider;
|
||||
let searchCommand: SearchCommand;
|
||||
|
||||
@@ -48,7 +48,7 @@ class AstCodeSplitterStub {
|
||||
this.loadedLanguages = new Map();
|
||||
// Import LangChain splitter as fallback
|
||||
try {
|
||||
const { LangChainCodeSplitter } = require('@code-indexer/core');
|
||||
const { LangChainCodeSplitter } = require('@zilliz/code-context-core');
|
||||
this.fallbackSplitter = new LangChainCodeSplitter(chunkSize, chunkOverlap);
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize LangChain fallback splitter:', error);
|
||||
@@ -142,7 +142,7 @@ class AstCodeSplitterStub {
|
||||
normalizeLanguage(language) {
|
||||
const langMap = {
|
||||
'js': 'javascript',
|
||||
'ts': 'typescript',
|
||||
'ts': 'typescript',
|
||||
'py': 'python',
|
||||
'c++': 'cpp',
|
||||
'c': 'cpp',
|
||||
@@ -158,7 +158,7 @@ class AstCodeSplitterStub {
|
||||
console.log('[AST Splitter] web-tree-sitter not available, using LangChain fallback');
|
||||
return this.fallbackSplitter.split(code, language, filePath);
|
||||
}
|
||||
|
||||
|
||||
const languageParser = await this.loadLanguage(language);
|
||||
if (!languageParser) {
|
||||
console.log(`[AST Splitter] Language ${language} not supported by web AST, using LangChain fallback for: ${filePath || 'unknown'}`);
|
||||
@@ -180,13 +180,13 @@ class AstCodeSplitterStub {
|
||||
}
|
||||
|
||||
console.log(`🌳 [AST Splitter] Using web-tree-sitter for ${language} file: ${filePath || 'unknown'}`);
|
||||
|
||||
|
||||
const normalizedLang = this.normalizeLanguage(language);
|
||||
const nodeTypes = SPLITTABLE_NODE_TYPES[normalizedLang] || [];
|
||||
|
||||
|
||||
// Extract chunks based on AST nodes
|
||||
const chunks = this.extractChunks(tree.rootNode, code, nodeTypes, language, filePath);
|
||||
|
||||
|
||||
// If chunks are too large, split them further
|
||||
const refinedChunks = await this.refineChunks(chunks, code);
|
||||
|
||||
@@ -203,7 +203,7 @@ class AstCodeSplitterStub {
|
||||
|
||||
// Find all splittable nodes
|
||||
const splittableNodes = this.findSplittableNodes(node, nodeTypes);
|
||||
|
||||
|
||||
if (splittableNodes.length === 0) {
|
||||
// No splittable nodes found, treat as single chunk
|
||||
return [{
|
||||
@@ -222,7 +222,7 @@ class AstCodeSplitterStub {
|
||||
for (const astNode of splittableNodes) {
|
||||
const startLine = astNode.startPosition.row + 1;
|
||||
const endLine = astNode.endPosition.row + 1;
|
||||
|
||||
|
||||
// Add any content between previous node and current node
|
||||
if (startLine > lastEndLine + 1) {
|
||||
const betweenContent = lines.slice(lastEndLine, startLine - 1).join('\n');
|
||||
@@ -276,7 +276,7 @@ class AstCodeSplitterStub {
|
||||
|
||||
findSplittableNodes(node, nodeTypes) {
|
||||
const nodes = [];
|
||||
|
||||
|
||||
// Check if current node is splittable
|
||||
if (nodeTypes.includes(node.type)) {
|
||||
nodes.push(node);
|
||||
@@ -303,11 +303,11 @@ class AstCodeSplitterStub {
|
||||
// Chunk is too large, split it using LangChain splitter
|
||||
console.log(`📏 [AST Splitter] Chunk too large (${chunk.content.length} chars), using LangChain for refinement`);
|
||||
const subChunks = await this.fallbackSplitter.split(
|
||||
chunk.content,
|
||||
chunk.metadata.language,
|
||||
chunk.content,
|
||||
chunk.metadata.language,
|
||||
chunk.metadata.filePath
|
||||
);
|
||||
|
||||
|
||||
// Adjust line numbers for sub-chunks
|
||||
let currentStartLine = chunk.metadata.startLine;
|
||||
for (const subChunk of subChunks) {
|
||||
|
||||
@@ -25,10 +25,10 @@ module.exports = {
|
||||
// support reading TypeScript and JavaScript files
|
||||
extensions: ['.ts', '.js'],
|
||||
alias: {
|
||||
'@code-indexer/core': path.resolve(__dirname, '../core/dist/index.js'),
|
||||
'@code-indexer/core/dist/splitter': path.resolve(__dirname, '../core/dist/splitter'),
|
||||
'@code-indexer/core/dist/embedding': path.resolve(__dirname, '../core/dist/embedding'),
|
||||
'@code-indexer/core/dist/vectordb': path.resolve(__dirname, '../core/dist/vectordb')
|
||||
'@zilliz/code-context-core': path.resolve(__dirname, '../core/dist/index.js'),
|
||||
'@zilliz/code-context-core/dist/splitter': path.resolve(__dirname, '../core/dist/splitter'),
|
||||
'@zilliz/code-context-core/dist/embedding': path.resolve(__dirname, '../core/dist/embedding'),
|
||||
'@zilliz/code-context-core/dist/vectordb': path.resolve(__dirname, '../core/dist/vectordb')
|
||||
}
|
||||
},
|
||||
module: {
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@code-indexer/core": [
|
||||
"@zilliz/code-context-core": [
|
||||
"./packages/core/src"
|
||||
],
|
||||
"@code-indexer/core/*": [
|
||||
"@zilliz/code-context-core/*": [
|
||||
"./packages/core/src/*"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user