Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jpogran committed Nov 16, 2021
1 parent e663b97 commit d4ef8a8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/langserver/handlers/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams)

serverCaps.Capabilities.SemanticTokensProvider = semanticTokensOpts

svc.jrpcSvr = jrpc2.ServerFromContext(ctx)

// set commandPrefix for session
lsctx.SetCommandPrefix(ctx, out.Options.CommandPrefix)
// apply prefix to executeCommand handler names
Expand Down
9 changes: 9 additions & 0 deletions internal/langserver/handlers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type service struct {
decoder *decoder.Decoder
stateStore *state.StateStore

jrpcSvr *jrpc2.Server

additionalHandlers map[string]rpch.Func
}

Expand Down Expand Up @@ -446,6 +448,13 @@ func (svc *service) configureSessionDependencies(ctx context.Context, cfgOpts *s
svc.stateStore.SetLogger(svc.logger)
svc.stateStore.Modules.ChangeHooks = state.ModuleChangeHooks{
sendModuleTelemetry(svc.sessCtx, svc.stateStore, svc.telemetry),
func(_, newMod *state.Module) {
svc.logger.Printf("Sending refresh notification for %s", newMod.Path)
_, err := svc.jrpcSvr.Callback(svc.srvCtx, "workspace/semanticTokens/refresh", nil)
if err != nil {
svc.logger.Printf("Error refreshing %s: %s", newMod.Path, err)
}
},
}

svc.modStore = svc.stateStore.Modules
Expand Down
27 changes: 27 additions & 0 deletions internal/state/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package state

import (
"path/filepath"
"runtime"

"github.com/hashicorp/go-memdb"
"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -448,6 +449,13 @@ func (s *ModuleStore) UpdateModManifest(path string, manifest *datadir.ModuleMan
return err
}

txn.Defer(func() {
for _, hook := range s.ChangeHooks {
s.logger.Printf("%s Sending refresh for %s", funcName(), path)
hook(nil, mod)
}
})

txn.Commit()
return nil
}
Expand All @@ -467,6 +475,13 @@ func (s *ModuleStore) SetTerraformVersionState(path string, state op.OpState) er
return err
}

txn.Defer(func() {
for _, hook := range s.ChangeHooks {
s.logger.Printf("%s Sending refresh for %s", funcName(), path)
hook(nil, mod)
}
})

txn.Commit()
return nil
}
Expand Down Expand Up @@ -548,6 +563,13 @@ func (s *ModuleStore) UpdateTerraformVersion(modPath string, tfVer *version.Vers
return err
}

txn.Defer(func() {
for _, hook := range s.ChangeHooks {
s.logger.Printf("%s Sending refresh for %s", funcName(), modPath)
hook(nil, mod)
}
})

txn.Commit()
return nil
}
Expand Down Expand Up @@ -820,3 +842,8 @@ func (s *ModuleStore) UpdateReferenceOrigins(path string, origins reference.Orig
txn.Commit()
return nil
}

func funcName() string {
pc, _, _, _ := runtime.Caller(1)
return runtime.FuncForPC(pc).Name()
}

0 comments on commit d4ef8a8

Please sign in to comment.