mirror of
https://github.com/golang/go
synced 2024-11-18 10:14:45 -07:00
6a8222ee25
gopls has many settings. We want to automatically generate documentation, and we want to allow clients to perform their own validation if they so desire. Using all three of AST, type information, and reflection, generate a JSON description of the settings and their default values. Add a gopls command that prints it. Add a documentation generator that uses it to write settings.md. I assumed that everything not explicitly documented was experimental, and moved it into that section. I also moved expandWorkspaceToModule to experimental; I hope it's not long for this world, personally. Along the way, rename many fields, make the enum matching case insensitive, and add a stringer call so that the defaults print nicely. Fixes golang/go#33544. Change-Id: Ibb652002933e355ed3c6038d6ca48345b39b3025 Reviewed-on: https://go-review.googlesource.com/c/tools/+/252322 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
// Copyright 2020 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package lsp
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"golang.org/x/tools/internal/event"
|
|
"golang.org/x/tools/internal/lsp/mod"
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
)
|
|
|
|
func (s *Server) codeLens(ctx context.Context, params *protocol.CodeLensParams) ([]protocol.CodeLens, error) {
|
|
snapshot, fh, ok, release, err := s.beginFileRequest(ctx, params.TextDocument.URI, source.UnknownKind)
|
|
defer release()
|
|
if !ok {
|
|
return nil, err
|
|
}
|
|
var lensFuncs map[string]source.LensFunc
|
|
switch fh.Kind() {
|
|
case source.Mod:
|
|
lensFuncs = mod.LensFuncs()
|
|
case source.Go:
|
|
lensFuncs = source.LensFuncs()
|
|
default:
|
|
// Unsupported file kind for a code lens.
|
|
return nil, nil
|
|
}
|
|
var result []protocol.CodeLens
|
|
for lens, lf := range lensFuncs {
|
|
if !snapshot.View().Options().Codelens[lens] {
|
|
continue
|
|
}
|
|
added, err := lf(ctx, snapshot, fh)
|
|
// Code lens is called on every keystroke, so we should just operate in
|
|
// a best-effort mode, ignoring errors.
|
|
if err != nil {
|
|
event.Error(ctx, fmt.Sprintf("code lens %s failed", lens), err)
|
|
continue
|
|
}
|
|
result = append(result, added...)
|
|
}
|
|
return result, nil
|
|
}
|