Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
appilon committed Oct 14, 2020
1 parent 39c955f commit aff4d2f
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions langserver/handlers/execute_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,18 @@ import (
type executeCommandHandler func(context.Context, lsp.ExecuteCommandParams) (interface{}, error)

type rootmoduleCommandResponse struct {
Rootmodule string `json:"rootmodule"`
Initialized bool `json:"initialized"`
Rootmodule string `json:"rootmodule"`
Initialized bool `json:"initialized"`
StillWalking bool
}

var executeCommandHandlers = map[string]executeCommandHandler{
"rootmodule": func(ctx context.Context, params lsp.ExecuteCommandParams) (interface{}, error) {
"rootmodules": func(ctx context.Context, params lsp.ExecuteCommandParams) (interface{}, error) {
walker, err := lsctx.RootModuleWalker(ctx)
if err != nil {
return nil, err
}

if err := Waiter(func() (bool, error) {
return !walker.IsWalking(), nil
}).Waitf("root module walker is still walking"); err != nil {
return nil, err
}

uri := lsp.DocumentURI(params.Arguments[0].(string))
fh := ilsp.FileHandlerFromDocumentURI(uri)

Expand All @@ -37,17 +32,10 @@ var executeCommandHandlers = map[string]executeCommandHandler{
return nil, err
}

candidates := cf.RootModuleCandidatesByPath(fh.Dir())
if len(candidates) > 1 {
return nil, fmt.Errorf("%q appears to have multiple candidate root modules", uri)
}

var resp rootmoduleCommandResponse
if len(candidates) == 1 {
resp.Initialized = true
resp.Rootmodule = candidates[0].Path()
}
return resp, nil
return rootmoduleCommandResponse{
candidates: cf.RootModuleCandidatesByPath(fh.Dir()),
isWalking: walker.IsWalking(),
}, nil
},
}

Expand Down

0 comments on commit aff4d2f

Please sign in to comment.