window.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package hostbridge
  2. import (
  3. "context"
  4. "fmt"
  5. "log"
  6. proto "github.com/cline/grpc-go/host"
  7. )
  8. // WindowService implements the proto.WindowServiceServer interface
  9. type WindowService struct {
  10. proto.UnimplementedWindowServiceServer
  11. verbose bool
  12. }
  13. // NewWindowService creates a new WindowService
  14. func NewWindowService(verbose bool) *WindowService {
  15. return &WindowService{
  16. verbose: verbose,
  17. }
  18. }
  19. // ShowTextDocument opens a text document for viewing/editing
  20. func (s *WindowService) ShowTextDocument(ctx context.Context, req *proto.ShowTextDocumentRequest) (*proto.TextEditorInfo, error) {
  21. if s.verbose {
  22. log.Printf("ShowTextDocument called for path: %s", req.GetPath())
  23. }
  24. // For console implementation, we'll just log that we would open the document
  25. fmt.Printf("[Cline] Would open document: %s\n", req.GetPath())
  26. return &proto.TextEditorInfo{
  27. DocumentPath: req.GetPath(),
  28. IsActive: true,
  29. }, nil
  30. }
  31. // ShowOpenDialogue shows a file open dialog
  32. func (s *WindowService) ShowOpenDialogue(ctx context.Context, req *proto.ShowOpenDialogueRequest) (*proto.SelectedResources, error) {
  33. if s.verbose {
  34. log.Printf("ShowOpenDialogue called")
  35. }
  36. // For console implementation, return empty list (user cancelled)
  37. return &proto.SelectedResources{
  38. Paths: []string{},
  39. }, nil
  40. }
  41. // ShowMessage displays a message to the user
  42. func (s *WindowService) ShowMessage(ctx context.Context, req *proto.ShowMessageRequest) (*proto.SelectedResponse, error) {
  43. if s.verbose {
  44. log.Printf("ShowMessage called: %s", req.GetMessage())
  45. }
  46. // Display message to console
  47. fmt.Printf("[Cline] %s\n", req.GetMessage())
  48. return &proto.SelectedResponse{}, nil
  49. }
  50. // ShowInputBox shows an input dialog to the user
  51. func (s *WindowService) ShowInputBox(ctx context.Context, req *proto.ShowInputBoxRequest) (*proto.ShowInputBoxResponse, error) {
  52. if s.verbose {
  53. log.Printf("ShowInputBox called: %s", req.GetTitle())
  54. }
  55. // For console implementation, return empty response (user cancelled)
  56. return &proto.ShowInputBoxResponse{}, nil
  57. }
  58. // ShowSaveDialog shows a save file dialog
  59. func (s *WindowService) ShowSaveDialog(ctx context.Context, req *proto.ShowSaveDialogRequest) (*proto.ShowSaveDialogResponse, error) {
  60. if s.verbose {
  61. log.Printf("ShowSaveDialog called")
  62. }
  63. // For console implementation, return empty response (user cancelled)
  64. return &proto.ShowSaveDialogResponse{}, nil
  65. }
  66. // OpenFile opens a file in the editor
  67. func (s *WindowService) OpenFile(ctx context.Context, req *proto.OpenFileRequest) (*proto.OpenFileResponse, error) {
  68. if s.verbose {
  69. log.Printf("OpenFile called for path: %s", req.GetFilePath())
  70. }
  71. // For console implementation, just log that we would open the file
  72. fmt.Printf("[Cline] Would open file: %s\n", req.GetFilePath())
  73. return &proto.OpenFileResponse{}, nil
  74. }
  75. // GetOpenTabs returns a list of currently open tabs
  76. func (s *WindowService) GetOpenTabs(ctx context.Context, req *proto.GetOpenTabsRequest) (*proto.GetOpenTabsResponse, error) {
  77. if s.verbose {
  78. log.Printf("GetOpenTabs called")
  79. }
  80. // For console implementation, return empty list
  81. return &proto.GetOpenTabsResponse{
  82. Paths: []string{},
  83. }, nil
  84. }
  85. // GetVisibleTabs returns a list of currently visible tabs
  86. func (s *WindowService) GetVisibleTabs(ctx context.Context, req *proto.GetVisibleTabsRequest) (*proto.GetVisibleTabsResponse, error) {
  87. if s.verbose {
  88. log.Printf("GetVisibleTabs called")
  89. }
  90. // For console implementation, return empty list
  91. return &proto.GetVisibleTabsResponse{
  92. Paths: []string{},
  93. }, nil
  94. }
  95. // GetActiveEditor returns information about the current active editor
  96. func (s *WindowService) GetActiveEditor(ctx context.Context, req *proto.GetActiveEditorRequest) (*proto.GetActiveEditorResponse, error) {
  97. if s.verbose {
  98. log.Printf("GetActiveEditor called")
  99. }
  100. // Return empty response (no active file)
  101. return &proto.GetActiveEditorResponse{
  102. FilePath: nil,
  103. }, nil
  104. }