Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools / gopls@v0.5.2 / internal / hooks / hooks.go
1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Package hooks adds all the standard gopls implementations.
6 // This can be used in tests without needing to use the gopls main, and is
7 // also the place to edit for custom builds of gopls.
8 package hooks // import "golang.org/x/tools/gopls/internal/hooks"
9
10 import (
11         "context"
12         "regexp"
13
14         "golang.org/x/tools/internal/lsp/source"
15         "mvdan.cc/gofumpt/format"
16         "mvdan.cc/xurls/v2"
17 )
18
19 func Options(options *source.Options) {
20         if options.GoDiff {
21                 options.ComputeEdits = ComputeEdits
22         }
23         options.URLRegexp = urlRegexp()
24         options.GofumptFormat = func(ctx context.Context, src []byte) ([]byte, error) {
25                 return format.Source(src, format.Options{})
26         }
27         updateAnalyzers(options)
28 }
29
30 func urlRegexp() *regexp.Regexp {
31         // Ensure links are matched as full words, not anywhere.
32         re := regexp.MustCompile(`\b(` + xurls.Relaxed().String() + `)\b`)
33         re.Longest()
34         return re
35 }