MCPcopy
hub / github.com/MadAppGang/dingo / handleDidOpen

Method handleDidOpen

pkg/lsp/server.go:492–561  ·  view source on GitHub ↗

handleDidOpen processes didOpen notifications

(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2.Request)

Source from the content-addressed store, hash-verified

490
491// handleDidOpen processes didOpen notifications
492func (s *Server) handleDidOpen(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2.Request) error {
493 var params protocol.DidOpenTextDocumentParams
494 if err := json.Unmarshal(req.Params(), &params); err != nil {
495 return reply(ctx, nil, err)
496 }
497
498 // CRITICAL FIX D1: When .dingo file opens, ensure .go file exists and open with gopls
499 // This is necessary for gopls to analyze the file and send diagnostics
500 if isDingoFile(params.TextDocument.URI) {
501 dingoPath := params.TextDocument.URI.Filename()
502 s.config.Logger.Infof("[didOpen] Opened .dingo file: %s", dingoPath)
503
504 // Run linter on open (provides immediate feedback)
505 go s.runLintOnOpen(ctx, params.TextDocument.URI)
506
507 // Initialize incremental parser for this document
508 if err := s.docManager.OpenDocument(string(params.TextDocument.URI), params.TextDocument.Text); err != nil {
509 s.config.Logger.Warnf("[didOpen] Failed to initialize incremental parser: %v", err)
510 } else {
511 s.config.Logger.Debugf("[didOpen] Incremental parser initialized")
512
513 // NOTE: We intentionally do NOT publish parse diagnostics for .dingo files.
514 // The incremental parser uses Go's parser which produces invalid errors
515 // for Dingo syntax (e.g., "missing ',' in type argument list" for Result[T, E]).
516 // Valid diagnostics come from:
517 // - lint: from the Dingo linter (runLintOnOpen above)
518 // - gopls: translated from gopls analyzing the transpiled .go file
519 // - transpile: from the Dingo transpiler (scheduleTranspileFromBuffer below)
520 s.config.Logger.Debugf("[didOpen] Skipping parse diagnostics (Go parser errors invalid for Dingo)")
521 }
522
523 // Check if .go file exists, if not auto-transpile
524 goPath := s.dingoToGoPath(dingoPath)
525 if _, err := os.Stat(goPath); os.IsNotExist(err) {
526 s.config.Logger.Infof("[didOpen] .go file missing, auto-transpiling: %s", dingoPath)
527
528 // Auto-transpile to generate .go file
529 if s.transpiler != nil {
530 s.transpiler.OnFileChange(ctx, dingoPath)
531 s.config.Logger.Infof("[didOpen] Auto-transpile completed (check for errors above)")
532 } else {
533 s.config.Logger.Warnf("[didOpen] Transpiler not available!")
534 }
535 } else {
536 s.config.Logger.Infof("[didOpen] .go file already exists: %s", goPath)
537 }
538
539 // Open corresponding .go file with gopls (if transpilation succeeded)
540 if err := s.openGoFileWithGopls(ctx, dingoPath); err != nil {
541 s.config.Logger.Warnf("[didOpen] Failed to open .go file with gopls: %v", err)
542 } else {
543 s.config.Logger.Infof("[didOpen] Successfully opened .go file with gopls")
544 }
545
546 // Schedule transpilation from buffer to get initial transpile diagnostics
547 // This catches syntax errors that the parser might miss
548 if s.config.AutoTranspile {
549 s.scheduleTranspileFromBuffer(params.TextDocument.URI, params.TextDocument.Text)

Callers 1

handleRequestMethod · 0.95

Calls 11

runLintOnOpenMethod · 0.95
dingoToGoPathMethod · 0.95
openGoFileWithGoplsMethod · 0.95
isDingoFileFunction · 0.85
OpenDocumentMethod · 0.80
OnFileChangeMethod · 0.80
InfofMethod · 0.65
WarnfMethod · 0.65
DebugfMethod · 0.65
DidOpenMethod · 0.45

Tested by

no test coverage detected