Skip to content

Commit f09a10c

Browse files
before converting to ts
1 parent a807196 commit f09a10c

File tree

8 files changed

+593
-27
lines changed

8 files changed

+593
-27
lines changed

Frontend/src/App/CodeEditor/MonacoEditor/MonacoEditor.tsx

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,97 @@ export default function MonacoEditor({
193193
return initialValue;
194194
};
195195

196+
// Add this to your MonacoEditor.tsx, updating your existing useEffect
197+
198+
useEffect(() => {
199+
if (editorRef.current) {
200+
// Configure TypeScript compiler options with more advanced settings
201+
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
202+
target: monaco.languages.typescript.ScriptTarget.Latest,
203+
allowNonTsExtensions: true,
204+
moduleResolution:
205+
monaco.languages.typescript.ModuleResolutionKind.NodeJs,
206+
module: monaco.languages.typescript.ModuleKind.ESNext,
207+
noEmit: true,
208+
typeRoots: ["node_modules/@types"],
209+
jsx: monaco.languages.typescript.JsxEmit.React,
210+
allowJs: true,
211+
checkJs: true, // Enable JavaScript validation
212+
strict: true,
213+
esModuleInterop: true,
214+
allowSyntheticDefaultImports: true,
215+
resolveJsonModule: true,
216+
noImplicitAny: false, // More permissive for quick editing
217+
});
218+
219+
// Set diagnostic options to show errors for imports
220+
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
221+
noSemanticValidation: false,
222+
noSyntaxValidation: false,
223+
noSuggestionDiagnostics: false,
224+
diagnosticCodesToIgnore: [],
225+
});
226+
227+
// Add basic browser and DOM typings
228+
monaco.languages.typescript.javascriptDefaults.addExtraLib(
229+
`
230+
// Basic DOM and browser APIs
231+
interface Window {
232+
document: Document;
233+
console: Console;
234+
localStorage: Storage;
235+
sessionStorage: Storage;
236+
setTimeout(callback: Function, ms: number): number;
237+
clearTimeout(id: number): void;
238+
setInterval(callback: Function, ms: number): number;
239+
clearInterval(id: number): void;
240+
}
241+
declare var window: Window;
242+
declare var document: Document;
243+
declare var console: Console;
244+
245+
// Common modules
246+
declare module "react" {
247+
export const useState: any;
248+
export const useEffect: any;
249+
export const useRef: any;
250+
export const useCallback: any;
251+
export const useMemo: any;
252+
export const useContext: any;
253+
export default any;
254+
}
255+
declare module "react-dom" {
256+
export const createRoot: any;
257+
export default any;
258+
}
259+
`,
260+
"ts:filename/lib.d.ts"
261+
);
262+
263+
// Register a mock file system for handling imports
264+
const fileMap = {
265+
"/src/utils.js": `
266+
export const add = (a, b) => a + b;
267+
export const subtract = (a, b) => a - b;
268+
export default { add, subtract };
269+
`,
270+
"/src/constants.js": `
271+
export const PI = 3.14159;
272+
export const MAX_VALUE = 1000;
273+
export default { PI, MAX_VALUE };
274+
`,
275+
};
276+
277+
// Register each mock file
278+
Object.entries(fileMap).forEach(([filePath, content]) => {
279+
monaco.languages.typescript.javascriptDefaults.addExtraLib(
280+
content,
281+
`file:${filePath}`
282+
);
283+
});
284+
}
285+
}, [editorRef.current]);
286+
196287
return (
197288
<div className="h-full flex flex-col">
198289
<CollaborativeCursor

Version_Engine/package-lock.json

Lines changed: 159 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Version_Engine/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"@supabase/supabase-js": "^2.57.2"
4+
}
5+
}
Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,91 @@
1-
const handleCommit = async (sessionId) => {
1+
import fs from "fs/promises";
2+
import path from "path";
3+
import { exec } from "child_process";
4+
import { promisify } from "util";
5+
import {
6+
getGitFolderFromStorage,
7+
checkGitFolderExists,
8+
saveGitFolderToStorage,
9+
saveCommitToDatabase,
10+
getLatestCommit,
11+
} from "../utils/database.js";
12+
13+
const execPromise = promisify(exec);
14+
15+
/**
16+
* Handles a commit operation for a session
17+
*
18+
* @param {string} sessionId - The session ID
19+
* @param {string} message - The commit message
20+
* @param {string} branchId - The branch ID
21+
* @returns {Promise<Object>} - Returns commit result
22+
*/
23+
const handleCommit = async (sessionId, message, branchId) => {
224
console.log(`Handling commit for session: ${sessionId}`);
3-
return "Commit job handled";
25+
26+
try {
27+
const gitRepoPath = await getGitFolderFromStorage(sessionId);
28+
29+
const gitInitialized = await checkGitFolderExists(sessionId);
30+
if (!gitInitialized) {
31+
console.log(
32+
`Git not initialized for session ${sessionId}, initializing now...`
33+
);
34+
await execPromise("git init", { cwd: gitRepoPath });
35+
await execPromise(
36+
'git config --local user.email "system@codespace.com"',
37+
{ cwd: gitRepoPath }
38+
);
39+
await execPromise('git config --local user.name "Codespace System"', {
40+
cwd: gitRepoPath,
41+
});
42+
}
43+
44+
await execPromise("git add .", { cwd: gitRepoPath });
45+
46+
const commitMessage = message || "Automated commit";
47+
const { stdout } = await execPromise(`git commit -m "${commitMessage}"`, {
48+
cwd: gitRepoPath,
49+
});
50+
51+
const commitHashMatch = stdout.match(/\[([^\]]+)\s([a-f0-9]{7,40})\]/);
52+
if (!commitHashMatch) {
53+
throw new Error("Could not extract commit hash from git output");
54+
}
55+
const commitHash = commitHashMatch[2];
56+
57+
const commitRecord = await saveCommitToDatabase(
58+
branchId,
59+
null,
60+
commitHash,
61+
commitMessage
62+
);
63+
64+
await saveGitFolderToStorage(sessionId);
65+
66+
return {
67+
success: true,
68+
message: "Commit successful",
69+
commitId: commitRecord.id,
70+
commitHash: commitHash,
71+
};
72+
} catch (error) {
73+
if (error.message && error.message.includes("nothing to commit")) {
74+
console.log("No changes to commit");
75+
return {
76+
success: false,
77+
message: "No changes to commit",
78+
error: "no_changes",
79+
};
80+
}
81+
82+
console.error("Error in handleCommit:", error);
83+
return {
84+
success: false,
85+
message: `Commit failed: ${error.message}`,
86+
error: error.message,
87+
};
88+
}
489
};
590

691
export default handleCommit;

Version_Engine/worker-git/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ new Worker(
2424
let msg = "Unknown job type";
2525
switch (job.data.type) {
2626
case "COMMIT":
27-
msg = await handleCommit(job.data);
27+
msg = await handleCommit(
28+
job.data.sessionId,
29+
job.data.message,
30+
job.data.branchId
31+
);
2832
break;
2933
case "ROLLBACK":
3034
msg = await handleRollback(job.data);

0 commit comments

Comments
 (0)