Skip to content

Commit a1b5bb2

Browse files
authored
settings: repurpose indexer-related options (#1003)
* settings: repurpose indexer-related options * track IgnorePaths via telemetry * settings: prepend options with 'indexing'
1 parent ef90e32 commit a1b5bb2

File tree

6 files changed

+85
-61
lines changed

6 files changed

+85
-61
lines changed

docs/SETTINGS.md

+23-15
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,30 @@ Path to the Terraform binary.
2222
This is usually looked up automatically from `$PATH` and should not need to be
2323
specified in majority of cases. Use this to override the automatic lookup.
2424

25-
## `rootModulePaths` (`[]string`)
25+
## **DEPRECATED**: `rootModulePaths` (`[]string`)
2626

27-
This allows overriding automatic root module discovery by passing a static list
28-
of absolute or relative paths to root modules (i.e. folders with `*.tf` files
29-
which have been `terraform init`-ed). Conflicts with `ExcludeModulePaths` option.
27+
This option is deprecated and ignored from v0.29+, it was used as an escape hatch
28+
to force indexing of paths in cases where indexer wouldn't index them otherwise.
29+
Indexer in 0.29.0 no longer limited to just initialized modules (folders with `.terraform`)
30+
and instead indexes all directories with `*.tf` files in them.
31+
Therefore this option is no longer relevant.
3032

31-
Relative paths are resolved relative to the directory opened in the editor.
33+
If you previously used it to force indexing of a folder outside of a workspace,
34+
you can just add that folder to the workspace and it will be indexed as usual.
3235

33-
Path separators are converted automatically to the match separators
34-
of the target platform (e.g. `\` on Windows, or `/` on Unix),
35-
symlinks are followed, trailing slashes automatically removed,
36-
and `~` is replaced with your home directory.
36+
## **DEPRECATED**: `excludeModulePaths` (`[]string`)
3737

38-
## `excludeModulePaths` (`[]string`)
38+
Deprecated in favour of `ignorePaths`
3939

40-
This allows exclude root module path when automatic root module discovery by passing a static list
41-
of absolute or relative paths to root modules (i.e. folders with `*.tf` files
42-
which have been `terraform init`-ed). Conflicts with `rootModulePaths` option.
40+
## `indexing.ignorePaths` (`[]string`)
4341

44-
Relative paths are resolved relative to the directory opened in the editor.
42+
Paths to ignore when indexing the workspace on initialization. This can serve
43+
as an escape hatch in large workspaces. Key side effect of ignoring a path
44+
is that go-to-definition, go-to-references and generally most IntelliSense
45+
related to local `module` blocks will **not** work until the target module code
46+
is explicitly opened.
47+
48+
Relative paths are resolved relative to the root (workspace) path opened in the editor.
4549

4650
Path separators are converted automatically to the match separators
4751
of the target platform (e.g. `\` on Windows, or `/` on Unix),
@@ -68,7 +72,11 @@ Or if left empty
6872
This setting should be deprecated once the language server supports multiple workspaces,
6973
as this arises in VS code because a server instance is started per VS Code workspace.
7074

71-
## `ignoreDirectoryNames` (`[]string`)
75+
## **DEPRECATED**: `ignoreDirectoryNames` (`[]string`)
76+
77+
Deprecated in favour of `indexing.ignoreDirectoryNames`
78+
79+
## `indexing.ignoreDirectoryNames` (`[]string`)
7280

7381
This allows excluding directories from being indexed upon initialization by passing a list of directory names.
7482

internal/langserver/handlers/initialize.go

+32-13
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ func getTelemetryProperties(out *settings.DecodedOptions) map[string]interface{}
183183
"lsVersion": "",
184184
}
185185

186-
properties["options.rootModulePaths"] = len(out.Options.ModulePaths) > 0
187-
properties["options.rootModulePaths"] = len(out.Options.ModulePaths) > 0
188-
properties["options.excludeModulePaths"] = len(out.Options.ExcludeModulePaths) > 0
186+
properties["options.rootModulePaths"] = len(out.Options.XLegacyModulePaths) > 0
187+
properties["options.excludeModulePaths"] = len(out.Options.XLegacyExcludeModulePaths) > 0
189188
properties["options.commandPrefix"] = len(out.Options.CommandPrefix) > 0
190-
properties["options.ignoreDirectoryNames"] = len(out.Options.IgnoreDirectoryNames) > 0
189+
properties["options.indexing.ignoreDirectoryNames"] = len(out.Options.IgnoreDirectoryNames) > 0
190+
properties["options.indexing.ignorePaths"] = len(out.Options.IgnorePaths) > 0
191191
properties["options.experimentalFeatures.prefillRequiredFields"] = out.Options.ExperimentalFeatures.PrefillRequiredFields
192192
properties["options.experimentalFeatures.validateOnSave"] = out.Options.ExperimentalFeatures.ValidateOnSave
193193
properties["options.ignoreSingleFileWarning"] = out.Options.IgnoreSingleFileWarning
@@ -248,14 +248,33 @@ func (svc *service) setupWalker(ctx context.Context, params lsp.InitializeParams
248248
return err
249249
}
250250

251-
var excludeModulePaths []string
252-
for _, rawPath := range options.ExcludeModulePaths {
251+
if len(options.XLegacyModulePaths) != 0 {
252+
jrpc2.ServerFromContext(ctx).Notify(ctx, "window/showMessage", &lsp.ShowMessageParams{
253+
Type: lsp.Warning,
254+
Message: fmt.Sprintf("rootModulePaths (%q) is deprecated (no-op), add a folder to workspace "+
255+
"instead if you'd like it to be indexed", options.XLegacyModulePaths),
256+
})
257+
}
258+
if len(options.XLegacyExcludeModulePaths) != 0 {
259+
jrpc2.ServerFromContext(ctx).Notify(ctx, "window/showMessage", &lsp.ShowMessageParams{
260+
Type: lsp.Warning,
261+
Message: fmt.Sprintf("excludeModulePaths (%q) is deprecated (no-op), use indexing.ignorePaths instead",
262+
options.XLegacyExcludeModulePaths),
263+
})
264+
}
265+
266+
var ignoredPaths []string
267+
for _, rawPath := range options.IgnorePaths {
253268
modPath, err := resolvePath(root.Path(), rawPath)
254269
if err != nil {
255-
svc.logger.Printf("Ignoring excluded module path %s: %s", rawPath, err)
270+
jrpc2.ServerFromContext(ctx).Notify(ctx, "window/showMessage", &lsp.ShowMessageParams{
271+
Type: lsp.Warning,
272+
Message: fmt.Sprintf("Unable to ignore path (unsupported or invalid URI): %s: %s",
273+
rawPath, err),
274+
})
256275
continue
257276
}
258-
excludeModulePaths = append(excludeModulePaths, modPath)
277+
ignoredPaths = append(ignoredPaths, modPath)
259278
}
260279

261280
err = svc.stateStore.WalkerPaths.EnqueueDir(root)
@@ -268,7 +287,7 @@ func (svc *service) setupWalker(ctx context.Context, params lsp.InitializeParams
268287
if !uri.IsURIValid(folder.URI) {
269288
jrpc2.ServerFromContext(ctx).Notify(ctx, "window/showMessage", &lsp.ShowMessageParams{
270289
Type: lsp.Warning,
271-
Message: fmt.Sprintf("Ignoring workspace folder (unsupport or invalid URI) %s."+
290+
Message: fmt.Sprintf("Ignoring workspace folder (unsupported or invalid URI) %s."+
272291
" This is most likely bug, please report it.", folder.URI),
273292
})
274293
continue
@@ -288,10 +307,10 @@ func (svc *service) setupWalker(ctx context.Context, params lsp.InitializeParams
288307
}
289308
}
290309

291-
svc.closedDirWalker.SetIgnoreDirectoryNames(options.IgnoreDirectoryNames)
292-
svc.closedDirWalker.SetExcludeModulePaths(excludeModulePaths)
293-
svc.openDirWalker.SetIgnoreDirectoryNames(options.IgnoreDirectoryNames)
294-
svc.openDirWalker.SetExcludeModulePaths(excludeModulePaths)
310+
svc.closedDirWalker.SetIgnoredDirectoryNames(options.IgnoreDirectoryNames)
311+
svc.closedDirWalker.SetIgnoredPaths(ignoredPaths)
312+
svc.openDirWalker.SetIgnoredDirectoryNames(options.IgnoreDirectoryNames)
313+
svc.openDirWalker.SetIgnoredPaths(ignoredPaths)
295314

296315
return nil
297316
}

internal/langserver/handlers/initialize_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func TestInitialize_ignoreDirectoryNames(t *testing.T) {
196196
"rootUri": %q,
197197
"processId": 12345,
198198
"initializationOptions": {
199-
"ignoreDirectoryNames": [%q]
199+
"indexing.ignoreDirectoryNames": [%q]
200200
}
201201
}`, tmpDir.URI, "ignore")})
202202
waitForWalkerPath(t, ss, wc, tmpDir)

