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 <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/gopls/doc/settings.md b/gopls/doc/settings.md
index f0e7314..1c1b1e6 100644
--- a/gopls/doc/settings.md
+++ b/gopls/doc/settings.md
@@ -63,8 +63,11 @@
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 a106c61..43ce2ca 100755
--- a/internal/lsp/source/api_json.go
+++ b/internal/lsp/source/api_json.go
@@ -34,7 +34,7 @@
{
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 826faa6..3cea6a5 100644
--- a/internal/lsp/source/options.go
+++ b/internal/lsp/source/options.go
@@ -213,8 +213,11 @@
// 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 @@
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":