improve copilot + fix minor bugs

This commit is contained in:
Ishaan Dey 2024-05-26 18:04:43 -07:00
parent fbb98ac3b0
commit 6285a68102
7 changed files with 57 additions and 47 deletions

View File

@ -19,7 +19,7 @@ export default {
{ {
role: "system", role: "system",
content: content:
"You are an expert coding assistant. You read code from a file, and you suggest new code to add to the file. You may be given instructions on what to generate, which you should follow. You should generate code that is correct, efficient, and follows best practices. You should also generate code that is clear and easy to read. When you generate code, you should only return the code, and nothing else. You should not include backticks in the code you generate.", "You are an expert coding assistant. You read code from a file, and you suggest new code to add to the file. You may be given instructions on what to generate, which you should follow. You should generate code that is CORRECT, efficient, and follows best practices. You may generate multiple lines of code if necessary. When you generate code, you should ONLY return the code, and nothing else. You MUST NOT include backticks in the code you generate.",
}, },
{ {
role: "user", role: "user",

View File

@ -17,8 +17,6 @@ import {
getSandboxFiles, getSandboxFiles,
renameFile, renameFile,
saveFile, saveFile,
stopServer,
testDescribe,
} from "./utils"; } from "./utils";
import { IDisposable, IPty, spawn } from "node-pty"; import { IDisposable, IPty, spawn } from "node-pty";
import { import {
@ -453,24 +451,22 @@ io.on("connection", async (socket) => {
); );
} }
const sockets = await io.fetchSockets(); // const sockets = await io.fetchSockets();
if (inactivityTimeout) { // if (inactivityTimeout) {
clearTimeout(inactivityTimeout); // clearTimeout(inactivityTimeout);
} // }
if (sockets.length === 0) { // if (sockets.length === 0) {
console.log("STARTING TIMER"); // console.log("STARTING TIMER");
inactivityTimeout = setTimeout(() => { // inactivityTimeout = setTimeout(() => {
io.fetchSockets().then(async (sockets) => { // io.fetchSockets().then(async (sockets) => {
if (sockets.length === 0) { // if (sockets.length === 0) {
console.log("Closing server due to inactivity."); // console.log("Server stopped", res);
const res = await stopServer(data.sandboxId); // }
console.log("Server stopped", res); // });
} // }, 20000);
}); // } else {
}, 20000); // console.log("number of sockets", sockets.length);
} else { // }
console.log("number of sockets", sockets.length);
}
}); });
}); });

View File

