From be791d07ff540698e45cf82cd66daadd120266ac Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Thu, 8 Apr 2021 14:33:27 -0400 Subject: [PATCH] internal/lsp/source: small fixes to directory filters Add missing newlines in documentation, and allow trailing slashes in the filter expressions. Change-Id: I90106b209222d8cc542e3517c6ff6edb2569243d Reviewed-on: https://go-review.googlesource.com/c/tools/+/308453 Trust: Heschi Kreinick Run-TryBot: Heschi Kreinick gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Robert Findley --- gopls/doc/settings.md | 3 +++ internal/lsp/source/api_json.go | 2 +- internal/lsp/source/options.go | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gopls/doc/settings.md b/gopls/doc/settings.md index f0e73144444..1c1b1e68b4e 100644 --- a/gopls/doc/settings.md +++ b/gopls/doc/settings.md @@ -63,8 +63,11 @@ the last filter that applies to a path controls whether it is included. The path prefix can be empty, so an initial `-` excludes everything. Examples: + Exclude node_modules: `-node_modules` + Include only project_a: `-` (exclude everything), `+project_a` + Include only project_a, but not node_modules inside it: `-`, `+project_a`, `-project_a/node_modules` Default: `[]`. diff --git a/internal/lsp/source/api_json.go b/internal/lsp/source/api_json.go index a106c61a54c..43ce2ca3481 100755 --- a/internal/lsp/source/api_json.go +++ b/internal/lsp/source/api_json.go @@ -34,7 +34,7 @@ var GeneratedAPIJSON = &APIJSON{ { Name: "directoryFilters", Type: "[]string", - Doc: "directoryFilters can be used to exclude unwanted directories from the\nworkspace. By default, all directories are included. Filters are an\noperator, `+` to include and `-` to exclude, followed by a path prefix\nrelative to the workspace folder. They are evaluated in order, and\nthe last filter that applies to a path controls whether it is included.\nThe path prefix can be empty, so an initial `-` excludes everything.\n\nExamples:\nExclude node_modules: `-node_modules`\nInclude only project_a: `-` (exclude everything), `+project_a`\nInclude only project_a, but not node_modules inside it: `-`, `+project_a`, `-project_a/node_modules`\n", + Doc: "directoryFilters can be used to exclude unwanted directories from the\nworkspace. By default, all directories are included. Filters are an\noperator, `+` to include and `-` to exclude, followed by a path prefix\nrelative to the workspace folder. They are evaluated in order, and\nthe last filter that applies to a path controls whether it is included.\nThe path prefix can be empty, so an initial `-` excludes everything.\n\nExamples:\n\nExclude node_modules: `-node_modules`\n\nInclude only project_a: `-` (exclude everything), `+project_a`\n\nInclude only project_a, but not node_modules inside it: `-`, `+project_a`, `-project_a/node_modules`\n", EnumKeys: EnumKeys{ ValueType: "", Keys: nil, diff --git a/internal/lsp/source/options.go b/internal/lsp/source/options.go index 826faa65b98..3cea6a5b511 100644 --- a/internal/lsp/source/options.go +++ b/internal/lsp/source/options.go @@ -213,8 +213,11 @@ type BuildOptions struct { // The path prefix can be empty, so an initial `-` excludes everything. // // Examples: + // // Exclude node_modules: `-node_modules` + // // Include only project_a: `-` (exclude everything), `+project_a` + // // Include only project_a, but not node_modules inside it: `-`, `+project_a`, `-project_a/node_modules` DirectoryFilters []string @@ -747,7 +750,7 @@ func (o *Options) set(name string, value interface{}, seen map[string]struct{}) result.errorf("invalid filter %q, must start with + or -", filter) return result } - filters = append(filters, filepath.FromSlash(filter)) + filters = append(filters, strings.TrimRight(filepath.FromSlash(filter), "/")) } o.DirectoryFilters = filters case "completionDocumentation":