diff --git a/internal/langserver/handlers/did_change_watched_files.go b/internal/langserver/handlers/did_change_watched_files.go index 9489c4c43..d517afa8a 100644 --- a/internal/langserver/handlers/did_change_watched_files.go +++ b/internal/langserver/handlers/did_change_watched_files.go @@ -77,7 +77,17 @@ func (svc *service) DidChangeWatchedFiles(ctx context.Context, params lsp.DidCha } // If the .terraform/modules/terraform-sources.json file changes - // TODO: implement this + if modUri, ok := datadir.ModuleUriFromTerraformSourcesFile(rawURI); ok { + modHandle := document.DirHandleFromURI(modUri) + // manifest change event handles terraform-sources.json as well + svc.eventBus.ManifestChange(eventbus.ManifestChangeEvent{ + Context: ctx, // We pass the context for data here + Dir: modHandle, + ChangeType: change.Type, + }) + + continue + } rawPath, err := uri.PathFromURI(rawURI) if err != nil { diff --git a/internal/terraform/datadir/paths.go b/internal/terraform/datadir/paths.go index f6c762817..c009c5938 100644 --- a/internal/terraform/datadir/paths.go +++ b/internal/terraform/datadir/paths.go @@ -85,3 +85,11 @@ func ModuleUriFromModuleLockFile(rawUri string) (string, bool) { } return "", false } + +func ModuleUriFromTerraformSourcesFile(rawUri string) (string, bool) { + suffix := "/" + path.Join(terraformSourcesPathElements...) + if strings.HasSuffix(rawUri, suffix) { + return strings.TrimSuffix(rawUri, suffix), true + } + return "", false +}