Skip to content

Commit

Permalink
Passed contextLines to the providers
Browse files Browse the repository at this point in the history
Signed-off-by: Md Sahil <[email protected]>
  • Loading branch information
MdSahil-oss committed Aug 16, 2023
1 parent 3b5eb6f commit 421d414
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions cmd/analyzer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func main() {
providers := map[string]provider.InternalProviderClient{}

for _, config := range configs {
config.ContextLines = contextLines
// IF analsyis mode is set from the CLI, then we will override this for each init config
if analysisMode != "" {
inits := []provider.InitConfig{}
Expand Down
9 changes: 3 additions & 6 deletions provider/internal/java/snipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import (
)

const (
// TODO: make this configurable in the future
// We may or may not need to do this so holding off for now.
CONTEXT_LINES = 10
FILE_URI_PREFIX = "konveyor-jdt"
)

Expand Down Expand Up @@ -91,13 +88,13 @@ func (p *javaProvider) scanFile(path string, loc engine.Location) (string, error
scanner := bufio.NewScanner(readFile)
lineNumber := 0
codeSnip := ""
paddingSize := len(strconv.Itoa(loc.EndPosition.Line + CONTEXT_LINES))
paddingSize := len(strconv.Itoa(loc.EndPosition.Line + p.config.ContextLines))
for scanner.Scan() {
if (lineNumber - CONTEXT_LINES) == loc.EndPosition.Line {
if (lineNumber - p.config.ContextLines) == loc.EndPosition.Line {
codeSnip = codeSnip + fmt.Sprintf("%*d %v", paddingSize, lineNumber+1, scanner.Text())
break
}
if (lineNumber + CONTEXT_LINES) >= loc.StartPosition.Line {
if (lineNumber + p.config.ContextLines) >= loc.StartPosition.Line {
codeSnip = codeSnip + fmt.Sprintf("%*d %v\n", paddingSize, lineNumber+1, scanner.Text())
}
lineNumber += 1
Expand Down
11 changes: 6 additions & 5 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ type Capability struct {
}

type Config struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
BinaryPath string `yaml:"binaryPath,omitempty" json:"binaryPath,omitempty"`
Address string `yaml:"address,omitempty" json:"address,omitempty"`
Proxy *Proxy `yaml:"proxyConfig,omitempty" json:"proxyConfig,omitempty"`
InitConfig []InitConfig `yaml:"initConfig,omitempty" json:"initConfig,omitempty"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
BinaryPath string `yaml:"binaryPath,omitempty" json:"binaryPath,omitempty"`
Address string `yaml:"address,omitempty" json:"address,omitempty"`
Proxy *Proxy `yaml:"proxyConfig,omitempty" json:"proxyConfig,omitempty"`
InitConfig []InitConfig `yaml:"initConfig,omitempty" json:"initConfig,omitempty"`
ContextLines int
}

type Proxy httpproxy.Config
Expand Down

0 comments on commit 421d414

Please sign in to comment.