diff --git a/gopls/doc/settings.md b/gopls/doc/settings.md index f0e7314444..1c1b1e68b4 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 a106c61a54..43ce2ca348 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 826faa65b9..3cea6a5b51 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":