Skip to content

Commit

Permalink
default configuration in lsp server without notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
carlverge authored Mar 18, 2024
1 parent 1f4648f commit d981197
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 22 deletions.
6 changes: 3 additions & 3 deletions editor/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "Apache License Version 2.0",
"description": "Jsonnet IDE Support. Autocomplete, lint, format, goto def, signature help.",
"icon": "images/icon.png",
"version": "0.2.5",
"version": "0.2.6",
"engines": {
"vscode": "^1.75.0"
},
Expand Down Expand Up @@ -97,9 +97,9 @@
},
"jsonnet.lsp.diag.evaluate": {
"type": "boolean",
"default": true,
"default": false,
"scope": "resource",
"description": "Enable live evaluation diagnostics"
"description": "Enable live evaluation diagnostics. (Warning: can expensive)"
},
"jsonnet.lsp.fmt.indent": {
"type": "number",
Expand Down
3 changes: 2 additions & 1 deletion editor/code/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ async function startClient(binaryPath: string, cfg: WorkspaceConfiguration): Pro
clientOptions
);

client.start();
await client.start();
await client.sendNotification(DidChangeConfigurationNotification.type, {settings: cfg});
}

function builtinBinaryPath(): string {
Expand Down
58 changes: 41 additions & 17 deletions pkg/lsp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,48 @@ import (
"go.lsp.dev/uri"
)


type DiagConfiguration struct {
Linter bool `json:"linter"`
Evaluate bool `json:"evaluate"`
}

type FmtConfiguration struct {
Indent int `json:"indent"`
MaxBlankLines int `json:"maxBlankLines"`
StringStyle string `json:"stringStyle"`
CommentStyle string `json:"commentStyle"`
PrettyFieldNames bool `json:"prettyFieldNames"`
PadArrays bool `json:"padArrays"`
PadObjects bool `json:"padObjects"`
SortImports bool `json:"sortImports"`
ImplicitPlus bool `json:"implicitPlus"`
}

func defaultConfiguration() *Configuration {
return &Configuration{
Diag: DiagConfiguration{
Linter: true,
Evaluate: false,
},
Fmt: FmtConfiguration{
Indent: 2,
StringStyle: "\"",
CommentStyle: "//",
MaxBlankLines: 2,
PrettyFieldNames: true,
PadArrays: false,
PadObjects: true,
ImplicitPlus: true,
SortImports: true,
},
}
}

type Configuration struct {
Diag struct {
Linter bool `json:"linter"`
Evaluate bool `json:"evaluate"`
} `json:"diag"`
JPaths []string `json:"jpaths"`

Fmt struct {
Indent int `json:"indent"`
MaxBlankLines int `json:"maxBlankLines"`
StringStyle string `json:"stringStyle"`
CommentStyle string `json:"commentStyle"`
PrettyFieldNames bool `json:"prettyFieldNames"`
PadArrays bool `json:"padArrays"`
PadObjects bool `json:"padObjects"`
SortImports bool `json:"sortImports"`
ImplicitPlus bool `json:"implicitPlus"`
} `json:"fmt"`
Diag DiagConfiguration `json:"diag"`
JPaths []string `json:"jpaths"`
Fmt FmtConfiguration `json:"fmt"`
}

func (c *Configuration) FormatterOptions() formatter.Options {
Expand Down
2 changes: 1 addition & 1 deletion pkg/lsp/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func RunServer(ctx context.Context, stdout *os.File) error {
overlay: overlay.NewOverlay(),
cancel: cancel,
notifier: notifier,
config: &Configuration{},
config: defaultConfiguration(),
}

handler := srv.Handler()
Expand Down

0 comments on commit d981197

Please sign in to comment.