-
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
72aef8b
commit 518371d
Showing
16 changed files
with
391 additions
and
37 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
86 changes: 86 additions & 0 deletions
86
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,86 @@ | ||
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 | ||
} | ||
|
||
mm, err := lsctx.ModuleManager(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 | ||
} | ||
walker.RemovePathFromQueue(modPath) | ||
|
||
err = watcher.RemoveModule(modPath) | ||
if err != nil { | ||
lh.logger.Printf("failed to remove module from watcher: %s", err) | ||
continue | ||
} | ||
|
||
callers, err := mm.CallersOfModule(modPath) | ||
if err != nil { | ||
lh.logger.Printf("failed to remove module from watcher: %s", err) | ||
continue | ||
} | ||
if len(callers) == 0 { | ||
mm.RemoveModule(modPath) | ||
} | ||
} | ||
|
||
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 | ||
} | ||
|
||
walker.EnqueuePath(modPath) | ||
} | ||
|
||
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
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
Oops, something went wrong.