Skip to content

Commit

Permalink
internal/service: add support for didChangeWatchedFiles
Browse files Browse the repository at this point in the history
Signed-off-by: danishprakash <grafitykoncept@gmail.com>
  • Loading branch information
danishprakash committed Apr 10, 2022
1 parent f29eb8c commit ad97566
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
48 changes: 48 additions & 0 deletions internal/langserver/handlers/did_change_watched_files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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)
}

// case protocol.Created:
// err := fs.CreateAndOpenDocument(fh, fh.Filename(), []byte(""))
// if err != nil {
// return err
// }

if change.Type == protocol.Changed {
dh := ilsp.HandleFromDocumentURI(change.URI)

jobIds, err := svc.parseAndDecodeModule(dh.Dir)
if err != nil {
return err
}

return svc.stateStore.JobStore.WaitForJobs(ctx, jobIds...)
}
}

return nil
}
8 changes: 8 additions & 0 deletions internal/langserver/handlers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ func (svc *service) Assigner() (jrpc2.Assigner, error) {

return handle(ctx, req, svc.DidChangeWorkspaceFolders)
},
"workspace/didChangeWatchedFiles": func(ctx context.Context, req *jrpc2.Request) (interface{}, error) {
err := session.CheckInitializationIsConfirmed()
if err != nil {
return nil, err
}

return handle(ctx, req, svc.DidChangeWatchedFiles)
},
"textDocument/references": func(ctx context.Context, req *jrpc2.Request) (interface{}, error) {
err := session.CheckInitializationIsConfirmed()
if err != nil {
Expand Down

0 comments on commit ad97566

Please sign in to comment.