Skip to content

Commit

Permalink
Implement Files() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Prates committed Jun 11, 2021
1 parent 18655e3 commit e03a296
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tflint/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,24 @@ func (c *Client) File(filename string) (*hcl.File, error) {
return file, nil
}

// Files calls the server-side Files method and returns a collection of hcl.File object.
func (c *Client) Files() (map[string]*hcl.File, error) {
var response FilesResponse
if err := c.rpcClient.Call("Plugin.Files", FilesRequest{}, &response); err != nil {
return nil, err
}

files := make(map[string]*hcl.File)
for filename, content := range response.Files {
file, diags := parseConfig(content, filename, hcl.InitialPos)
if diags.HasErrors() {
return nil, diags
}
files[filename] = file
}
return files, nil
}

// RootProvider calls the server-side RootProvider method and returns the provider configuration.
func (c *Client) RootProvider(name string) (*configs.Provider, error) {
log.Printf("[DEBUG] Accessing to the `%s` provider config in the root module", name)
Expand Down
9 changes: 9 additions & 0 deletions tflint/client/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ type FileResponse struct {
Range hcl.Range
}

// FilesRequest is a request to the server-side Files method.
type FilesRequest struct{}

// FilesResponse is a response to the server-side Files method.
type FilesResponse struct {
Files map[string][]byte
Err error
}

// RootProviderRequest is a request to the server-side RootProvider method.
type RootProviderRequest struct {
Name string
Expand Down
1 change: 1 addition & 0 deletions tflint/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ type Server interface {
Backend(*client.BackendRequest, *client.BackendResponse) error
EvalExpr(*client.EvalExprRequest, *client.EvalExprResponse) error
EmitIssue(*client.EmitIssueRequest, *interface{}) error
Files(*client.FilesRequest, *client.FilesResponse) error
}

0 comments on commit e03a296

Please sign in to comment.