mirror of
https://github.com/aaif-goose/goose.git
synced 2026-07-03 14:10:03 +02:00
debug: replace complex spell checker with simple test version
- Replace Typo.js integration with simple hardcoded spell checker - Should catch 'gasdd2', 'recieve', 'seperate', 'definately', etc. - Add detailed logging to debug spell check process - This will help identify if issue is with Typo.js or the highlighting system - If this works, we know the highlighting is fine and can fix Typo.js separately
This commit is contained in:
@@ -41,93 +41,37 @@ const initSpellChecker = async (): Promise<Typo> => {
|
||||
};
|
||||
|
||||
export const checkSpelling = async (text: string): Promise<MisspelledWord[]> => {
|
||||
console.log('🔍 SIMPLE SPELL CHECK: Checking text:', text);
|
||||
const misspelledWords: MisspelledWord[] = [];
|
||||
|
||||
console.log('🔍 REAL SPELL CHECK: Starting spell check for:', text);
|
||||
// Simple test words that should definitely be caught
|
||||
const testMisspellings = ['gasdd2', 'recieve', 'seperate', 'definately', 'teh', 'wierd', 'freind', 'sdd', 'asdf'];
|
||||
|
||||
try {
|
||||
const checker = await initSpellChecker();
|
||||
console.log('🔍 REAL SPELL CHECK: Checker initialized:', !!checker);
|
||||
// Split text into words
|
||||
const words = text.split(/\s+/);
|
||||
let currentPos = 0;
|
||||
|
||||
for (const word of words) {
|
||||
const cleanWord = word.toLowerCase().replace(/[^a-z]/g, '');
|
||||
console.log('🔍 SIMPLE SPELL CHECK: Checking word:', cleanWord);
|
||||
|
||||
// Split text into words while preserving positions
|
||||
const wordRegex = /\b[a-zA-Z]+\b/g;
|
||||
let match;
|
||||
|
||||
while ((match = wordRegex.exec(text)) !== null) {
|
||||
const word = match[0];
|
||||
const start = match.index;
|
||||
const end = start + word.length;
|
||||
|
||||
console.log('🔍 REAL SPELL CHECK: Checking word:', word);
|
||||
|
||||
// Skip very short words and common abbreviations
|
||||
if (word.length < 3) {
|
||||
console.log('🔍 REAL SPELL CHECK: Skipping short word:', word);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip common technical terms that might not be in dictionary
|
||||
const technicalTerms = [
|
||||
'api', 'url', 'http', 'https', 'json', 'xml', 'css', 'html', 'js', 'ts', 'jsx', 'tsx',
|
||||
'npm', 'git', 'cli', 'ui', 'ux', 'db', 'sql', 'dev', 'prod', 'env', 'config', 'src',
|
||||
'app', 'web', 'www', 'com', 'org', 'net', 'io', 'ai', 'ml', 'gpu', 'cpu', 'ram',
|
||||
'github', 'gitlab', 'docker', 'aws', 'gcp', 'azure', 'oauth', 'jwt', 'cors', 'auth',
|
||||
'goose', 'chat', 'llm', 'gpt', 'claude', 'openai', 'anthropic', 'react', 'node',
|
||||
'typescript', 'javascript', 'python', 'rust', 'java', 'cpp', 'php', 'ruby', 'golang',
|
||||
'webpack', 'babel', 'eslint', 'prettier', 'tailwind', 'scss', 'sass', 'redux', 'graphql'
|
||||
];
|
||||
|
||||
if (technicalTerms.includes(word.toLowerCase())) {
|
||||
console.log('🔍 REAL SPELL CHECK: Skipping technical term:', word);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if the word is misspelled
|
||||
const isCorrect = checker.check(word);
|
||||
console.log('🔍 REAL SPELL CHECK: Word', word, 'is', isCorrect ? 'CORRECT' : 'MISSPELLED');
|
||||
|
||||
if (!isCorrect) {
|
||||
console.log('🔍 REAL SPELL CHECK: Found misspelling!', word);
|
||||
|
||||
// Get suggestions for the misspelled word
|
||||
const suggestions = checker.suggest ? checker.suggest(word, 3) : []; // Get up to 3 suggestions
|
||||
|
||||
if (testMisspellings.includes(cleanWord)) {
|
||||
const start = text.indexOf(word, currentPos);
|
||||
if (start !== -1) {
|
||||
misspelledWords.push({
|
||||
word: word,
|
||||
start: start,
|
||||
end: end,
|
||||
suggestions: suggestions
|
||||
end: start + word.length,
|
||||
suggestions: ['test', 'suggestion']
|
||||
});
|
||||
|
||||
console.log('🔍 REAL SPELL CHECK: Added misspelling:', { word, start, end, suggestions });
|
||||
console.log('🔍 SIMPLE SPELL CHECK: Found misspelling!', word, 'at position', start);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('🔍 REAL SPELL CHECK: Final misspelled words:', misspelledWords);
|
||||
|
||||
} catch (error) {
|
||||
console.error('🔍 REAL SPELL CHECK ERROR:', error);
|
||||
|
||||
// Fallback to simple spell check for testing
|
||||
console.log('🔍 REAL SPELL CHECK: Using fallback spell check');
|
||||
const simpleWords = ['recieve', 'seperate', 'definately', 'teh', 'wierd', 'freind'];
|
||||
const wordRegex = /\b[a-zA-Z]+\b/g;
|
||||
let match;
|
||||
|
||||
while ((match = wordRegex.exec(text)) !== null) {
|
||||
const word = match[0];
|
||||
if (simpleWords.includes(word.toLowerCase())) {
|
||||
misspelledWords.push({
|
||||
word: word,
|
||||
start: match.index,
|
||||
end: match.index + word.length,
|
||||
suggestions: []
|
||||
});
|
||||
console.log('🔍 FALLBACK SPELL CHECK: Found misspelling:', word);
|
||||
}
|
||||
}
|
||||
currentPos += word.length + 1; // +1 for space
|
||||
}
|
||||
|
||||
console.log('🔍 SIMPLE SPELL CHECK: Final result:', misspelledWords);
|
||||
return misspelledWords;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user