golang/go

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

开放

#41,504 创建于 2020年9月20日

 (11 条评论) (1 个反应) (0 位负责人)Go (19,008 个派生)batch import
NeedsFixToolsgoplshelp wanted

仓库指标

星标
 (133,883 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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

贡献者指南