From d981197cd7e95cc97020b0d467c91589e05c0ced Mon Sep 17 00:00:00 2001 From: Carl Verge <1541056+carlverge@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:56:18 -0700 Subject: [PATCH] default configuration in lsp server without notifications --- editor/code/package.json | 6 ++-- editor/code/src/extension.ts | 3 +- pkg/lsp/handler.go | 58 +++++++++++++++++++++++++----------- pkg/lsp/lsp.go | 2 +- 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/editor/code/package.json b/editor/code/package.json index aad9ca4..ad5859a 100644 --- a/editor/code/package.json +++ b/editor/code/package.json @@ -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" }, @@ -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", diff --git a/editor/code/src/extension.ts b/editor/code/src/extension.ts index 52f997b..ff07423 100644 --- a/editor/code/src/extension.ts +++ b/editor/code/src/extension.ts @@ -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 { diff --git a/pkg/lsp/handler.go b/pkg/lsp/handler.go index 68c44e1..bdddbf9 100644 --- a/pkg/lsp/handler.go +++ b/pkg/lsp/handler.go @@ -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 { diff --git a/pkg/lsp/lsp.go b/pkg/lsp/lsp.go index ba5f633..9bb3cb2 100644 --- a/pkg/lsp/lsp.go +++ b/pkg/lsp/lsp.go @@ -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()