1
0
mirror of https://github.com/golang/go synced 2024-11-18 23:14:43 -07:00
go/internal/lsp
Muir Manders 7baacfbe02 internal/lsp: support function literal completions
Now we will offer function literal completions when we know the
expected type is a function. For example:

sort.Slice(someSlice, <>)

will offer the completion "func(...) {}" which if selected will
insert:

func(i, j int) bool {<>}

I opted to use an abbreviated label "func(...) {}" because function
signatures can be quite long/verbose with all the type names in there.

The only interesting challenge is how to handle signatures that don't
name the parameters. For example,

func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) {

does not name the "ResponseWriter" and "Request" parameters. I went
with a minimal effort approach where we try abbreviating the type
names, so the literal completion item for "handler" would look like:

func(<rw> ResponseWriter, <r> *Request) {<>}

where <> denote placeholders. The user can tab through quickly if they
like the abbreviations, otherwise they can rename them.

For unnamed types or if the abbreviation would duplicate a previous
abbreviation, we fall back to "_" as the parameter name. The user will
have to rename the parameter before they can use it.

One side effect of this is that we cannot support function literal
completions with unnamed parameters unless the user has enabled
snippet placeholders.

Change-Id: Ic0ec81e85cd8de79bff73314e80e722f10f8c84c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/193699
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-09-18 23:49:17 +00:00
..
browser internal/lsp: add version and bug commands 2019-05-11 04:16:02 +00:00
cache internal/lsp: ensure that an AST cannot be nil without an error 2019-09-18 18:10:22 +00:00
cmd internal/lsp: show errors when the user is in the wrong directory 2019-09-17 21:41:55 +00:00
debug internal/lsp/debug: bump version number for release 2019-09-16 17:20:13 +00:00
diff all: fix more typos 2019-09-11 15:13:14 +00:00
fuzzy all: fix more typos 2019-09-11 15:13:14 +00:00
protocol internal/lsp: reduce usage of column mapper 2019-09-16 22:00:07 +00:00
snippet internal/lsp: add literal completion candidates 2019-09-18 17:13:17 +00:00
source internal/lsp: support function literal completions 2019-09-18 23:49:17 +00:00
telemetry internal/lsp/cache: add additional spans for tracing 2019-09-05 21:33:45 +00:00
testdata internal/lsp: support function literal completions 2019-09-18 23:49:17 +00:00
tests internal/lsp: support function literal completions 2019-09-18 23:49:17 +00:00
code_action.go internal/lsp: remove helpers for getting packages 2019-09-17 16:23:42 +00:00
completion.go internal/lsp: add literal completion candidates 2019-09-18 17:13:17 +00:00
definition.go x/tools/gopls: convert to the august, 2019 version of the LSP protocol 2019-09-08 13:59:31 +00:00
diagnostics.go internal/lsp: show errors when the user is in the wrong directory 2019-09-17 21:41:55 +00:00
folding_range.go internal/lsp: use the view options, not the session options 2019-09-11 22:59:40 +00:00
format.go internal/lsp: change to protocol.TextEdit for formatting 2019-09-06 17:54:09 +00:00
general.go internal/lsp: change names used by per-folder configs 2019-09-18 20:53:03 +00:00
highlight.go x/tools/gopls: convert to the august, 2019 version of the LSP protocol 2019-09-08 13:59:31 +00:00
hover.go internal/lsp: use the view options, not the session options 2019-09-11 22:59:40 +00:00
link.go internal/lsp: distinguish parse errors from actual errors 2019-09-17 21:21:32 +00:00
lsp_test.go internal/lsp: support function literal completions 2019-09-18 23:49:17 +00:00
references.go internal/lsp: remove the GetToken and GetAST functions 2019-09-09 18:10:35 +00:00
rename.go x/tools/gopls: convert to the august, 2019 version of the LSP protocol 2019-09-08 13:59:31 +00:00
reset_golden.sh internal/lsp: fix definition tests to use golden files 2019-05-10 21:06:55 +00:00
server.go internal/lsp: only build a view when we have its configuration 2019-09-10 14:40:41 +00:00
signature_help.go x/tools/gopls: convert to the august, 2019 version of the LSP protocol 2019-09-08 13:59:31 +00:00
symbols.go internal/lsp: switch to using protocol positions for document symbols 2019-09-06 18:11:17 +00:00
text_synchronization.go internal/lsp: return errors from diagnostics 2019-09-17 21:08:37 +00:00
util.go internal/lsp: use protocol.TextEdits in suggested fixes 2019-09-07 02:01:28 +00:00
watched_files.go internal/lsp: fix bug in diagnostics for watched changed files 2019-09-18 22:02:41 +00:00
workspace.go internal/lsp: merge session and view options into one 2019-09-11 19:36:49 +00:00