workspace.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package hostbridge
  2. import (
  3. "context"
  4. "log"
  5. "os"
  6. "github.com/cline/grpc-go/host"
  7. )
  8. // WorkspaceService implements the host.WorkspaceServiceServer interface
  9. type WorkspaceService struct {
  10. host.UnimplementedWorkspaceServiceServer
  11. coreAddress string
  12. verbose bool
  13. }
  14. // NewWorkspaceService creates a new WorkspaceService
  15. func NewWorkspaceService(coreAddress string, verbose bool) *WorkspaceService {
  16. return &WorkspaceService{
  17. coreAddress: coreAddress,
  18. verbose: verbose,
  19. }
  20. }
  21. // GetWorkspacePaths returns the workspace directory paths
  22. func (s *WorkspaceService) GetWorkspacePaths(ctx context.Context, req *host.GetWorkspacePathsRequest) (*host.GetWorkspacePathsResponse, error) {
  23. if s.verbose {
  24. log.Printf("GetWorkspacePaths called")
  25. }
  26. // Get current working directory as the workspace
  27. cwd, err := os.Getwd()
  28. if err != nil {
  29. return nil, err
  30. }
  31. return &host.GetWorkspacePathsResponse{
  32. Paths: []string{cwd},
  33. }, nil
  34. }
  35. // SaveOpenDocumentIfDirty saves an open document if it has unsaved changes
  36. func (s *WorkspaceService) SaveOpenDocumentIfDirty(ctx context.Context, req *host.SaveOpenDocumentIfDirtyRequest) (*host.SaveOpenDocumentIfDirtyResponse, error) {
  37. if s.verbose {
  38. log.Printf("SaveOpenDocumentIfDirty called for path: %s", req.GetPath())
  39. }
  40. // For console implementation, we'll assume the document is already saved
  41. // In a real implementation, we'd check if the file has unsaved changes
  42. return &host.SaveOpenDocumentIfDirtyResponse{
  43. WasSaved: false, // Assume no changes to save
  44. }, nil
  45. }
  46. // GetDiagnostics returns diagnostic information for a file
  47. func (s *WorkspaceService) GetDiagnostics(ctx context.Context, req *host.GetDiagnosticsRequest) (*host.GetDiagnosticsResponse, error) {
  48. if s.verbose {
  49. log.Printf("GetDiagnostics called for path: %s", req.GetPath())
  50. }
  51. // For console implementation, return empty diagnostics
  52. return &host.GetDiagnosticsResponse{
  53. Diagnostics: []*host.Diagnostic{},
  54. }, nil
  55. }