simple_workspace.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package hostbridge
  2. import (
  3. "context"
  4. "log"
  5. "os"
  6. "github.com/cline/grpc-go/cline"
  7. "github.com/cline/grpc-go/host"
  8. )
  9. // SimpleWorkspaceService implements a basic workspace service without complex dependencies
  10. type SimpleWorkspaceService struct {
  11. host.UnimplementedWorkspaceServiceServer
  12. verbose bool
  13. workspaces []string
  14. }
  15. // NewSimpleWorkspaceService creates a new SimpleWorkspaceService
  16. func NewSimpleWorkspaceService(verbose bool, workspaces []string) *SimpleWorkspaceService {
  17. return &SimpleWorkspaceService{
  18. verbose: verbose,
  19. workspaces: workspaces,
  20. }
  21. }
  22. // GetWorkspacePaths returns the workspace directory paths
  23. func (s *SimpleWorkspaceService) GetWorkspacePaths(ctx context.Context, req *host.GetWorkspacePathsRequest) (*host.GetWorkspacePathsResponse, error) {
  24. if s.verbose {
  25. log.Printf("GetWorkspacePaths called")
  26. }
  27. paths := []string{}
  28. if len(s.workspaces) == 0 {
  29. cwd, err := os.Getwd()
  30. if err != nil {
  31. return nil, err
  32. }
  33. paths = append(paths, cwd)
  34. } else {
  35. paths = s.workspaces
  36. }
  37. if s.verbose {
  38. log.Printf("Returning configured workspaces: %v", paths)
  39. }
  40. return &host.GetWorkspacePathsResponse{
  41. Paths: paths,
  42. }, nil
  43. }
  44. // SaveOpenDocumentIfDirty saves an open document if it has unsaved changes
  45. func (s *SimpleWorkspaceService) SaveOpenDocumentIfDirty(ctx context.Context, req *host.SaveOpenDocumentIfDirtyRequest) (*host.SaveOpenDocumentIfDirtyResponse, error) {
  46. if s.verbose {
  47. log.Printf("SaveOpenDocumentIfDirty called for path: %s", req.GetFilePath())
  48. }
  49. // For console implementation, we'll assume the document is already saved
  50. wasSaved := false
  51. return &host.SaveOpenDocumentIfDirtyResponse{
  52. WasSaved: &wasSaved,
  53. }, nil
  54. }
  55. // GetDiagnostics returns diagnostic information for a file - simplified version
  56. func (s *SimpleWorkspaceService) GetDiagnostics(ctx context.Context, req *host.GetDiagnosticsRequest) (*host.GetDiagnosticsResponse, error) {
  57. if s.verbose {
  58. log.Printf("GetDiagnostics called")
  59. }
  60. // For console implementation, return empty diagnostics
  61. return &host.GetDiagnosticsResponse{
  62. FileDiagnostics: []*cline.FileDiagnostics{},
  63. }, nil
  64. }
  65. // OpenProblemsPanel opens the problems panel - no-op for console implementation
  66. func (s *SimpleWorkspaceService) OpenProblemsPanel(ctx context.Context, req *host.OpenProblemsPanelRequest) (*host.OpenProblemsPanelResponse, error) {
  67. return &host.OpenProblemsPanelResponse{}, nil
  68. }
  69. // OpenInFileExplorerPanel opens a file/folder in the file explorer - no-op for console implementation
  70. func (s *SimpleWorkspaceService) OpenInFileExplorerPanel(ctx context.Context, req *host.OpenInFileExplorerPanelRequest) (*host.OpenInFileExplorerPanelResponse, error) {
  71. return &host.OpenInFileExplorerPanelResponse{}, nil
  72. }
  73. // OpenClineSidebarPanel opens the Cline sidebar panel - no-op for console implementation
  74. func (s *SimpleWorkspaceService) OpenClineSidebarPanel(ctx context.Context, req *host.OpenClineSidebarPanelRequest) (*host.OpenClineSidebarPanelResponse, error) {
  75. return &host.OpenClineSidebarPanelResponse{}, nil
  76. }
  77. // OpenTerminalPanel opens the terminal panel - no-op for console implementation
  78. func (s *SimpleWorkspaceService) OpenTerminalPanel(ctx context.Context, req *host.OpenTerminalRequest) (*host.OpenTerminalResponse, error) {
  79. return &host.OpenTerminalResponse{}, nil
  80. }