-
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.
- Loading branch information
1 parent
92a2a2c
commit ca61baf
Showing
10 changed files
with
168 additions
and
11 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
internal/langserver/handlers/did_change_workspace_folders.go
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,74 @@ | ||
package handlers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/creachadair/jrpc2" | ||
lsctx "github.com/hashicorp/terraform-ls/internal/context" | ||
lsp "github.com/hashicorp/terraform-ls/internal/protocol" | ||
"github.com/hashicorp/terraform-ls/internal/uri" | ||
) | ||
|
||
func (lh *logHandler) DidChangeWorkspaceFolders(ctx context.Context, params lsp.DidChangeWorkspaceFoldersParams) error { | ||
watcher, err := lsctx.Watcher(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// walker, err := lsctx.ModuleWalker(ctx) | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
for _, removed := range params.Event.Removed { | ||
modPath, err := pathFromDocumentURI(removed.URI) | ||
if err != nil { | ||
jrpc2.ServerFromContext(ctx).Notify(ctx, "window/showMessage", &lsp.ShowMessageParams{ | ||
Type: lsp.Warning, | ||
Message: fmt.Sprintf("Ignoring removed workspace folder %s: %s."+ | ||
" This is most likely bug, please report it.", removed.URI, err), | ||
}) | ||
continue | ||
} | ||
err = watcher.RemoveModule(modPath) | ||
if err != nil { | ||
lh.logger.Printf("failed to remove module from watcher: %s", err) | ||
continue | ||
} | ||
|
||
// TODO: Remove module from walker's queue | ||
} | ||
|
||
for _, added := range params.Event.Added { | ||
modPath, err := pathFromDocumentURI(added.URI) | ||
if err != nil { | ||
jrpc2.ServerFromContext(ctx).Notify(ctx, "window/showMessage", &lsp.ShowMessageParams{ | ||
Type: lsp.Warning, | ||
Message: fmt.Sprintf("Ignoring new workspace folder %s: %s."+ | ||
" This is most likely bug, please report it.", added.URI, err), | ||
}) | ||
continue | ||
} | ||
err = watcher.AddModule(modPath) | ||
if err != nil { | ||
lh.logger.Printf("failed to add module to watcher: %s", err) | ||
continue | ||
} | ||
|
||
// TODO: Add module to walker's queue | ||
} | ||
|
||
// TODO: Restart walker if it's not walking | ||
|
||
return nil | ||
} | ||
|
||
func pathFromDocumentURI(docUri string) (string, error) { | ||
rawPath, err := uri.PathFromURI(docUri) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return cleanupPath(rawPath) | ||
} |
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
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
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
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
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
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
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
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
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