@ -67,8 +67,6 @@ export default async function CodePage({ params }: { params: { id: string } }) {
return notFound() return notFound()
} }
console.log("sandboxes: ", sandboxData)
return ( return (
<div className="overflow-hidden overscroll-none w-screen flex flex-col h-screen bg-background"> <div className="overflow-hidden overscroll-none w-screen flex flex-col h-screen bg-background">
<Room id={sandboxId}> <Room id={sandboxId}>

View File

@ -102,10 +102,6 @@
.inline-decoration::before { .inline-decoration::before {
content: "Generate"; content: "Generate";
color: #525252; color: #525252;
/* border: 1px solid #525252; */
/* padding: 2px 4px; */
/* border-radius: 4px; */
margin-left: 36px;
} }
.inline-decoration::after { .inline-decoration::after {
content: "⌘G"; content: "⌘G";

View File

@ -11,7 +11,7 @@ import * as Y from "yjs"
import LiveblocksProvider from "@liveblocks/yjs" import LiveblocksProvider from "@liveblocks/yjs"
import { MonacoBinding } from "y-monaco" import { MonacoBinding } from "y-monaco"
import { Awareness } from "y-protocols/awareness" import { Awareness } from "y-protocols/awareness"
import { TypedLiveblocksProvider, useRoom } from "@/liveblocks.config" import { TypedLiveblocksProvider, useRoom, useSelf } from "@/liveblocks.config"
import { import {
ResizableHandle, ResizableHandle,
@ -94,6 +94,7 @@ export default function CodeEditor({
// Liveblocks hooks // Liveblocks hooks
const room = useRoom() const room = useRoom()
const [provider, setProvider] = useState<TypedLiveblocksProvider>() const [provider, setProvider] = useState<TypedLiveblocksProvider>()
const userInfo = useSelf((me) => me.info)
// Refs for libraries / features // Refs for libraries / features
const editorContainerRef = useRef<HTMLDivElement>(null) const editorContainerRef = useRef<HTMLDivElement>(null)
@ -263,6 +264,14 @@ export default function CodeEditor({
if (!ai) return if (!ai) return
const model = editorRef?.getModel()
const line = model?.getLineContent(cursorLine)
if (line === undefined || line.trim() !== "") {
decorations.instance?.clear()
return
}
if (decorations.instance) { if (decorations.instance) {
decorations.instance.set(decorations.options) decorations.instance.set(decorations.options)
} else { } else {
@ -663,7 +672,9 @@ export default function CodeEditor({
) : // Note clerk.loaded is required here due to a bug: https://github.com/clerk/javascript/issues/1643 ) : // Note clerk.loaded is required here due to a bug: https://github.com/clerk/javascript/issues/1643
clerk.loaded ? ( clerk.loaded ? (
<> <>
{provider ? <Cursors yProvider={provider} /> : null} {provider && userInfo ? (
<Cursors yProvider={provider} userInfo={userInfo} />
) : null}
<Editor <Editor
height="100%" height="100%"
language={editorLanguage} language={editorLanguage}

View File

@ -7,11 +7,18 @@ import {
} from "@/liveblocks.config" } from "@/liveblocks.config"
import { colors } from "@/lib/colors" import { colors } from "@/lib/colors"
export function Cursors({ yProvider }: { yProvider: TypedLiveblocksProvider }) { export function Cursors({
yProvider,
userInfo,
}: {
yProvider: TypedLiveblocksProvider
userInfo: {
name: string
email: string
color: "red" | "orange" | "yellow" | "green" | "blue" | "purple" | "pink"
}
}) {
// Get user info from Liveblocks authentication endpoint // Get user info from Liveblocks authentication endpoint
const userInfo = useSelf((me) => me.info)
if (!userInfo) return null
const [awarenessUsers, setAwarenessUsers] = useState<AwarenessList>([]) const [awarenessUsers, setAwarenessUsers] = useState<AwarenessList>([])

View File

@ -1,15 +1,17 @@
import Image from "next/image"; "use client"
import Logo from "@/assets/logo.svg";
import { Skeleton } from "@/components/ui/skeleton"; import Image from "next/image"
import { Loader2, X } from "lucide-react"; import Logo from "@/assets/logo.svg"
import { Skeleton } from "@/components/ui/skeleton"
import { Loader2, X } from "lucide-react"
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
DialogDescription, DialogDescription,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@/components/ui/dialog"; } from "@/components/ui/dialog"
import { useEffect, useState } from "react"; import { useEffect, useState } from "react"
export default function Loading({ export default function Loading({
didFail = false, didFail = false,
@ -17,18 +19,18 @@ export default function Loading({
text = "", text = "",
description = "", description = "",
}: { }: {
didFail?: boolean; didFail?: boolean
withNav?: boolean; withNav?: boolean
text?: string; text?: string
description?: string; description?: string
}) { }) {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false)
useEffect(() => { useEffect(() => {
if (text) { if (text) {
setOpen(true); setOpen(true)
} }
}, [text]); }, [text])
return ( return (
<div className="overflow-hidden overscroll-none w-screen flex flex-col justify-center items-center z-0 h-screen bg-background relative"> <div className="overflow-hidden overscroll-none w-screen flex flex-col justify-center items-center z-0 h-screen bg-background relative">
@ -98,5 +100,5 @@ export default function Loading({
</div> </div>
</div> </div>
</div> </div>
); )
} }