golang/go

x/tools/gopls: workspace/didChangeWatchedFiles RegisterCapability globs are too broad

Aperta

#41.504 aperta il 20 set 2020

 (11 commenti) (1 reazione) (0 assegnatari)Go (19.008 fork)batch import
NeedsFixToolsgoplshelp wanted

Metriche repository

Star
 (133.883 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

What version of Go are you using (go version)?

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

What did you do?

Given the following setup:

-- blah/blah.go --
package blah

const Message = "hello"
-- blah/go.mod --
module blah.com

go 1.16
-- go.mod --
module mod.com

go 1.16

require blah.com v0.0.0-00010101000000-000000000000

replace blah.com => ./blah
-- go.sum --
-- main.go --
package main

import (
	"fmt"

	"blah.com"
)

func main() {
	fmt.Println(blah.Message)
}

I loaded govim.

What did you expect to see?

Precise workspace/didChangeWatchedFiles globls in any RegisterCapability call.

What did you see instead?

RegisterCapability: &protocol.RegistrationParams{
    Registrations: {
        {
            ID:              "workspace/didChangeWatchedFiles-0",
            Method:          "workspace/didChangeWatchedFiles",
            RegisterOptions: map[string]interface {}{
                "watchers": []interface {}{
                    map[string]interface {}{
                        "globPattern": "**/*.{go,mod,sum}",
                        "kind":        float64(7),
                    },
                    map[string]interface {}{
                        "globPattern": "/home/myitcv/gostuff/src/github.com/myitcv/playground/blah/**/*.{go,mod,sum}",
                        "kind":        float64(7),
                    },
                    map[string]interface {}{
                        "globPattern": "/home/myitcv/gostuff/src/github.com/myitcv/playground/**/*.{go,mod,sum}",
                        "kind":        float64(7),
                    },
                },
            },
        },
    },
}

Side note: the working directory of govim (and therefore gopls) in this case was /home/myitcv/gostuff/src/github.com/myitcv/playground, so the first and third watchers appear to be duplicates.

If I understand the glob spec, **/*.{go,mod,sum} means "all .go, .mod and .sum files in all subdirectories".

The recursive descent into subdirectories does not stop at directories whose names start with . or _, or those that contain go.mod files. This can, and does, make this watch very expensive if, for example, you have a directory like node_modules that contains lots of files that are and always will be totally irrelevant to gopls (the advice here is to put a go.mod in that directory).

I suspect this situation is somewhat a function of the LSP spec, but can these globs be made more specific in some way?

An approach to .gitignore patterns would work for example.


cc @stamblerre

FYI @leitzler

Guida contributor