Mahdi Naser Moghadasi commited on
Commit ·
b890cbb
1
Parent(s): 9d69b49
Remove remaining JavaScript and C++ references from CodeEditor
Browse files- Remove javascript and cpp from languageMap
- Remove javascript and cpp from getCodeMirrorLanguage switch
- Remove javascript and cpp from getLanguageName
- Remove javascript and cpp from language selector dropdown
- Remove cpp-specific language prop handling
- Remove javascript and cpp cases from code-templates
- Remove javascript and cpp function name extraction from llmChecker
- Fixes build error: 'javascript' does not exist in type 'Record<SupportedLanguage, string>'
- components/CodeEditor.tsx +0 -2
- lib/code-templates.ts +0 -33
- lib/llmChecker.ts +0 -49
components/CodeEditor.tsx
CHANGED
|
@@ -145,9 +145,7 @@ export default function CodeEditor({
|
|
| 145 |
if (monaco && monaco.editor) {
|
| 146 |
const languageMap: Record<SupportedLanguage, string> = {
|
| 147 |
python: 'python',
|
| 148 |
-
javascript: 'javascript',
|
| 149 |
java: 'java',
|
| 150 |
-
cpp: 'cpp',
|
| 151 |
}
|
| 152 |
const model = editorRef.current.getModel()
|
| 153 |
if (model) {
|
|
|
|
| 145 |
if (monaco && monaco.editor) {
|
| 146 |
const languageMap: Record<SupportedLanguage, string> = {
|
| 147 |
python: 'python',
|
|
|
|
| 148 |
java: 'java',
|
|
|
|
| 149 |
}
|
| 150 |
const model = editorRef.current.getModel()
|
| 151 |
if (model) {
|
lib/code-templates.ts
CHANGED
|
@@ -65,39 +65,6 @@ export function generateStarterCode(question: Question, language: SupportedLangu
|
|
| 65 |
}
|
| 66 |
}`
|
| 67 |
|
| 68 |
-
case 'cpp':
|
| 69 |
-
// Infer types from parameter names (simplified)
|
| 70 |
-
const cppParams = params.map(p => {
|
| 71 |
-
if (p.includes('nums') || p.includes('arr') || p.includes('list') || p.includes('prices')) {
|
| 72 |
-
return `vector<int>& ${p}`
|
| 73 |
-
}
|
| 74 |
-
if (p.includes('target') || p.includes('val') || p.includes('num')) {
|
| 75 |
-
return `int ${p}`
|
| 76 |
-
}
|
| 77 |
-
return `int ${p}` // Default to int
|
| 78 |
-
}).join(', ')
|
| 79 |
-
|
| 80 |
-
// Infer return type from function name (simplified)
|
| 81 |
-
let cppReturnType = 'int'
|
| 82 |
-
if (functionName.includes('Sum') || functionName.includes('List') || functionName.includes('Array')) {
|
| 83 |
-
cppReturnType = 'vector<int>'
|
| 84 |
-
} else if (functionName.includes('Profit') || functionName.includes('Max') || functionName.includes('Min') || functionName.includes('Length') || functionName.includes('Count')) {
|
| 85 |
-
cppReturnType = 'int'
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
return `#include <vector>
|
| 89 |
-
#include <iostream>
|
| 90 |
-
#include <unordered_map>
|
| 91 |
-
using namespace std;
|
| 92 |
-
|
| 93 |
-
class Solution {
|
| 94 |
-
public:
|
| 95 |
-
${cppReturnType} ${functionName}(${cppParams}) {
|
| 96 |
-
// Write your code here
|
| 97 |
-
|
| 98 |
-
}
|
| 99 |
-
};`
|
| 100 |
-
|
| 101 |
default:
|
| 102 |
return question.starterCode
|
| 103 |
}
|
|
|
|
| 65 |
}
|
| 66 |
}`
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
default:
|
| 69 |
return question.starterCode
|
| 70 |
}
|
lib/llmChecker.ts
CHANGED
|
@@ -94,58 +94,9 @@ export async function executeAndCheckWithLLM(
|
|
| 94 |
if (language === 'python') {
|
| 95 |
const match = code.match(/def\s+(\w+)\s*\([^)]*\):/)
|
| 96 |
functionName = match ? match[1] : 'unknown'
|
| 97 |
-
} else if (language === 'javascript') {
|
| 98 |
-
const match = code.match(/(?:function\s+(\w+)|const\s+(\w+)\s*=\s*(?:\([^)]*\)\s*=>|function))/)
|
| 99 |
-
functionName = match ? (match[1] || match[2]) : 'unknown'
|
| 100 |
} else if (language === 'java') {
|
| 101 |
const match = code.match(/public\s+(?:static\s+)?\w+\s+(\w+)\s*\([^)]*\)/)
|
| 102 |
functionName = match ? match[1] : 'unknown'
|
| 103 |
-
} else if (language === 'cpp') {
|
| 104 |
-
// Try multiple patterns to extract function name from C++ code
|
| 105 |
-
// Pattern 1: Match function after public: (most common in LeetCode style)
|
| 106 |
-
// Handles multiline: public:\n int functionName(...)
|
| 107 |
-
let match = code.match(/public:\s*\n\s*(?:vector<int>|int|void|string|auto|double|float|bool|char)\s+(\w+)\s*\([^)]*\)/)
|
| 108 |
-
|
| 109 |
-
// Pattern 2: Match function on same line as public:
|
| 110 |
-
if (!match) {
|
| 111 |
-
match = code.match(/public:\s*(?:vector<int>|int|void|string|auto|double|float|bool|char)\s+(\w+)\s*\([^)]*\)/)
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
// Pattern 3: Direct function definition (returnType functionName(params))
|
| 115 |
-
if (!match) {
|
| 116 |
-
match = code.match(/(?:vector<int>|int|void|string|auto|double|float|bool|char)\s+(\w+)\s*\([^)]*\)/)
|
| 117 |
-
}
|
| 118 |
-
|
| 119 |
-
// Pattern 4: Any method in class Solution (more flexible, handles any whitespace)
|
| 120 |
-
if (!match) {
|
| 121 |
-
match = code.match(/class\s+Solution\s*\{[\s\S]*?(\w+)\s*\([^)]*\)/)
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
// Pattern 5: Look for function after any access specifier
|
| 125 |
-
if (!match) {
|
| 126 |
-
match = code.match(/(?:public|private|protected):\s*(?:vector<int>|int|void|string|auto|double|float|bool|char)\s+(\w+)\s*\(/)
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
functionName = match ? match[1] : 'unknown'
|
| 130 |
-
|
| 131 |
-
// Debug: log if we couldn't find function name
|
| 132 |
-
if (functionName === 'unknown') {
|
| 133 |
-
console.warn('Could not extract C++ function name from code:', code.substring(0, 300))
|
| 134 |
-
// Last resort: try to extract from Python starter code if available
|
| 135 |
-
if (questionStarterCode) {
|
| 136 |
-
const pythonMatch = questionStarterCode.match(/def\s+(\w+)\s*\(/)
|
| 137 |
-
if (pythonMatch) {
|
| 138 |
-
functionName = pythonMatch[1]
|
| 139 |
-
console.log('Fell back to Python function name from starter code:', functionName)
|
| 140 |
-
}
|
| 141 |
-
}
|
| 142 |
-
// Also try to extract from current code (might have Python remnants)
|
| 143 |
-
const pythonMatch = code.match(/def\s+(\w+)\s*\(/)
|
| 144 |
-
if (pythonMatch) {
|
| 145 |
-
functionName = pythonMatch[1]
|
| 146 |
-
console.log('Fell back to Python function name from code:', functionName)
|
| 147 |
-
}
|
| 148 |
-
}
|
| 149 |
}
|
| 150 |
|
| 151 |
// Final fallback: ALWAYS try to extract from Python starter code if available
|
|
|
|
| 94 |
if (language === 'python') {
|
| 95 |
const match = code.match(/def\s+(\w+)\s*\([^)]*\):/)
|
| 96 |
functionName = match ? match[1] : 'unknown'
|
|
|
|
|
|
|
|
|
|
| 97 |
} else if (language === 'java') {
|
| 98 |
const match = code.match(/public\s+(?:static\s+)?\w+\s+(\w+)\s*\([^)]*\)/)
|
| 99 |
functionName = match ? match[1] : 'unknown'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
}
|
| 101 |
|
| 102 |
// Final fallback: ALWAYS try to extract from Python starter code if available
|