internal/settings/settings.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ type ExperimentalFeatures struct {
1616
}
1717

1818
type Options struct {
19-
// ModulePaths describes a list of absolute paths to modules to load
20-
ModulePaths []string `mapstructure:"rootModulePaths"`
21-
ExcludeModulePaths []string `mapstructure:"excludeModulePaths"`
2219
CommandPrefix string `mapstructure:"commandPrefix"`
23-
IgnoreDirectoryNames []string `mapstructure:"ignoreDirectoryNames"`
20+
IgnoreDirectoryNames []string `mapstructure:"indexing.ignoreDirectoryNames"`
21+
IgnorePaths []string `mapstructure:"indexing.ignorePaths"`
2422

2523
// ExperimentalFeatures encapsulates experimental features users can opt into.
2624
ExperimentalFeatures ExperimentalFeatures `mapstructure:"experimentalFeatures"`
@@ -30,13 +28,12 @@ type Options struct {
3028
TerraformExecPath string `mapstructure:"terraformExecPath"`
3129
TerraformExecTimeout string `mapstructure:"terraformExecTimeout"`
3230
TerraformLogFilePath string `mapstructure:"terraformLogFilePath"`
31+
32+
XLegacyModulePaths []string `mapstructure:"rootModulePaths"`
33+
XLegacyExcludeModulePaths []string `mapstructure:"excludeModulePaths"`
3334
}
3435

3536
func (o *Options) Validate() error {
36-
if len(o.ModulePaths) != 0 && len(o.ExcludeModulePaths) != 0 {
37-
return fmt.Errorf("at most one of `rootModulePaths` and `excludeModulePaths` could be set")
38-
}
39-
4037
if o.TerraformExecPath != "" {
4138
path := o.TerraformExecPath
4239
if !filepath.IsAbs(path) {

internal/settings/settings_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ func TestDecodeOptions_nil(t *testing.T) {
1616
}
1717
opts := out.Options
1818

19-
if opts.ModulePaths != nil {
20-
t.Fatalf("expected no options for nil, %#v given", opts.ModulePaths)
19+
if opts.IgnoreDirectoryNames != nil {
20+
t.Fatalf("expected no options for nil, %#v given", opts.IgnoreDirectoryNames)
2121
}
2222
}
2323

2424
func TestDecodeOptions_wrongType(t *testing.T) {
2525
_, err := DecodeOptions(map[string]interface{}{
26-
"rootModulePaths": "/random/path",
26+
"indexing.ignorePaths": "/random/path",
2727
})
2828
if err == nil {
2929
t.Fatal("expected decoding of wrong type to result in error")
@@ -32,14 +32,14 @@ func TestDecodeOptions_wrongType(t *testing.T) {
3232

3333
func TestDecodeOptions_success(t *testing.T) {
3434
out, err := DecodeOptions(map[string]interface{}{
35-
"rootModulePaths": []string{"/random/path"},
35+
"indexing.ignorePaths": []string{"/random/path"},
3636
})
3737
if err != nil {
3838
t.Fatal(err)
3939
}
4040
opts := out.Options
4141
expectedPaths := []string{"/random/path"}
42-
if diff := cmp.Diff(expectedPaths, opts.ModulePaths); diff != "" {
42+
if diff := cmp.Diff(expectedPaths, opts.IgnorePaths); diff != "" {
4343
t.Fatalf("options mismatch: %s", diff)
4444
}
4545
}
@@ -55,7 +55,7 @@ func TestValidate_IgnoreDirectoryNames_error(t *testing.T) {
5555

5656
for _, table := range tables {
5757
out, err := DecodeOptions(map[string]interface{}{
58-
"ignoreDirectoryNames": []string{table.input},
58+
"indexing.ignoreDirectoryNames": []string{table.input},
5959
})
6060
if err != nil {
6161
t.Fatal(err)
@@ -69,7 +69,7 @@ func TestValidate_IgnoreDirectoryNames_error(t *testing.T) {
6969
}
7070
func TestValidate_IgnoreDirectoryNames_success(t *testing.T) {
7171
out, err := DecodeOptions(map[string]interface{}{
72-
"ignoreDirectoryNames": []string{"directory"},
72+
"indexing.ignoreDirectoryNames": []string{"directory"},
7373
})
7474
if err != nil {
7575
t.Fatal(err)

internal/walker/walker.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ type Walker struct {
4444

4545
cancelFunc context.CancelFunc
4646

47-
excludeModulePaths map[string]bool
48-
ignoreDirectoryNames map[string]bool
47+
ignoredPaths map[string]bool
48+
ignoredDirectoryNames map[string]bool
4949
}
5050

5151
type WalkFunc func(ctx context.Context, modHandle document.DirHandle) (job.IDs, error)
@@ -62,32 +62,32 @@ type ModuleStore interface {
6262

6363
func NewWalker(fs fs.ReadDirFS, pathStore PathStore, modStore ModuleStore, walkFunc WalkFunc) *Walker {
6464
return &Walker{
65-
fs: fs,
66-
pathStore: pathStore,
67-
modStore: modStore,
68-
walkFunc: walkFunc,
69-
logger: discardLogger,
70-
ignoreDirectoryNames: skipDirNames,
65+
fs: fs,
66+
pathStore: pathStore,
67+
modStore: modStore,
68+
walkFunc: walkFunc,
69+
logger: discardLogger,
70+
ignoredDirectoryNames: skipDirNames,
7171
}
7272
}
7373

7474
func (w *Walker) SetLogger(logger *log.Logger) {
7575
w.logger = logger
7676
}
7777

78-
func (w *Walker) SetExcludeModulePaths(excludeModulePaths []string) {
79-
w.excludeModulePaths = make(map[string]bool)
80-
for _, path := range excludeModulePaths {
81-
w.excludeModulePaths[path] = true
78+
func (w *Walker) SetIgnoredPaths(ignoredPaths []string) {
79+
w.ignoredPaths = make(map[string]bool)
80+
for _, path := range ignoredPaths {
81+
w.ignoredPaths[path] = true
8282
}
8383
}
8484

85-
func (w *Walker) SetIgnoreDirectoryNames(ignoreDirectoryNames []string) {
85+
func (w *Walker) SetIgnoredDirectoryNames(ignoredDirectoryNames []string) {
8686
if w.cancelFunc != nil {
8787
panic("cannot set ignorelist after walking started")
8888
}
89-
for _, path := range ignoreDirectoryNames {
90-
w.ignoreDirectoryNames[path] = true
89+
for _, path := range ignoredDirectoryNames {
90+
w.ignoredDirectoryNames[path] = true
9191
}
9292
}
9393

@@ -154,12 +154,12 @@ func (w *Walker) collectJobIds(jobIds job.IDs) {
154154
}
155155

156156
func (w *Walker) isSkippableDir(dirName string) bool {
157-
_, ok := w.ignoreDirectoryNames[dirName]
157+
_, ok := w.ignoredDirectoryNames[dirName]
158158
return ok
159159
}
160160

161161
func (w *Walker) walk(ctx context.Context, dir document.DirHandle) error {
162-
if _, ok := w.excludeModulePaths[dir.Path()]; ok {
162+
if _, ok := w.ignoredPaths[dir.Path()]; ok {
163163
w.logger.Printf("skipping walk due to dir being excluded: %s", dir.Path())
164164
return nil
165165
}

0 commit comments

Comments
 (0)