Skip to content
Merged
3 changes: 0 additions & 3 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ func main() {
// Obtener el router configurado con CORS y rutas
r := routes.SetupRouter()

// No es necesario configurar rutas aquí, ya están en SetupRouter()
// ¡Elimina estas líneas!

log.Println("Servidor escuchando en :8080")
log.Fatal(r.Run(":8080"))
}
6 changes: 6 additions & 0 deletions backend/routes/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func SetupRouter() *gin.Engine {
c.String(200, "Bienvenido a la API de Aprendizaje Python")
})

// Ruta LSP para WebSocket
r.GET("/lsp", LSPHandler)

// Ruta para verificar Python
r.GET("/verify", VerificarPythonHandler)

// Configurar rutas de API
api := r.Group("/api")

Expand Down
13 changes: 7 additions & 6 deletions backend/routes/index.routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ package routes

import (
"fmt"
"net/http"
"os/exec"

"github.com/gin-gonic/gin"
)

func Homehandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("esto vien de la carpeta routesss"))
func Homehandler(c *gin.Context) {
c.String(200, "esto vien de la carpeta routesss")
}

func VerificarPythonHandler(w http.ResponseWriter, r *http.Request) {
func VerificarPythonHandler(c *gin.Context) {
rutaArchivo := "test.py" // En la práctica lo recibes por POST o desde un path

cmd := exec.Command("pyright", rutaArchivo)
salida, err := cmd.CombinedOutput()
if err != nil {
http.Error(w, fmt.Sprintf("Errores detectados:\n%s", salida), http.StatusBadRequest)
c.String(400, fmt.Sprintf("Errores detectados:\n%s", salida))
return
}

w.Write([]byte(fmt.Sprintf("Sin errores:\n%s", salida)))
c.String(200, fmt.Sprintf("Sin errores:\n%s", salida))
}
18 changes: 14 additions & 4 deletions backend/routes/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ import (
"net/http"
"os/exec"

"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
)

var upgrader = websocket.Upgrader{}
var upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
return true // Permitir todas las conexiones
},
}

func LspHandler(w http.ResponseWriter, r *http.Request) {
conn, err := upgrader.Upgrade(w, r, nil)
// LSPHandler maneja las conexiones WebSocket para el Language Server Protocol
func LSPHandler(c *gin.Context) {
// Obtener la conexión WebSocket desde Gin
conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
if err != nil {
log.Println("Error al actualizar a WebSocket:", err)
return
}
defer conn.Close()

// Iniciar el servidor Pyright
cmd := exec.Command("pyright-langserver", "--stdio")
stdin, err := cmd.StdinPipe()
if err != nil {
Expand All @@ -35,6 +43,7 @@ func LspHandler(w http.ResponseWriter, r *http.Request) {
return
}

// Goroutine para leer mensajes del WebSocket y enviarlos a Pyright
go func() {
for {
_, message, err := conn.ReadMessage()
Expand All @@ -50,7 +59,8 @@ func LspHandler(w http.ResponseWriter, r *http.Request) {
}
}()

buf := make([]byte, 1024)
// Leer respuestas de Pyright y enviarlas al WebSocket
buf := make([]byte, 4096)
for {
n, err := stdout.Read(buf)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion frontend/angular/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@
"node_modules/codemirror/lib/codemirror.css",
"node_modules/codemirror/theme/material.css",
"node_modules/codemirror/addon/lint/lint.css",
"node_modules/codemirror/addon/hint/show-hint.css",
"src/styles.scss"
],
"scripts": [
"node_modules/codemirror/lib/codemirror.js",
"node_modules/codemirror/mode/python/python.js",
"node_modules/codemirror/addon/display/placeholder.js"
"node_modules/codemirror/addon/display/placeholder.js",
"node_modules/codemirror/addon/hint/show-hint.js",
"node_modules/codemirror/addon/hint/anyword-hint.js"
]
},
"configurations": {
Expand Down
Loading
Loading