Skip to content

Commit

Permalink
fix: remove telementry hooks (#14)
Browse files Browse the repository at this point in the history
Signed-off-by: Gamunu Balagalla <gamunu@fastcode.io>
  • Loading branch information
gamunu authored Jul 17, 2024
1 parent e595118 commit a13b4ee
Show file tree
Hide file tree
Showing 12 changed files with 4 additions and 462 deletions.
41 changes: 0 additions & 41 deletions .github/workflows/add-copyright-headers.yml

This file was deleted.

59 changes: 0 additions & 59 deletions .github/workflows/build-pr.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:

build:
runs-on: ubuntu-latest
needs: [generate-provider-schemas]
strategy:
matrix:
include:
Expand Down
36 changes: 0 additions & 36 deletions .github/workflows/check-changelog.yml

This file was deleted.

2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chigopher/pathlib v0.19.1 h1:RoLlUJc0CqBGwq239cilyhxPNLXTK+HXoASGyGznx5A=
github.com/chigopher/pathlib v0.19.1/go.mod h1:tzC1dZLW8o33UQpWkNkhvPwL5n4yyFRFm/jL1YGWFvY=
github.com/chigopher/pathlib v1.0.0 h1:SbsCrFX4vDf4M2d8mT/RTzuVlKOjTKoPHK0HidsQFak=
github.com/chigopher/pathlib v1.0.0/go.mod h1:3+YPPV21mU9vyw8Mjp+F33CyCfE6iOzinpiqBcccv7I=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
Expand Down
2 changes: 0 additions & 2 deletions internal/features/modules/hooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ package hooks
import (
"log"

"github.com/algolia/algoliasearch-client-go/v3/algolia/search"
"github.com/hashicorp/terraform-ls/internal/features/modules/state"
"github.com/hashicorp/terraform-ls/internal/registry"
)

type Hooks struct {
ModStore *state.ModuleStore
RegistryClient registry.Client
AlgoliaClient *search.Client
Logger *log.Logger
}
50 changes: 2 additions & 48 deletions internal/features/modules/hooks/module_source_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,16 @@ package hooks

import (
"context"
"strings"

"github.com/algolia/algoliasearch-client-go/v3/algolia/opt"
"github.com/hashicorp/hcl-lang/decoder"
"github.com/hashicorp/hcl-lang/lang"
"github.com/zclconf/go-cty/cty"
"strings"
)

type RegistryModule struct {
FullName string `json:"full-name"`
Description string `json:"description"`
}

const algoliaModuleIndex = "tf-registry:prod:modules"

func (h *Hooks) fetchModulesFromAlgolia(ctx context.Context, term string) ([]RegistryModule, error) {
modules := make([]RegistryModule, 0)

index := h.AlgoliaClient.InitIndex(algoliaModuleIndex)
params := []interface{}{
ctx, // transport.Request will magically extract the context from here
opt.AttributesToRetrieve("full-name", "description"),
opt.HitsPerPage(10),
}

res, err := index.Search(term, params...)
if err != nil {
return modules, err
}

err = res.UnmarshalHits(&modules)
if err != nil {
return modules, err

}

return modules, nil
}

func (h *Hooks) RegistryModuleSources(ctx context.Context, value cty.Value) ([]decoder.Candidate, error) {
candidates := make([]decoder.Candidate, 0)
prefix := value.AsString()
Expand All @@ -54,24 +25,7 @@ func (h *Hooks) RegistryModuleSources(ctx context.Context, value cty.Value) ([]d
return candidates, nil
}

if h.AlgoliaClient == nil {
return candidates, nil
}

modules, err := h.fetchModulesFromAlgolia(ctx, prefix)
if err != nil {
h.Logger.Printf("Error fetching modules from Algolia: %#v", err)
return candidates, err
}

for _, mod := range modules {
c := decoder.ExpressionCompletionCandidate(decoder.ExpressionCandidate{
Value: cty.StringVal(mod.FullName),
Detail: "registry",
Description: lang.PlainText(mod.Description),
})
candidates = append(candidates, c)
}
//TODO: figure out how we can do module autocompletion

return candidates, nil
}
Loading

0 comments on commit a13b4ee

Please sign in to comment.