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

[pcl/binder] Include the component source directory in diagnostics when reporting PCL errors #13017

Merged
merged 2 commits into from May 24, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,4 @@
changes:
- type: feat
scope: programgen
description: Include the component source directory in diagnostics when reporting PCL errors
22 changes: 22 additions & 0 deletions pkg/codegen/pcl/binder_component.go
Expand Up @@ -135,10 +135,32 @@ func ComponentProgramBinderFromFileSystem() ComponentProgramBinder {
DirPath(componentSourceDir),
ComponentBinder(ComponentProgramBinderFromFileSystem()))

includeSourceDirectoryInDiagnostics(programDiags, componentSourceDir)

return componentProgram, programDiags, err
}
}

// Replaces the Subject of the input diagnostics from just a file name to the full path of the component directory.
func includeSourceDirectoryInDiagnostics(diags hcl.Diagnostics, componentSourceDir string) {
for _, diag := range diags {
start := hcl.Pos{}
end := hcl.Pos{}

if diag.Subject != nil {
start = diag.Subject.Start
end = diag.Subject.End
componentSourceDir = filepath.Join(componentSourceDir, diag.Subject.Filename)
}

diag.Subject = &hcl.Range{
Filename: componentSourceDir,
Zaid-Ajaj marked this conversation as resolved.
Show resolved Hide resolved
Start: start,
End: end,
}
}
}

func (b *binder) bindComponent(node *Component) hcl.Diagnostics {
block, diagnostics := model.BindBlock(node.syntax, model.StaticScope(b.root), b.tokens, b.options.modelOptions()...)
node.Definition = block
Expand Down