Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gopls: add maxUnimportedPackageNames option that makes the number of completion candidates for unimported packages configurable #442

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions gopls/doc/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ fields in completion responses.

Default: `false`.

##### **maxUnimportedPackageNames** *int*

max number of completion candidates for unimported packages.

Default: `5`.

##### **completionBudget** *time.Duration*

**This setting is for debugging purposes only.**
Expand Down
1 change: 1 addition & 0 deletions gopls/internal/lsp/protocol/generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func writeserver() {
fmt.Fprintln(out, fileHdr)
out.WriteString(
`import (
"bytes"
"context"
"encoding/json"

Expand Down
4 changes: 3 additions & 1 deletion gopls/internal/lsp/protocol/generate/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ func genCase(method string, param, result *Type, dir string) {
nm = "ParamConfiguration" // gopls compatibility
}
fmt.Fprintf(out, "\t\tvar params %s\n", nm)
fmt.Fprintf(out, "\t\tif err := json.Unmarshal(r.Params(), &params); err != nil {\n")
fmt.Fprintf(out, "\t\tdecoder := json.NewDecoder(bytes.NewReader(r.Params()))\n")
fmt.Fprintf(out, "\t\tdecoder.UseNumber()\n")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed because the default json.Unmarshal treats a number as a float type.

fmt.Fprintf(out, "\t\tif err := decoder.Decode(&params); err != nil {\n")
fmt.Fprintf(out, "\t\t\treturn true, sendParseError(ctx, reply, err)\n\t\t}\n")
p = ", &params"
}
Expand Down