Skip to content

Commit

Permalink
cmd/govim: completion options to disable fuzzy or deep matching
Browse files Browse the repository at this point in the history
Provide options to disable the now-default fuzzy and/or deep completion
modes.

Whilst we await golang/go#32258, users will
need to set these config options in their .vimrc and then restart Vim.
Even then there is a race condition for Vim8 package users that might
mean even this doesn't work.
  • Loading branch information
myitcv committed Sep 7, 2019
1 parent 74faeda commit 836e588
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
16 changes: 16 additions & 0 deletions autoload/govim/config.vim
Expand Up @@ -74,9 +74,25 @@ function! s:validExperimentalCursorTriggeredHoverPopupOptions(v)
return s:validExperimentalMouseTriggeredHoverPopupOptions(a:v)
endfunction

function! s:validCompletionDeepCompletionsDisable(v)
if type(a:v) != 0 && type(a:v) != 6
return [v:false, "must be of type number or bool"
endif
return [v:true, ""]
endfunction

function! s:validCompletionFuzzyMatchingDisable(v)
if type(a:v) != 0 && type(a:v) != 6
return [v:false, "must be of type number or bool"
endif
return [v:true, ""]
endfunction

let s:validators = {
\ "FormatOnSave": function("s:validFormatOnSave"),
\ "QuickfixAutoDiagnosticsDisable": function("s:validQuickfixAutoDiagnosticsDisable"),
\ "CompletionDeepCompletionsDisable": function("s:validCompletionDeepCompletionsDisable"),
\ "CompletionFuzzyMatchingDisable": function("s:validCompletionFuzzyMatchingDisable"),
\ "QuickfixSignsDisable": function("s:validQuickfixSignsDisable"),
\ "ExperimentalMouseTriggeredHoverPopupOptions": function("s:validExperimentalMouseTriggeredHoverPopupOptions"),
\ "ExperimentalCursorTriggeredHoverPopupOptions": function("s:validExperimentalCursorTriggeredHoverPopupOptions"),
Expand Down
8 changes: 8 additions & 0 deletions cmd/govim/config/config.go
Expand Up @@ -29,6 +29,14 @@ type Config struct {
// Default: false (0)
QuickfixSignsDisable bool

// CompletionDeepCompletiionsDisable disables gopls' deep completion option
// in the derivation of completion candidates.
CompletionDeepCompletionsDisable bool

// CompletionFuzzyMatchingDisable disables gopls' fuzzy matching in the
// derivation of completion candidates.
CompletionFuzzyMatchingDisable bool

// ExperimentalMouseTriggeredHoverPopupOptions is a map of options to apply
// when creating hover-based popup windows triggered by the mouse hovering
// over an identifier. It corresponds to the second argument to popup_create
Expand Down
10 changes: 8 additions & 2 deletions cmd/govim/gopls_client.go
Expand Up @@ -12,8 +12,10 @@ import (
)

const (
goplsConfigNoDocsOnHover = "noDocsOnHover"
goplsConfigHoverKind = "hoverKind"
goplsConfigNoDocsOnHover = "noDocsOnHover"
goplsConfigHoverKind = "hoverKind"
goplsDisableDeepCompletion = "disableDeepCompletion"
goplsDisableFuzzyMatching = "disableFuzzyMatching"
)

var _ protocol.Client = (*govimplugin)(nil)
Expand Down Expand Up @@ -58,7 +60,11 @@ func (g *govimplugin) Configuration(ctxt context.Context, params *protocol.Confi
res := make([]interface{}, len(params.Items))
conf := make(map[string]interface{})
conf[goplsConfigHoverKind] = "FullDocumentation"
conf[goplsDisableDeepCompletion] = g.vimstate.config.CompletionDeepCompletionsDisable
conf[goplsDisableFuzzyMatching] = g.vimstate.config.CompletionFuzzyMatchingDisable
res[0] = conf

g.logGoplsClientf("Configuration response: %v", pretty.Sprint(res))
return res, nil
}
func (g *govimplugin) ApplyEdit(context.Context, *protocol.ApplyWorkspaceEditParams) (*protocol.ApplyWorkspaceEditResponse, error) {
Expand Down
22 changes: 19 additions & 3 deletions cmd/govim/vimstate.go
Expand Up @@ -68,14 +68,18 @@ func (v *vimstate) setConfig(args ...json.RawMessage) (interface{}, error) {
FormatOnSave config.FormatOnSave
QuickfixAutoDiagnosticsDisable int
QuickfixSignsDisable int
CompletionDeepCompletionsDisable int
CompletionFuzzyMatchingDisable int
ExperimentalMouseTriggeredHoverPopupOptions map[string]json.RawMessage
ExperimentalCursorTriggeredHoverPopupOptions map[string]json.RawMessage
}
v.Parse(args[0], &c)
v.config = config.Config{
FormatOnSave: c.FormatOnSave,
QuickfixSignsDisable: c.QuickfixSignsDisable != 0,
QuickfixAutoDiagnosticsDisable: c.QuickfixAutoDiagnosticsDisable != 0,
FormatOnSave: c.FormatOnSave,
QuickfixSignsDisable: c.QuickfixSignsDisable != 0,
QuickfixAutoDiagnosticsDisable: c.QuickfixAutoDiagnosticsDisable != 0,
CompletionDeepCompletionsDisable: c.CompletionDeepCompletionsDisable != 0,
CompletionFuzzyMatchingDisable: c.CompletionFuzzyMatchingDisable != 0,
}
if len(c.ExperimentalMouseTriggeredHoverPopupOptions) > 0 {
v.config.ExperimentalMouseTriggeredHoverPopupOptions = make(map[string]interface{})
Expand Down Expand Up @@ -103,6 +107,18 @@ func (v *vimstate) setConfig(args ...json.RawMessage) (interface{}, error) {
return nil, v.updateQuickfix()
}
}

// TODO: when https://github.com/golang/go/issues/32258 is fixed, we will
// need to trigger a didChangeConfiguration call here for gopls-related
// config, e.g.:
//
// CompletionDeepCompletiionsDisable
// CompletionFuzzyMatchingDisable
//
// As a workaround for now, users will need to set config in their .vimrc
// and then restart Vim (even then there is a race condition for Vim8
// package users that might mean even this doesn't work.)

return nil, nil
}

Expand Down

0 comments on commit 836e588

Please sign in to comment.