Skip to content

Commit

Permalink
cmd/govim: add config option for case sensitive completion (#529)
Browse files Browse the repository at this point in the history
This is a WIP PR that depends on an as-yet-unmerged CL. Full commit
message to follow
  • Loading branch information
myitcv committed Sep 26, 2019
1 parent 45380c4 commit 9e916d5
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 11 deletions.
5 changes: 5 additions & 0 deletions autoload/govim/config.vim
Expand Up @@ -69,6 +69,10 @@ function! s:validStaticcheck(v)
return s:validBool(a:v)
endfunction

function! s:validCompletionCaseSensitive(v)
return s:validBool(a:v)
endfunction

function! s:validExperimentalMouseTriggeredHoverPopupOptions(v)
if has_key(a:v, "line")
if type(a:v["line"]) != 0
Expand All @@ -94,6 +98,7 @@ let s:validators = {
\ "CompletionFuzzyMatching": function("s:validCompletionFuzzyMatching"),
\ "QuickfixSigns": function("s:validQuickfixSigns"),
\ "Staticcheck": function("s:validStaticcheck"),
\ "CompletionCaseSensitive": function("s:validCompletionCaseSensitive"),
\ "ExperimentalMouseTriggeredHoverPopupOptions": function("s:validExperimentalMouseTriggeredHoverPopupOptions"),
\ "ExperimentalCursorTriggeredHoverPopupOptions": function("s:validExperimentalCursorTriggeredHoverPopupOptions"),
\ }
5 changes: 5 additions & 0 deletions cmd/govim/config/config.go
Expand Up @@ -60,6 +60,11 @@ type Config struct {
// Staticcheck enables staticcheck analyses in gopls
Staticcheck *bool `json:",omitempty"`

// CompletionCaseSensitive configures gopls' matching to be case sensitive.
// This option only takes effect when both CompletionDeepCompletions and
// CompletionFuzzyMatching are set to false.
CompletionCaseSensitive *bool `json:",omitempty"`

// 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
14 changes: 9 additions & 5 deletions cmd/govim/gopls_client.go
Expand Up @@ -12,11 +12,12 @@ import (
)

const (
goplsConfigNoDocsOnHover = "noDocsOnHover"
goplsConfigHoverKind = "hoverKind"
goplsDeepCompletion = "deepCompletion"
goplsFuzzyMatching = "fuzzyMatching"
goplsStaticcheck = "staticcheck"
goplsConfigNoDocsOnHover = "noDocsOnHover"
goplsConfigHoverKind = "hoverKind"
goplsDeepCompletion = "deepCompletion"
goplsFuzzyMatching = "fuzzyMatching"
goplsStaticcheck = "staticcheck"
goplsCaseSensitiveCompletion = "caseSensitiveCompletion"
)

var _ protocol.Client = (*govimplugin)(nil)
Expand Down Expand Up @@ -101,6 +102,9 @@ func (g *govimplugin) Configuration(ctxt context.Context, params *protocol.Param
if g.vimstate.config.Staticcheck != nil {
conf[goplsStaticcheck] = *g.vimstate.config.Staticcheck
}
if g.vimstate.config.CompletionCaseSensitive != nil {
conf[goplsCaseSensitiveCompletion] = *g.vimstate.config.CompletionCaseSensitive
}
res[0] = conf

g.logGoplsClientf("Configuration response: %v", pretty.Sprint(res))
Expand Down
14 changes: 8 additions & 6 deletions cmd/govim/internal/vimconfig/vimconfig.go
Expand Up @@ -13,18 +13,20 @@ type VimConfig struct {
CompletionDeepCompletions *int
CompletionFuzzyMatching *int
Staticcheck *int
CompletionCaseSensitive *int
ExperimentalMouseTriggeredHoverPopupOptions *map[string]interface{}
ExperimentalCursorTriggeredHoverPopupOptions *map[string]interface{}
}

func (c *VimConfig) ToConfig(d config.Config) config.Config {
v := config.Config{
FormatOnSave: c.FormatOnSave,
QuickfixSigns: boolVal(c.QuickfixSigns, d.QuickfixSigns),
QuickfixAutoDiagnostics: boolVal(c.QuickfixAutoDiagnostics, d.QuickfixAutoDiagnostics),
CompletionDeepCompletions: boolVal(c.CompletionDeepCompletions, d.CompletionDeepCompletions),
CompletionFuzzyMatching: boolVal(c.CompletionFuzzyMatching, d.CompletionFuzzyMatching),
Staticcheck: boolVal(c.Staticcheck, d.Staticcheck),
FormatOnSave: c.FormatOnSave,
QuickfixSigns: boolVal(c.QuickfixSigns, d.QuickfixSigns),
QuickfixAutoDiagnostics: boolVal(c.QuickfixAutoDiagnostics, d.QuickfixAutoDiagnostics),
CompletionDeepCompletions: boolVal(c.CompletionDeepCompletions, d.CompletionDeepCompletions),
CompletionFuzzyMatching: boolVal(c.CompletionFuzzyMatching, d.CompletionFuzzyMatching),
Staticcheck: boolVal(c.Staticcheck, d.Staticcheck),
CompletionCaseSensitive: boolVal(c.CompletionCaseSensitive, d.CompletionCaseSensitive),
ExperimentalMouseTriggeredHoverPopupOptions: copyMap(c.ExperimentalMouseTriggeredHoverPopupOptions, d.ExperimentalMouseTriggeredHoverPopupOptions),
ExperimentalCursorTriggeredHoverPopupOptions: copyMap(c.ExperimentalCursorTriggeredHoverPopupOptions, d.ExperimentalCursorTriggeredHoverPopupOptions),
}
Expand Down
90 changes: 90 additions & 0 deletions cmd/govim/testdata/scenario_casesensitivecompletion/complete.txt
@@ -0,0 +1,90 @@
# Test that ominfunc complete works. This simple test uses an existing file on disk that
# already has the relevant import required for the completion.

vim ex 'e main.go'
errlogmatch -wait 30s 'PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{\n\S+:\s+URI:\s+"file://'$WORK/main.go

# lower from lo
vim ex 'call cursor(7,1)'
vim normal Slo
vim ex 'execute \"normal A\\<C-X>\\<C-O>\"'
vim ex 'w'
cmp main.go main.go.lowercomplete
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

# UPPER from UP
vim ex 'call cursor(7,1)'
vim normal SUP
vim ex 'execute \"normal A\\<C-X>\\<C-O>\"'
vim ex 'w'
cmp main.go main.go.uppercomplete
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

# lower from LO
vim ex 'call cursor(7,1)'
vim normal SLO
vim ex 'execute \"normal A\\<C-X>\\<C-O>\"'
vim ex 'w'
cmp main.go main.go.lowermiss
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

# UPPER from up
vim ex 'call cursor(7,1)'
vim normal Sup
vim ex 'execute \"normal A\\<C-X>\\<C-O>\"'
vim ex 'w'
cmp main.go main.go.uppermiss
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

-- go.mod --
module mod.com

-- main.go --
package main

func main() {
var lower int
var UPPER int

//
}
-- main.go.lowercomplete --
package main

func main() {
var lower int
var UPPER int

lower
}
-- main.go.uppercomplete --
package main

func main() {
var lower int
var UPPER int

UPPER
}
-- main.go.lowermiss --
package main

func main() {
var lower int
var UPPER int

LO
}
-- main.go.uppermiss --
package main

func main() {
var lower int
var UPPER int

up
}
@@ -0,0 +1,6 @@
{
"FormatOnSave": "goimports",
"CompletionDeepCompletions": false,
"CompletionFuzzyMatching": false,
"CompletionCaseSensitive": true
}
1 change: 1 addition & 0 deletions cmd/govim/vimstate.go
Expand Up @@ -90,6 +90,7 @@ func (v *vimstate) setConfig(args ...json.RawMessage) (interface{}, error) {
//
// CompletionDeepCompletiionsDisable
// CompletionFuzzyMatchingDisable
// CompletionCaseSensitive
//
// 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
Expand Down

0 comments on commit 9e916d5

Please sign in to comment.