-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ adding reflection client to determine what provider provides
Signed-off-by: Shawn Hurley <[email protected]>
- Loading branch information
1 parent
20e6323
commit 9a92350
Showing
14 changed files
with
901 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package grpc | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/konveyor/analyzer-lsp/engine" | ||
pb "github.com/konveyor/analyzer-lsp/provider/internal/grpc" | ||
"go.lsp.dev/uri" | ||
) | ||
|
||
type codeSnipProviderClient struct { | ||
client pb.ProviderCodeLocationServiceClient | ||
} | ||
|
||
// GetCodeSnip implements engine.CodeSnip. | ||
func (c *codeSnipProviderClient) GetCodeSnip(u uri.URI, loc engine.Location) (string, error) { | ||
resp, err := c.client.GetCodeSnip(context.TODO(), &pb.GetCodeSnipRequest{ | ||
Uri: string(u), | ||
CodeLocation: &pb.Location{ | ||
StartPosition: &pb.Position{ | ||
Line: float64(loc.StartPosition.Line), | ||
Character: float64(loc.StartPosition.Character), | ||
}, | ||
EndPosition: &pb.Position{ | ||
Line: float64(loc.EndPosition.Line), | ||
Character: float64(loc.EndPosition.Character), | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
return "", err | ||
} | ||
return resp.Snip, nil | ||
} | ||
|
||
var _ engine.CodeSnip = &codeSnipProviderClient{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package grpc | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/konveyor/analyzer-lsp/engine" | ||
"github.com/konveyor/analyzer-lsp/output/v1/konveyor" | ||
"github.com/konveyor/analyzer-lsp/provider" | ||
pb "github.com/konveyor/analyzer-lsp/provider/internal/grpc" | ||
"google.golang.org/protobuf/types/known/structpb" | ||
) | ||
|
||
type dependencyLocationResolverClient struct { | ||
client pb.ProviderDependencyLocationServiceClient | ||
} | ||
|
||
// GetLocation implements provider.DependencyLocationResolver. | ||
func (d *dependencyLocationResolverClient) GetLocation(ctx context.Context, dep konveyor.Dep, depFile string) (engine.Location, error) { | ||
extras, err := structpb.NewStruct(dep.Extras) | ||
if err != nil { | ||
return engine.Location{}, err | ||
} | ||
|
||
res, err := d.client.GetDependencyLocation(context.TODO(), &pb.GetDependencyLocationRequest{ | ||
Dep: &pb.Dependency{ | ||
Name: dep.Name, | ||
Version: dep.Version, | ||
Classifier: dep.Classifier, | ||
Type: dep.Type, | ||
ResolvedIdentifier: dep.ResolvedIdentifier, | ||
FileURIPrefix: dep.FileURIPrefix, | ||
Indirect: dep.Indirect, | ||
Extras: extras, | ||
Labels: dep.Labels, | ||
}, | ||
DepFile: depFile, | ||
}) | ||
if res.Location == nil { | ||
return engine.Location{}, nil | ||
} | ||
loc := engine.Location{} | ||
if res.Location.StartPosition != nil { | ||
loc.StartPosition = engine.Position{} | ||
loc.StartPosition.Line = int(res.Location.StartPosition.Line) | ||
loc.StartPosition.Character = int(res.Location.StartPosition.Character) | ||
} | ||
if res.Location.EndPosition != nil { | ||
loc.EndPosition = engine.Position{} | ||
loc.EndPosition.Line = int(res.Location.EndPosition.Line) | ||
loc.EndPosition.Character = int(res.Location.EndPosition.Character) | ||
} | ||
|
||
return loc, nil | ||
} | ||
|
||
var _ provider.DependencyLocationResolver = &dependencyLocationResolverClient{} |
Oops, something went wrong.