Skip to content

Commit

Permalink
feat: hide docstrings in completion by default (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
Duologic authored May 16, 2024
1 parent ff6d26f commit d286ca6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
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

0 comments on commit d286ca6

Please sign in to comment.