Skip to content

Commit

Permalink
wip - support did_change_watched_files for tf sources
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarm committed Sep 30, 2024
1 parent 422e844 commit e34be9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/langserver/handlers/did_change_watched_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions internal/terraform/datadir/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit e34be9d

Please sign in to comment.