-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/service: add support for didChangeWatchedFiles
Signed-off-by: danishprakash <grafitykoncept@gmail.com>
- Loading branch information
1 parent
f29eb8c
commit b450b15
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package handlers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
ilsp "github.com/hashicorp/terraform-ls/internal/lsp" | ||
"github.com/hashicorp/terraform-ls/internal/protocol" | ||
lsp "github.com/hashicorp/terraform-ls/internal/protocol" | ||
"github.com/hashicorp/terraform-ls/internal/terraform/ast" | ||
) | ||
|
||
func (svc *service) DidChangeWatchedFiles(ctx context.Context, params lsp.DidChangeWatchedFilesParams) error { | ||
for _, change := range params.Changes { | ||
URI := string(change.URI) | ||
dir, err := os.Stat(URI) | ||
if err != nil { | ||
return fmt.Errorf("Unable to update %s. Failed to open directory, error: %w", URI, err) | ||
} | ||
|
||
filename := path.Base(URI) | ||
if !dir.IsDir() && !ast.IsModuleFilename(filename) { | ||
// TODO: raise warning; unsupported file | ||
return fmt.Errorf("Unable to update %s, filetype not supported.", filename) | ||
} | ||
|
||
// only handle Changed event type | ||
if change.Type == protocol.Changed { | ||
dh := ilsp.HandleFromDocumentURI(change.URI) | ||
|
||
// check existence | ||
_, err = svc.modStore.ModuleByPath(dh.Dir.Path()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
jobIds, err := svc.parseAndDecodeModule(dh.Dir) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return svc.stateStore.JobStore.WaitForJobs(ctx, jobIds...) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters