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

feat: hide docstrings in completion by default #139

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ Environment variables:

func main() {
config := server.Configuration{
JPaths: filepath.SplitList(os.Getenv("JSONNET_PATH")),
FormattingOptions: formatter.DefaultOptions(),
JPaths: filepath.SplitList(os.Getenv("JSONNET_PATH")),
FormattingOptions: formatter.DefaultOptions(),
ShowDocstringInCompletion: false,
}
log.SetLevel(log.InfoLevel)

Expand All @@ -82,6 +83,8 @@ func main() {
config.EnableLintDiagnostics = true
case "--eval-diags":
config.EnableEvalDiagnostics = true
case "--show-docstrings":
config.ShowDocstringInCompletion = true
}
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/server/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (s *Server) completionFromStack(line string, stack *nodestack.NodeStack, vm
}

completionPrefix := strings.Join(indexes[:len(indexes)-1], ".")
return createCompletionItemsFromRanges(ranges, completionPrefix, line, position)
return s.createCompletionItemsFromRanges(ranges, completionPrefix, line, position)
}

func (s *Server) completionStdLib(line string) []protocol.CompletionItem {
Expand Down Expand Up @@ -132,7 +132,7 @@ func (s *Server) completionStdLib(line string) []protocol.CompletionItem {
return items
}

func createCompletionItemsFromRanges(ranges []processing.ObjectRange, completionPrefix, currentLine string, position protocol.Position) []protocol.CompletionItem {
func (s *Server) createCompletionItemsFromRanges(ranges []processing.ObjectRange, completionPrefix, currentLine string, position protocol.Position) []protocol.CompletionItem {
var items []protocol.CompletionItem
labels := make(map[string]bool)

Expand All @@ -147,6 +147,10 @@ func createCompletionItemsFromRanges(ranges []processing.ObjectRange, completion
continue
}

if !s.configuration.ShowDocstringInCompletion && strings.HasPrefix(label, "#") {
continue
}

// Ignore the current field
if strings.Contains(currentLine, label+":") && completionPrefix == "self" {
continue
Expand Down
11 changes: 9 additions & 2 deletions pkg/server/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ type Configuration struct {
ExtCode map[string]string
FormattingOptions formatter.Options

EnableEvalDiagnostics bool
EnableLintDiagnostics bool
EnableEvalDiagnostics bool
EnableLintDiagnostics bool
ShowDocstringInCompletion bool
}

func (s *Server) DidChangeConfiguration(_ context.Context, params *protocol.DidChangeConfigurationParams) error {
Expand Down Expand Up @@ -70,6 +71,12 @@ func (s *Server) DidChangeConfiguration(_ context.Context, params *protocol.DidC
} else {
return fmt.Errorf("%w: unsupported settings value for enable_lint_diagnostics. expected boolean. got: %T", jsonrpc2.ErrInvalidParams, sv)
}
case "show_docstring_in_completion":
if boolVal, ok := sv.(bool); ok {
s.configuration.ShowDocstringInCompletion = boolVal
} else {
return fmt.Errorf("%w: unsupported settings value for show_docstring_in_completion. expected boolean. got: %T", jsonrpc2.ErrInvalidParams, sv)
}
case "ext_vars":
newVars, err := s.parseExtVars(sv)
if err != nil {
Expand Down
Loading