on main help sign in
feat(lsp): load defaults by either name or command (#1109)
0da5e6bCarlos Alexandro Becker
crush.json+1−3
@@ -1,8 +1,6 @@
1{
1{
2 "$schema": "https://charm.land/crush.json",
2 "$schema": "https://charm.land/crush.json",
3 "lsp": {
3 "lsp": {
4− "Go": {
4+ "gopls": {}
5− "command": "gopls"
6− }
7 }
5 }
8}
6}
internal/config/config.go+1−1
@@ -118,7 +118,7 @@ type MCPConfig struct {
118
118
119type LSPConfig struct {
119type LSPConfig struct {
120 Disabled bool `json:"disabled,omitempty" jsonschema:"description=Whether this LSP server is disabled,default=false"`
120 Disabled bool `json:"disabled,omitempty" jsonschema:"description=Whether this LSP server is disabled,default=false"`
121− Command string `json:"command" jsonschema:"required,description=Command to execute for the LSP server,example=gopls"`
121+ Command string `json:"command,omitempty" jsonschema:"required,description=Command to execute for the LSP server,example=gopls"`
122 Args []string `json:"args,omitempty" jsonschema:"description=Arguments to pass to the LSP server command"`
122 Args []string `json:"args,omitempty" jsonschema:"description=Arguments to pass to the LSP server command"`
123 Env map[string]string `json:"env,omitempty" jsonschema:"description=Environment variables to set to the LSP server command"`
123 Env map[string]string `json:"env,omitempty" jsonschema:"description=Environment variables to set to the LSP server command"`
124 FileTypes []string `json:"filetypes,omitempty" jsonschema:"description=File types this LSP server handles,example=go,example=mod,example=rs,example=c,example=js,example=ts"`
124 FileTypes []string `json:"filetypes,omitempty" jsonschema:"description=File types this LSP server handles,example=go,example=mod,example=rs,example=c,example=js,example=ts"`
internal/config/load.go+11−2
@@ -351,10 +351,13 @@ func (c *Config) applyLSPDefaults() {
351
351
352 // Apply defaults to each LSP configuration
352 // Apply defaults to each LSP configuration
353 for name, cfg := range c.LSP {
353 for name, cfg := range c.LSP {
354− // Try to get defaults from powernap based on command name
354+ // Try to get defaults from powernap based on name or command name.
355 base, ok := configManager.GetServer(name)
355 base, ok := configManager.GetServer(name)
356 if !ok {
356 if !ok {
357+ base, ok = configManager.GetServer(cfg.Command)
358+ if !ok {
357− continue
359+ continue
360+ }
358 }
361 }
359 if cfg.Options == nil {
362 if cfg.Options == nil {
360 cfg.Options = base.Settings
363 cfg.Options = base.Settings
@@ -368,6 +371,12 @@ func (c *Config) applyLSPDefaults() {
368 if len(cfg.RootMarkers) == 0 {
371 if len(cfg.RootMarkers) == 0 {
369 cfg.RootMarkers = base.RootMarkers
372 cfg.RootMarkers = base.RootMarkers
370 }
373 }
374+ if len(cfg.Args) == 0 {
375+ cfg.Args = base.Args
376+ }
377+ if len(cfg.Env) == 0 {
378+ cfg.Env = base.Environment
379+ }
371 // Update the config in the map
380 // Update the config in the map
372 c.LSP[name] = cfg
381 c.LSP[name] = cfg
373 }
382 }