Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👻 change fmt.prints to log #744

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (d *dotnetServiceClient) Evaluate(ctx context.Context, cap string, conditio
return provider.ProviderEvaluateResponse{Matched: false}, nil
}
for _, position := range positions {
fmt.Println("%#v", position)
d.log.V(5).Info("got position", "position", position)
res := []protocol.Location{}
switch position.(type) {
case protocol.ReferenceParams:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ func (sc *NodeServiceClient) EvaluateReferenced(ctx context.Context, cap string,

symbols := sc.GetAllDeclarations(ctx, sc.BaseConfig.WorkspaceFolders, query)

fmt.Printf("symbols: %v\n", symbols)
// fmt.Printf("symbols: %v\n", symbols)

incidents := []provider.IncidentContext{}
incidentsMap := make(map[string]provider.IncidentContext) // Remove duplicates

for _, s := range symbols {
references := sc.GetAllReferences(ctx, s.Location.Value.(protocol.Location))

fmt.Printf("references: %v\n", references)
//fmt.Printf("references: %v\n", references)

breakEarly := false
for _, ref := range references {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (sc *YamlServiceClient) EvaluateReferenced(ctx context.Context, cap string,
return provider.ProviderEvaluateResponse{}, err
}

fmt.Println(schemaFile.Name())
// fmt.Println(schemaFile.Name())

// Send a workspace/didChangeConfiguration request
sc.configParams = []map[string]any{
Expand Down Expand Up @@ -278,7 +278,7 @@ func (sc *YamlServiceClient) EvaluateReferenced(ctx context.Context, cap string,
return provider.ProviderEvaluateResponse{}, err
}

fmt.Printf("didOpen %s\n", yamlFiles[batchRight])
// fmt.Printf("didOpen %s\n", yamlFiles[batchRight])

err = didOpen(yamlFiles[batchRight], text)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (p *javaServiceClient) getURI(refURI string) (string, uri.URI, error) {
cmd.Dir = filepath.Dir(jarPath)
err := cmd.Run()
if err != nil {
fmt.Printf("\n java error%v", err)
p.log.Error(err, "error unpacking java archive")
return "", "", err
}
}
Expand Down Expand Up @@ -245,7 +245,7 @@ func (p *javaServiceClient) getURI(refURI string) (string, uri.URI, error) {
cmd.Dir = filepath.Dir(sourcesFile)
err = cmd.Run()
if err != nil {
fmt.Printf("\n java error%v", err)
p.log.Error(err, "error unpacking java archive")
return "", "", err
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func resolveSourcesJarsForGradle(ctx context.Context, log logr.Logger, fernflowe
return err
}

fmt.Printf("%d", len(unresolvedSources))
log.V(5).Info("total unresolved sources", "count", len(unresolvedSources))

decompileJobs := []decompileJob{}
if len(unresolvedSources) > 1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (p *javaServiceClient) GetAllReferences(ctx context.Context, symbol protoco
if jsonrpc2.IsRPCClosed(err) {
p.log.Error(err, "connection to the language server is closed, language server is not running")
} else {
fmt.Printf("Error rpc: %v", err)
p.log.Error(err, "unknown error in RPC connection")
}
}
return res
Expand Down Expand Up @@ -304,7 +304,6 @@ func (p *javaServiceClient) initialization(ctx context.Context) {
break
}
if err := p.rpc.Notify(ctx, "initialized", &protocol.InitializedParams{}); err != nil {
fmt.Printf("initialized failed: %v", err)
p.log.Error(err, "initialize failed")
}
p.log.V(2).Info("java connection initialized")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func (p *yqProvider) Capabilities() []provider.Capability {
r := openapi3.NewReflector()
k8sResourceMatched, err := provider.ToProviderCap(r, p.log, k8sResourceCondition{}, "k8sResourceMatched")
if err != nil {
fmt.Printf("not working")
p.log.Error(err, "error generating capabilities")
return caps
}
caps = append(caps, k8sResourceMatched)
return caps
Expand Down Expand Up @@ -105,7 +106,7 @@ func (p *yqProvider) Init(ctx context.Context, log logr.Logger, c provider.InitC
go func() {
err := cmd.Run()
if err != nil {
fmt.Printf("cmd failed - %v", err)
log.Error(err, "failed to start LSP server")
// TODO: Probably should cancel the ctx here, to shut everything down
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ func (p *yqServiceClient) GetAllValuesForKey(ctx context.Context, query []string

matchingYAMLFiles, err := provider.FindFilesMatchingPattern(p.config.Location, "*.yaml")
if err != nil {
fmt.Printf("unable to find any YAML files: %v\n", err)
p.log.Error(err, "unable to find any YML files")
return results, err
}
matchingYMLFiles, err := provider.FindFilesMatchingPattern(p.config.Location, "*.yml")
if err != nil {
fmt.Printf("unable to find any YML files: %v\n", err)
p.log.Error(err, "unable to find any YML files")
return results, err
}
matchingYAMLFiles = append(matchingYAMLFiles, matchingYMLFiles...)

Expand All @@ -152,11 +154,9 @@ func (p *yqServiceClient) GetAllValuesForKey(ctx context.Context, query []string
go func(file string) {
defer wg.Done()

fmt.Printf("Reading YAML file: %s\n", file)

data, err := os.ReadFile(file)
if err != nil {
fmt.Printf("Error reading YAML file '%s': %v\n", file, err)
p.log.Error(err, "error reading YAML file", "file", file)
return
}

Expand Down
9 changes: 1 addition & 8 deletions lsp/base_service_client/base_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package base

import (
"context"
"fmt"

"github.com/go-logr/logr"
jsonrpc2 "github.com/konveyor/analyzer-lsp/jsonrpc2_v2"
Expand All @@ -19,13 +18,7 @@ func (*DefaultHandler) Handle(context.Context, *jsonrpc2.Request) (interface{},
// Logs the requests received
func LogHandler(log logr.Logger) jsonrpc2.HandlerFunc {
return func(ctx context.Context, req *jsonrpc2.Request) (interface{}, error) {
log.V(5).Info("Request received", "Method", req.Method)
fmt.Printf(
"Request received:\n- ID: %v\n- Method: %s\n- Params: %s\n\n",
req.ID,
req.Method,
string(req.Params),
)
log.V(5).Info("Request received", "Method", req.Method, "Id", req.ID, "params", req.Params)
return nil, jsonrpc2.ErrNotHandled
}
}
Expand Down
7 changes: 0 additions & 7 deletions lsp/protocol/extensions.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package protocol

import (
"fmt"
)

// Whether the server supports the given method or not. Servers, such as pylsp,
// crash when given a method they do not support.
// FIXME: Implement all requests!
Expand Down Expand Up @@ -159,8 +155,5 @@ func (c *ServerCapabilities) Supports(method string) bool {
// case "workspaceSymbol/resolve":
}

// Default to false for now. May cause headaches until all request checks are
// implemented unfortunately.
fmt.Printf("Method `%s` is not supported!\n", method)
return false
}
2 changes: 1 addition & 1 deletion lsp/protocol/generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func writeprotocol() {
s = s[:i] + h + s[i+len("}"):]

types["XInitializeParams"] = s
fmt.Printf("%s", types["XInitializeParams"])
// fmt.Printf("%s", types["XInitializeParams"])

// and some aliases to make the new code contain the old
types["PrepareRename2Gn"] = "type PrepareRename2Gn = Msg_PrepareRename2Gn // (alias) line 13927\n"
Expand Down
2 changes: 1 addition & 1 deletion provider/grpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewGRPCClient(config provider.Config, log logr.Logger) (provider.InternalPr

services, err := checkServicesRunning(refClt, log)
if err != nil {
fmt.Printf("\n%v\n", err)
log.Error(err, "failed to check if services are running")
return nil, err
}
foundCodeSnip := false
Expand Down
12 changes: 4 additions & 8 deletions provider/internal/builtin/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,7 @@ func findXMLFiles(baseLocation string, filePaths []string, log logr.Logger) ([]s
func queryXMLFile(filePath string, query *xpath.Expr) (nodes []*xmlquery.Node, err error) {
f, err := os.Open(filePath)
if err != nil {
fmt.Printf("unable to open file '%s': %v\n", filePath, err)
return nil, err
return nil, fmt.Errorf("unable to open file '%s': %w", filePath, err)
}
defer f.Close()
// TODO This should start working if/when this merges and releases: https://github.com/golang/go/pull/56848
Expand All @@ -513,18 +512,15 @@ func queryXMLFile(filePath string, query *xpath.Expr) (nodes []*xmlquery.Node, e
var b []byte
b, err = os.ReadFile(filePath)
if err != nil {
fmt.Printf("unable to parse xml file '%s': %v\n", filePath, err)
return nil, err
return nil, fmt.Errorf("unable to parse xml file '%s': %w", filePath, err)
}
docString := strings.Replace(string(b), "<?xml version=\"1.1\"", "<?xml version = \"1.0\"", 1)
doc, err = xmlquery.Parse(strings.NewReader(docString))
if err != nil {
fmt.Printf("unable to parse xml file '%s': %v\n", filePath, err)
return nil, err
return nil, fmt.Errorf("unable to parse xml file '%s': %w", filePath, err)
}
} else {
fmt.Printf("unable to parse xml file '%s': %v\n", filePath, err)
return nil, err
return nil, fmt.Errorf("unable to parse xml file '%s': %w", filePath, err)
}
}
defer func() {
Expand Down
5 changes: 0 additions & 5 deletions provider/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ func GetFiles(configLocation string, filepaths []string, patterns ...string) ([]
}
files, err := FindFilesMatchingPattern(configLocation, pattern)
if err != nil {
// Something went wrong dealing with the pattern, so we'll assume the user input
// is good and pass it on
// TODO: If we're ever hitting this for real, we should investigate
fmt.Printf("Unable to resolve pattern '%s': %v", pattern, err)
xmlFiles = append(xmlFiles, pattern)
} else {
xmlFiles = append(xmlFiles, files...)
Expand All @@ -91,7 +87,6 @@ func GetFiles(configLocation string, filepaths []string, patterns ...string) ([]
for _, pattern := range filepaths {
files, err := FindFilesMatchingPattern(configLocation, pattern)
if err != nil {
fmt.Printf("Unable to find files using pattern `%s`: %v", pattern, err)
continue
} else {
xmlFiles = append(xmlFiles, files...)
Expand Down
Loading