diff --git a/cmd/analyzer/main.go b/cmd/analyzer/main.go index 8bfa071c..ff436e67 100644 --- a/cmd/analyzer/main.go +++ b/cmd/analyzer/main.go @@ -131,7 +131,6 @@ func AnalysisCmd() *cobra.Command { builtinConfigs := []provider.InitConfig{} providerLocations := []string{} for _, config := range configs { - fmt.Printf("here: %#v\n", config) config.ContextLines = contextLines for _, ind := range config.InitConfig { providerLocations = append(providerLocations, ind.Location) @@ -251,7 +250,6 @@ func AnalysisCmd() *cobra.Command { } if builtinClient, ok := needProviders["builtin"]; ok { - fmt.Printf("here: %v\n", builtinClient) if _, err = builtinClient.ProviderInit(ctx, builtinConfigs); err != nil { errLog.Error(err, "unable to init builtin provider") os.Exit(1) diff --git a/external-providers/dotnet-external-provider/main.go b/external-providers/dotnet-external-provider/main.go index 7e7c4adf..16fe514e 100644 --- a/external-providers/dotnet-external-provider/main.go +++ b/external-providers/dotnet-external-provider/main.go @@ -7,7 +7,7 @@ import ( "os" "github.com/bombsimon/logrusr/v3" - "github.com/konveyor/analyzer-lsp/provider" + server "github.com/konveyor/analyzer-lsp/provider/server" "github.com/konveyor/dotnet-external-provider/pkg/dotnet" "github.com/sirupsen/logrus" ) @@ -55,7 +55,7 @@ func main() { secret = *secretKey } - s := provider.NewServer(client, *port, c, k, secret, log) + s := server.NewServer(client, *port, c, k, secret, 0, log) ctx := context.TODO() s.Start(ctx) } diff --git a/external-providers/generic-external-provider/main.go b/external-providers/generic-external-provider/main.go index 4d86ed82..12855cb8 100644 --- a/external-providers/generic-external-provider/main.go +++ b/external-providers/generic-external-provider/main.go @@ -7,7 +7,7 @@ import ( "os" "github.com/bombsimon/logrusr/v3" - "github.com/konveyor/analyzer-lsp/provider" + "github.com/konveyor/analyzer-lsp/provider/server" "github.com/konveyor/generic-external-provider/pkg/generic_external_provider" "github.com/sirupsen/logrus" ) @@ -72,7 +72,7 @@ func main() { secret = *secretKey } - s := provider.NewServer(client, *port, c, k, secret, log) + s := server.NewServer(client, *port, c, k, secret, 0, log) ctx := context.TODO() s.Start(ctx) } diff --git a/external-providers/yq-external-provider/main.go b/external-providers/yq-external-provider/main.go index c47c587c..0779187a 100644 --- a/external-providers/yq-external-provider/main.go +++ b/external-providers/yq-external-provider/main.go @@ -7,7 +7,7 @@ import ( "os" "github.com/bombsimon/logrusr/v3" - "github.com/konveyor/analyzer-lsp/provider" + "github.com/konveyor/analyzer-lsp/provider/server" "github.com/konveyor/yq-external-provider/pkg/yq_provider" "github.com/sirupsen/logrus" ) @@ -51,7 +51,7 @@ func main() { secret = *secretKey } - s := provider.NewServer(client, *port, c, k, secret, log) + s := server.NewServer(client, *port, c, k, secret, 0, log) ctx := context.TODO() s.Start(ctx) } diff --git a/provider/internal/builtin/provider.go b/provider/internal/builtin/provider.go index fec3e633..753e1677 100644 --- a/provider/internal/builtin/provider.go +++ b/provider/internal/builtin/provider.go @@ -1,14 +1,19 @@ package builtin import ( + "bufio" "context" "fmt" "os" + "strconv" + "strings" "github.com/go-logr/logr" + "github.com/konveyor/analyzer-lsp/engine" "github.com/konveyor/analyzer-lsp/provider" "github.com/konveyor/analyzer-lsp/provider/grpc" "github.com/swaggest/openapi-go/openapi3" + "go.lsp.dev/uri" "gopkg.in/yaml.v2" ) @@ -66,7 +71,10 @@ type builtinProvider struct { tags map[string]bool provider.UnimplementedDependenciesComponent - clients []provider.ServiceClient + clients []provider.ServiceClient + grpcProviders []engine.CodeSnip + + contextLines int } func NewBuiltinProvider(config provider.Config, log logr.Logger) *builtinProvider { @@ -171,6 +179,8 @@ func (p *builtinProvider) ProviderInit(ctx context.Context, additionalInitConfig if err != nil { return nil, err } + // We know that this should work + p.grpcProviders = append(p.grpcProviders, grpcClient.(engine.CodeSnip)) client, _, err := grpcClient.Init(ctx, p.log, c) if err != nil { @@ -190,10 +200,55 @@ func (p *builtinProvider) ProviderInit(ctx context.Context, additionalInitConfig } } - fmt.Printf("%#v", p.clients) return nil, nil } +func (p *builtinProvider) GetCodeSnip(u uri.URI, loc engine.Location) (string, error) { + for _, snip := range p.grpcProviders { + s, err := snip.GetCodeSnip(u, loc) + // If we can't find if in any GRPC providers we will try locally + if err != nil { + p.log.Error(err, "unable to get snip") + continue + } + fmt.Printf("here: %v", s) + return s, err + } + if !strings.Contains(string(u), uri.FileScheme) { + return "", fmt.Errorf("invalid file uri") + } + snip, err := p.scanFile(u.Filename(), loc) + if err != nil { + return "", err + } + return snip, nil +} + +func (p *builtinProvider) scanFile(path string, loc engine.Location) (string, error) { + readFile, err := os.Open(path) + if err != nil { + p.log.V(5).Error(err, "Unable to read file") + return "", err + } + defer readFile.Close() + + scanner := bufio.NewScanner(readFile) + lineNumber := 0 + codeSnip := "" + paddingSize := len(strconv.Itoa(loc.EndPosition.Line + p.contextLines)) + for scanner.Scan() { + if (lineNumber - p.contextLines) == loc.EndPosition.Line { + codeSnip = codeSnip + fmt.Sprintf("%*d %v", paddingSize, lineNumber+1, scanner.Text()) + break + } + if (lineNumber + p.contextLines) >= loc.StartPosition.Line { + codeSnip = codeSnip + fmt.Sprintf("%*d %v\n", paddingSize, lineNumber+1, scanner.Text()) + } + lineNumber += 1 + } + return codeSnip, nil +} + // We don't need to init anything func (p *builtinProvider) Init(ctx context.Context, log logr.Logger, config provider.InitConfig) (provider.ServiceClient, provider.InitConfig, error) { if config.AnalysisMode != provider.AnalysisMode("") { diff --git a/provider/internal/builtin/service_client.go b/provider/internal/builtin/service_client.go index d5565211..bccd48a2 100644 --- a/provider/internal/builtin/service_client.go +++ b/provider/internal/builtin/service_client.go @@ -49,7 +49,6 @@ func convertToInterface(s []string) []interface{} { return n } func (p *builtinServiceClient) Evaluate(ctx context.Context, cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { - fmt.Printf("\nhere: %v\n", cap) var cond builtinCondition err := yaml.Unmarshal(conditionInfo, &cond) if err != nil { diff --git a/provider/internal/grpc/library.pb.go b/provider/internal/grpc/library.pb.go index a50dc005..783410ef 100644 --- a/provider/internal/grpc/library.pb.go +++ b/provider/internal/grpc/library.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.30.0 -// protoc v5.27.1 +// protoc-gen-go v1.34.2 +// protoc v5.27.0 // source: provider/internal/grpc/library.proto package grpc @@ -1801,7 +1801,7 @@ func file_provider_internal_grpc_library_proto_rawDescGZIP() []byte { } var file_provider_internal_grpc_library_proto_msgTypes = make([]protoimpl.MessageInfo, 25) -var file_provider_internal_grpc_library_proto_goTypes = []interface{}{ +var file_provider_internal_grpc_library_proto_goTypes = []any{ (*Capability)(nil), // 0: provider.Capability (*Config)(nil), // 1: provider.Config (*InitResponse)(nil), // 2: provider.InitResponse @@ -1884,7 +1884,7 @@ func file_provider_internal_grpc_library_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_provider_internal_grpc_library_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*Capability); i { case 0: return &v.state @@ -1896,7 +1896,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*Config); i { case 0: return &v.state @@ -1908,7 +1908,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*InitResponse); i { case 0: return &v.state @@ -1920,7 +1920,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*ExternalLink); i { case 0: return &v.state @@ -1932,7 +1932,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[4].Exporter = func(v any, i int) any { switch v := v.(*Position); i { case 0: return &v.state @@ -1944,7 +1944,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[5].Exporter = func(v any, i int) any { switch v := v.(*Location); i { case 0: return &v.state @@ -1956,7 +1956,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[6].Exporter = func(v any, i int) any { switch v := v.(*IncidentContext); i { case 0: return &v.state @@ -1968,7 +1968,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[7].Exporter = func(v any, i int) any { switch v := v.(*ProviderEvaluateResponse); i { case 0: return &v.state @@ -1980,7 +1980,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[8].Exporter = func(v any, i int) any { switch v := v.(*BasicResponse); i { case 0: return &v.state @@ -1992,7 +1992,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[9].Exporter = func(v any, i int) any { switch v := v.(*EvaluateRequest); i { case 0: return &v.state @@ -2004,7 +2004,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[10].Exporter = func(v any, i int) any { switch v := v.(*EvaluateResponse); i { case 0: return &v.state @@ -2016,7 +2016,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[11].Exporter = func(v any, i int) any { switch v := v.(*CapabilitiesResponse); i { case 0: return &v.state @@ -2028,7 +2028,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[12].Exporter = func(v any, i int) any { switch v := v.(*ServiceRequest); i { case 0: return &v.state @@ -2040,7 +2040,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[13].Exporter = func(v any, i int) any { switch v := v.(*GetCodeSnipRequest); i { case 0: return &v.state @@ -2052,7 +2052,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[14].Exporter = func(v any, i int) any { switch v := v.(*GetDependencyLocationRequest); i { case 0: return &v.state @@ -2064,7 +2064,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[15].Exporter = func(v any, i int) any { switch v := v.(*GetCodeSnipResponse); i { case 0: return &v.state @@ -2076,7 +2076,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[16].Exporter = func(v any, i int) any { switch v := v.(*GetDependencyLocationResponse); i { case 0: return &v.state @@ -2088,7 +2088,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[17].Exporter = func(v any, i int) any { switch v := v.(*Dependency); i { case 0: return &v.state @@ -2100,7 +2100,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[18].Exporter = func(v any, i int) any { switch v := v.(*DependencyList); i { case 0: return &v.state @@ -2112,7 +2112,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[19].Exporter = func(v any, i int) any { switch v := v.(*DependencyResponse); i { case 0: return &v.state @@ -2124,7 +2124,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[20].Exporter = func(v any, i int) any { switch v := v.(*FileDep); i { case 0: return &v.state @@ -2136,7 +2136,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[21].Exporter = func(v any, i int) any { switch v := v.(*DependencyDAGItem); i { case 0: return &v.state @@ -2148,7 +2148,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[22].Exporter = func(v any, i int) any { switch v := v.(*DependencyDAGResponse); i { case 0: return &v.state @@ -2160,7 +2160,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[23].Exporter = func(v any, i int) any { switch v := v.(*FileDAGDep); i { case 0: return &v.state @@ -2172,7 +2172,7 @@ func file_provider_internal_grpc_library_proto_init() { return nil } } - file_provider_internal_grpc_library_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} { + file_provider_internal_grpc_library_proto_msgTypes[24].Exporter = func(v any, i int) any { switch v := v.(*Proxy); i { case 0: return &v.state @@ -2185,7 +2185,7 @@ func file_provider_internal_grpc_library_proto_init() { } } } - file_provider_internal_grpc_library_proto_msgTypes[6].OneofWrappers = []interface{}{} + file_provider_internal_grpc_library_proto_msgTypes[6].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ diff --git a/provider/internal/grpc/library_grpc.pb.go b/provider/internal/grpc/library_grpc.pb.go index 5a0a6247..01bc63f5 100644 --- a/provider/internal/grpc/library_grpc.pb.go +++ b/provider/internal/grpc/library_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.3.0 -// - protoc v5.27.1 +// - protoc-gen-go-grpc v1.4.0 +// - protoc v5.27.0 // source: provider/internal/grpc/library.proto package grpc @@ -16,8 +16,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 const ( ProviderCodeLocationService_GetCodeSnip_FullMethodName = "/provider.ProviderCodeLocationService/GetCodeSnip" @@ -39,8 +39,9 @@ func NewProviderCodeLocationServiceClient(cc grpc.ClientConnInterface) ProviderC } func (c *providerCodeLocationServiceClient) GetCodeSnip(ctx context.Context, in *GetCodeSnipRequest, opts ...grpc.CallOption) (*GetCodeSnipResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(GetCodeSnipResponse) - err := c.cc.Invoke(ctx, ProviderCodeLocationService_GetCodeSnip_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, ProviderCodeLocationService_GetCodeSnip_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -130,8 +131,9 @@ func NewProviderDependencyLocationServiceClient(cc grpc.ClientConnInterface) Pro } func (c *providerDependencyLocationServiceClient) GetDependencyLocation(ctx context.Context, in *GetDependencyLocationRequest, opts ...grpc.CallOption) (*GetDependencyLocationResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(GetDependencyLocationResponse) - err := c.cc.Invoke(ctx, ProviderDependencyLocationService_GetDependencyLocation_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, ProviderDependencyLocationService_GetDependencyLocation_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -231,8 +233,9 @@ func NewProviderServiceClient(cc grpc.ClientConnInterface) ProviderServiceClient } func (c *providerServiceClient) Capabilities(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*CapabilitiesResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(CapabilitiesResponse) - err := c.cc.Invoke(ctx, ProviderService_Capabilities_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, ProviderService_Capabilities_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -240,8 +243,9 @@ func (c *providerServiceClient) Capabilities(ctx context.Context, in *emptypb.Em } func (c *providerServiceClient) Init(ctx context.Context, in *Config, opts ...grpc.CallOption) (*InitResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(InitResponse) - err := c.cc.Invoke(ctx, ProviderService_Init_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, ProviderService_Init_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -249,8 +253,9 @@ func (c *providerServiceClient) Init(ctx context.Context, in *Config, opts ...gr } func (c *providerServiceClient) Evaluate(ctx context.Context, in *EvaluateRequest, opts ...grpc.CallOption) (*EvaluateResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(EvaluateResponse) - err := c.cc.Invoke(ctx, ProviderService_Evaluate_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, ProviderService_Evaluate_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -258,8 +263,9 @@ func (c *providerServiceClient) Evaluate(ctx context.Context, in *EvaluateReques } func (c *providerServiceClient) Stop(ctx context.Context, in *ServiceRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(emptypb.Empty) - err := c.cc.Invoke(ctx, ProviderService_Stop_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, ProviderService_Stop_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -267,8 +273,9 @@ func (c *providerServiceClient) Stop(ctx context.Context, in *ServiceRequest, op } func (c *providerServiceClient) GetDependencies(ctx context.Context, in *ServiceRequest, opts ...grpc.CallOption) (*DependencyResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(DependencyResponse) - err := c.cc.Invoke(ctx, ProviderService_GetDependencies_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, ProviderService_GetDependencies_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -276,8 +283,9 @@ func (c *providerServiceClient) GetDependencies(ctx context.Context, in *Service } func (c *providerServiceClient) GetDependenciesDAG(ctx context.Context, in *ServiceRequest, opts ...grpc.CallOption) (*DependencyDAGResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(DependencyDAGResponse) - err := c.cc.Invoke(ctx, ProviderService_GetDependenciesDAG_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, ProviderService_GetDependenciesDAG_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } diff --git a/provider/provider.go b/provider/provider.go index b59569c1..5084a401 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -361,7 +361,6 @@ func FullResponseFromServiceClients(ctx context.Context, clients []ServiceClient for _, c := range clients { r, err := c.Evaluate(ctx, cap, conditionInfo) if err != nil { - fmt.Printf("here, %v", cap) return fullResp, err } if !fullResp.Matched { diff --git a/provider/server/builtin-server.go b/provider/server/builtin-server.go index 50574827..49abb349 100644 --- a/provider/server/builtin-server.go +++ b/provider/server/builtin-server.go @@ -14,18 +14,27 @@ type builtinServer struct { server } -func NewBuiltinProviderServer(log logr.Logger) (libgrpc.ProviderServiceServer, error) { +type BuiltinGRPCServer interface { + libgrpc.ProviderCodeLocationServiceServer + libgrpc.ProviderServiceServer +} + +func NewBuiltinProviderServer(log logr.Logger, contextLines int) (BuiltinGRPCServer, error) { l := log.WithValues("builtin", "builtin") - builtin := builtin.NewBuiltinProvider(provider.Config{}, l) + builtin := builtin.NewBuiltinProvider(provider.Config{ + ContextLines: contextLines, + }, l) return &builtinServer{ server: server{ - Client: builtin, - mutex: sync.RWMutex{}, - clients: map[int64]clientMapItem{}, - rand: rand.Rand{}, - Log: l, + Client: builtin, + mutex: sync.RWMutex{}, + clients: map[int64]clientMapItem{}, + rand: rand.Rand{}, + Log: l, + CodeSnipeResolver: builtin, }, }, nil } -var _ libgrpc.ProviderServiceServer = &server{} +var _ libgrpc.ProviderServiceServer = &builtinServer{} +var _ libgrpc.ProviderCodeLocationServiceServer = &builtinServer{} diff --git a/provider/server/server.go b/provider/server/server.go index 350522fd..1163a4f2 100644 --- a/provider/server/server.go +++ b/provider/server/server.go @@ -108,11 +108,12 @@ func (s *server) Start(ctx context.Context) error { if err != nil { return err } - server, err := NewBuiltinProviderServer(s.Log) + server, err := NewBuiltinProviderServer(s.Log, 50) if err != nil { return err } libgrpc.RegisterProviderServiceServer(builtinGS, server) + libgrpc.RegisterProviderCodeLocationServiceServer(builtinGS, server) reflection.Register(builtinGS) lis, err := net.Listen("tcp", fmt.Sprintf(":%d", s.builtinProviderPort)) if err != nil { @@ -313,9 +314,8 @@ func (s *server) Evaluate(ctx context.Context, req *libgrpc.EvaluateRequest) (*l client := s.clients[req.Id] s.mutex.RUnlock() - s.Log.Info("here", "cap", req.Cap) + s.Log.V(5).Info("Evaluating", "cap", req.Cap) r, err := client.client.Evaluate(ctx, req.Cap, []byte(req.ConditionInfo)) - s.Log.Info("here", "r", r, "err", err) if err != nil { return &libgrpc.EvaluateResponse{ @@ -326,7 +326,6 @@ func (s *server) Evaluate(ctx context.Context, req *libgrpc.EvaluateRequest) (*l templateContext, err := structpb.NewStruct(r.TemplateContext) if err != nil { - s.Log.Info("here 329", "r", r, "err", err) return &libgrpc.EvaluateResponse{ Error: err.Error(), Successful: false, @@ -351,7 +350,6 @@ func (s *server) Evaluate(ctx context.Context, req *libgrpc.EvaluateRequest) (*l variables, err := structpb.NewStruct(i.Variables) if err != nil { - s.Log.Info("here 354", "r", r, "err", err) return &libgrpc.EvaluateResponse{ Error: err.Error(), Successful: false,