mirror of
https://github.com/golang/go
synced 2024-11-18 18:44:42 -07:00
internal/lsp: refactor and document options
This change cleans up the structure of the Options struct in order to clearly delineate which options should be configurable for the user. Follow-up work is needed to refactor the completion options to fit into this structure, as well as to make sure that the name of the field is the name of the setting. This will make it easier to generate markdown documentation from the code. Also, remove options that are no longer in-use and mark them as deprecated. Change-Id: Ib34ae25789e21b76077a564601e487fbebfc5f48 Reviewed-on: https://go-review.googlesource.com/c/tools/+/212519 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
parent
8647d4c879
commit
99d11d0e63
@ -92,7 +92,7 @@ func (s *Server) initialize(ctx context.Context, params *protocol.ParamInitializ
|
|||||||
TriggerCharacters: []string{"(", ","},
|
TriggerCharacters: []string{"(", ","},
|
||||||
},
|
},
|
||||||
TextDocumentSync: &protocol.TextDocumentSyncOptions{
|
TextDocumentSync: &protocol.TextDocumentSyncOptions{
|
||||||
Change: options.TextDocumentSyncKind,
|
Change: protocol.Incremental,
|
||||||
OpenClose: true,
|
OpenClose: true,
|
||||||
Save: protocol.SaveOptions{
|
Save: protocol.SaveOptions{
|
||||||
IncludeText: false,
|
IncludeText: false,
|
||||||
@ -130,7 +130,7 @@ func (s *Server) initialized(ctx context.Context, params *protocol.InitializedPa
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.WatchFileChanges && options.DynamicWatchedFilesSupported {
|
if options.DynamicWatchedFilesSupported {
|
||||||
registrations = append(registrations, protocol.Registration{
|
registrations = append(registrations, protocol.Registration{
|
||||||
ID: "workspace/didChangeWatchedFiles",
|
ID: "workspace/didChangeWatchedFiles",
|
||||||
Method: "workspace/didChangeWatchedFiles",
|
Method: "workspace/didChangeWatchedFiles",
|
||||||
|
@ -43,11 +43,22 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
DefaultOptions = Options{
|
DefaultOptions = Options{
|
||||||
Env: os.Environ(),
|
ClientOptions: DefaultClientOptions,
|
||||||
TextDocumentSyncKind: protocol.Incremental,
|
ServerOptions: DefaultServerOptions,
|
||||||
HoverKind: SynopsisDocumentation,
|
UserOptions: DefaultUserOptions,
|
||||||
InsertTextFormat: protocol.PlainTextTextFormat,
|
DebuggingOptions: DefaultDebuggingOptions,
|
||||||
|
ExperimentalOptions: DefaultExperimentalOptions,
|
||||||
|
Hooks: DefaultHooks,
|
||||||
|
}
|
||||||
|
DefaultClientOptions = ClientOptions{
|
||||||
|
InsertTextFormat: protocol.SnippetTextFormat,
|
||||||
PreferredContentFormat: protocol.Markdown,
|
PreferredContentFormat: protocol.Markdown,
|
||||||
|
ConfigurationSupported: true,
|
||||||
|
DynamicConfigurationSupported: true,
|
||||||
|
DynamicWatchedFilesSupported: true,
|
||||||
|
LineFoldingOnly: false,
|
||||||
|
}
|
||||||
|
DefaultServerOptions = ServerOptions{
|
||||||
SupportedCodeActions: map[FileKind]map[protocol.CodeActionKind]bool{
|
SupportedCodeActions: map[FileKind]map[protocol.CodeActionKind]bool{
|
||||||
Go: {
|
Go: {
|
||||||
protocol.SourceOrganizeImports: true,
|
protocol.SourceOrganizeImports: true,
|
||||||
@ -61,6 +72,10 @@ var (
|
|||||||
SupportedCommands: []string{
|
SupportedCommands: []string{
|
||||||
"tidy", // for go.mod files
|
"tidy", // for go.mod files
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
DefaultUserOptions = UserOptions{
|
||||||
|
Env: os.Environ(),
|
||||||
|
HoverKind: SynopsisDocumentation,
|
||||||
Completion: CompletionOptions{
|
Completion: CompletionOptions{
|
||||||
Documentation: true,
|
Documentation: true,
|
||||||
Deep: true,
|
Deep: true,
|
||||||
@ -68,61 +83,84 @@ var (
|
|||||||
Literal: true,
|
Literal: true,
|
||||||
Budget: 100 * time.Millisecond,
|
Budget: 100 * time.Millisecond,
|
||||||
},
|
},
|
||||||
|
LinkTarget: "pkg.go.dev",
|
||||||
|
}
|
||||||
|
DefaultHooks = Hooks{
|
||||||
ComputeEdits: myers.ComputeEdits,
|
ComputeEdits: myers.ComputeEdits,
|
||||||
URLRegexp: regexp.MustCompile(`(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?`),
|
URLRegexp: regexp.MustCompile(`(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?`),
|
||||||
Analyzers: defaultAnalyzers,
|
Analyzers: defaultAnalyzers,
|
||||||
GoDiff: true,
|
GoDiff: true,
|
||||||
LinkTarget: "pkg.go.dev",
|
}
|
||||||
|
DefaultExperimentalOptions = ExperimentalOptions{
|
||||||
TempModfile: false,
|
TempModfile: false,
|
||||||
}
|
}
|
||||||
|
DefaultDebuggingOptions = DebuggingOptions{}
|
||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
// Env is the current set of environment overrides on this view.
|
ClientOptions
|
||||||
Env []string
|
ServerOptions
|
||||||
|
UserOptions
|
||||||
|
DebuggingOptions
|
||||||
|
ExperimentalOptions
|
||||||
|
Hooks
|
||||||
|
}
|
||||||
|
|
||||||
// BuildFlags is used to adjust the build flags applied to the view.
|
type ClientOptions struct {
|
||||||
BuildFlags []string
|
|
||||||
|
|
||||||
HoverKind HoverKind
|
|
||||||
DisabledAnalyses map[string]struct{}
|
|
||||||
|
|
||||||
StaticCheck bool
|
|
||||||
GoDiff bool
|
|
||||||
|
|
||||||
WatchFileChanges bool
|
|
||||||
InsertTextFormat protocol.InsertTextFormat
|
InsertTextFormat protocol.InsertTextFormat
|
||||||
ConfigurationSupported bool
|
ConfigurationSupported bool
|
||||||
DynamicConfigurationSupported bool
|
DynamicConfigurationSupported bool
|
||||||
DynamicWatchedFilesSupported bool
|
DynamicWatchedFilesSupported bool
|
||||||
PreferredContentFormat protocol.MarkupKind
|
PreferredContentFormat protocol.MarkupKind
|
||||||
LineFoldingOnly bool
|
LineFoldingOnly bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerOptions struct {
|
||||||
SupportedCodeActions map[FileKind]map[protocol.CodeActionKind]bool
|
SupportedCodeActions map[FileKind]map[protocol.CodeActionKind]bool
|
||||||
|
|
||||||
SupportedCommands []string
|
SupportedCommands []string
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Remove the option once we are certain there are no issues here.
|
type UserOptions struct {
|
||||||
TextDocumentSyncKind protocol.TextDocumentSyncKind
|
// Env is the current set of environment overrides on this view.
|
||||||
|
Env []string
|
||||||
|
|
||||||
Completion CompletionOptions
|
// BuildFlags is used to adjust the build flags applied to the view.
|
||||||
|
BuildFlags []string
|
||||||
|
|
||||||
ComputeEdits diff.ComputeEdits
|
// HoverKind specifies the format of the content for hover requests.
|
||||||
URLRegexp *regexp.Regexp
|
HoverKind HoverKind
|
||||||
|
|
||||||
Analyzers map[string]*analysis.Analyzer
|
// DisabledAnalyses specify analyses that the user would like to disable.
|
||||||
|
DisabledAnalyses map[string]struct{}
|
||||||
|
|
||||||
|
// StaticCheck enables additional analyses from staticcheck.io.
|
||||||
|
StaticCheck bool
|
||||||
|
|
||||||
|
// LinkTarget is the website used for documentation.
|
||||||
|
LinkTarget string
|
||||||
|
|
||||||
// LocalPrefix is used to specify goimports's -local behavior.
|
// LocalPrefix is used to specify goimports's -local behavior.
|
||||||
LocalPrefix string
|
LocalPrefix string
|
||||||
|
|
||||||
VerboseOutput bool
|
Completion CompletionOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
type Hooks struct {
|
||||||
|
GoDiff bool
|
||||||
|
ComputeEdits diff.ComputeEdits
|
||||||
|
URLRegexp *regexp.Regexp
|
||||||
|
Analyzers map[string]*analysis.Analyzer
|
||||||
|
}
|
||||||
|
|
||||||
|
type ExperimentalOptions struct {
|
||||||
// WARNING: This configuration will be changed in the future.
|
// WARNING: This configuration will be changed in the future.
|
||||||
// It only exists while this feature is under development.
|
// It only exists while this feature is under development.
|
||||||
// Disable use of the -modfile flag in Go 1.14.
|
// Disable use of the -modfile flag in Go 1.14.
|
||||||
TempModfile bool
|
TempModfile bool
|
||||||
|
}
|
||||||
|
|
||||||
LinkTarget string
|
type DebuggingOptions struct {
|
||||||
|
VerboseOutput bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type CompletionOptions struct {
|
type CompletionOptions struct {
|
||||||
@ -241,12 +279,6 @@ func (o *Options) set(name string, value interface{}) OptionResult {
|
|||||||
}
|
}
|
||||||
o.BuildFlags = flags
|
o.BuildFlags = flags
|
||||||
|
|
||||||
case "noIncrementalSync":
|
|
||||||
if v, ok := result.asBool(); ok && v {
|
|
||||||
o.TextDocumentSyncKind = protocol.Full
|
|
||||||
}
|
|
||||||
case "watchFileChanges":
|
|
||||||
result.setBool(&o.WatchFileChanges)
|
|
||||||
case "completionDocumentation":
|
case "completionDocumentation":
|
||||||
result.setBool(&o.Completion.Documentation)
|
result.setBool(&o.Completion.Documentation)
|
||||||
case "usePlaceholders":
|
case "usePlaceholders":
|
||||||
@ -312,9 +344,6 @@ func (o *Options) set(name string, value interface{}) OptionResult {
|
|||||||
case "staticcheck":
|
case "staticcheck":
|
||||||
result.setBool(&o.StaticCheck)
|
result.setBool(&o.StaticCheck)
|
||||||
|
|
||||||
case "go-diff":
|
|
||||||
result.setBool(&o.GoDiff)
|
|
||||||
|
|
||||||
case "local":
|
case "local":
|
||||||
localPrefix, ok := value.(string)
|
localPrefix, ok := value.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -349,6 +378,15 @@ func (o *Options) set(name string, value interface{}) OptionResult {
|
|||||||
result.State = OptionDeprecated
|
result.State = OptionDeprecated
|
||||||
result.Replacement = "completeUnimported"
|
result.Replacement = "completeUnimported"
|
||||||
|
|
||||||
|
case "noIncrementalSync":
|
||||||
|
result.State = OptionDeprecated
|
||||||
|
|
||||||
|
case "watchFileChanges":
|
||||||
|
result.State = OptionDeprecated
|
||||||
|
|
||||||
|
case "go-diff":
|
||||||
|
result.State = OptionDeprecated
|
||||||
|
|
||||||
default:
|
default:
|
||||||
result.State = OptionUnexpected
|
result.State = OptionUnexpected
|
||||||
}
|
}
|
||||||
|
@ -132,11 +132,6 @@ func (s *Server) changedText(ctx context.Context, uri span.URI, changes []protoc
|
|||||||
return []byte(changes[0].Text), nil
|
return []byte(changes[0].Text), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// We only accept an incremental change if that's what the server expects.
|
|
||||||
if s.session.Options().TextDocumentSyncKind == protocol.Full {
|
|
||||||
return nil, errors.Errorf("expected a full content change, received incremental changes for %s", uri)
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.applyIncrementalChanges(ctx, uri, changes)
|
return s.applyIncrementalChanges(ctx, uri, changes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,9 +20,6 @@ func (s *Server) didChangeWatchedFiles(ctx context.Context, params *protocol.Did
|
|||||||
ctx := telemetry.File.With(ctx, uri)
|
ctx := telemetry.File.With(ctx, uri)
|
||||||
|
|
||||||
for _, view := range s.session.Views() {
|
for _, view := range s.session.Views() {
|
||||||
if !view.Options().WatchFileChanges {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
action := toFileAction(change.Type)
|
action := toFileAction(change.Type)
|
||||||
switch action {
|
switch action {
|
||||||
case source.Change, source.Create:
|
case source.Change, source.Create:
|
||||||
|
Loading…
Reference in New Issue
Block a user