diff --git a/go.mod b/go.mod index cbf7f193..94242a67 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( go.lsp.dev/jsonrpc2 v0.10.0 go.lsp.dev/protocol v0.12.0 go.lsp.dev/uri v0.3.0 + go.uber.org/zap v1.24.0 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 k8s.io/apiextensions-apiserver v0.29.2 @@ -65,7 +66,6 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/goleak v1.2.1 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.17.0 // indirect golang.org/x/net v0.19.0 // indirect golang.org/x/oauth2 v0.10.0 // indirect diff --git a/internal/adapter/yamlls/completion.go b/internal/adapter/yamlls/completion.go index 71f9d063..b3459259 100644 --- a/internal/adapter/yamlls/completion.go +++ b/internal/adapter/yamlls/completion.go @@ -7,7 +7,7 @@ import ( ) func (yamllsConnector Connector) CallCompletion(ctx context.Context, params *lsp.CompletionParams) (*lsp.CompletionList, error) { - if yamllsConnector.Conn == nil { + if yamllsConnector.server == nil { return &lsp.CompletionList{}, nil } diff --git a/internal/adapter/yamlls/diagnostics_integration_test.go b/internal/adapter/yamlls/diagnostics_integration_test.go index 6a6a6310..90df88f0 100644 --- a/internal/adapter/yamlls/diagnostics_integration_test.go +++ b/internal/adapter/yamlls/diagnostics_integration_test.go @@ -128,7 +128,7 @@ func TestYamllsDiagnosticsIntegration(t *testing.T) { config.YamllsSettings = yamllsSettings yamllsConnector := NewConnector(config, client, documents) - if yamllsConnector.Conn == nil { + if yamllsConnector.server == nil { t.Fatal("Could not connect to yaml-language-server") } diff --git a/internal/adapter/yamlls/documentSync.go b/internal/adapter/yamlls/documentSync.go index 167d0f6c..02c9bae7 100644 --- a/internal/adapter/yamlls/documentSync.go +++ b/internal/adapter/yamlls/documentSync.go @@ -10,7 +10,7 @@ import ( ) func (yamllsConnector Connector) InitiallySyncOpenDocuments(docs []*lsplocal.Document) { - if yamllsConnector.Conn == nil { + if yamllsConnector.server == nil { return } for _, doc := range docs { @@ -25,24 +25,24 @@ func (yamllsConnector Connector) InitiallySyncOpenDocuments(docs []*lsplocal.Doc func (yamllsConnector Connector) DocumentDidOpen(ast *sitter.Tree, params lsp.DidOpenTextDocumentParams) { logger.Debug("YamllsConnector DocumentDidOpen", params.TextDocument.URI) - if yamllsConnector.Conn == nil { + if yamllsConnector.server == nil { return } params.TextDocument.Text = lsplocal.TrimTemplate(ast, params.TextDocument.Text) - err := (*yamllsConnector.Conn).Notify(context.Background(), lsp.MethodTextDocumentDidOpen, params) + err := yamllsConnector.server.DidOpen(context.Background(), ¶ms) if err != nil { logger.Error("Error calling yamlls for didOpen", err) } } func (yamllsConnector Connector) DocumentDidSave(doc *lsplocal.Document, params lsp.DidSaveTextDocumentParams) { - if yamllsConnector.Conn == nil { + if yamllsConnector.server == nil { return } params.Text = lsplocal.TrimTemplate(doc.Ast, doc.Content) - err := (*yamllsConnector.Conn).Notify(context.Background(), lsp.MethodTextDocumentDidSave, params) + err := yamllsConnector.server.DidSave(context.Background(), ¶ms) if err != nil { logger.Error("Error calling yamlls for didSave", err) } @@ -55,7 +55,7 @@ func (yamllsConnector Connector) DocumentDidSave(doc *lsplocal.Document, params } func (yamllsConnector Connector) DocumentDidChange(doc *lsplocal.Document, params lsp.DidChangeTextDocumentParams) { - if yamllsConnector.Conn == nil { + if yamllsConnector.server == nil { return } trimmedText := lsplocal.TrimTemplate(doc.Ast, doc.Content) @@ -77,14 +77,14 @@ func (yamllsConnector Connector) DocumentDidChange(doc *lsplocal.Document, param } logger.Debug("Sending DocumentDidChange", params) - err := (*yamllsConnector.Conn).Notify(context.Background(), lsp.MethodTextDocumentDidChange, params) + err := yamllsConnector.server.DidChange(context.Background(), ¶ms) if err != nil { logger.Println("Error calling yamlls for didChange", err) } } func (yamllsConnector Connector) DocumentDidChangeFullSync(doc *lsplocal.Document, params lsp.DidChangeTextDocumentParams) { - if yamllsConnector.Conn == nil { + if yamllsConnector.server == nil { return } @@ -98,7 +98,7 @@ func (yamllsConnector Connector) DocumentDidChangeFullSync(doc *lsplocal.Documen } logger.Println("Sending DocumentDidChange with full sync", params) - err := (*yamllsConnector.Conn).Notify(context.Background(), lsp.MethodTextDocumentDidChange, params) + err := yamllsConnector.server.DidChange(context.Background(), ¶ms) if err != nil { logger.Println("Error calling yamlls for didChange", err) } diff --git a/internal/adapter/yamlls/hover.go b/internal/adapter/yamlls/hover.go index 1dc3520d..92b12453 100644 --- a/internal/adapter/yamlls/hover.go +++ b/internal/adapter/yamlls/hover.go @@ -10,7 +10,7 @@ import ( // Calls the Hover method of yamlls to get a fitting hover response // If hover returns nothing appropriate, calls yamlls for completions func (yamllsConnector Connector) CallHover(ctx context.Context, params lsp.HoverParams, word string) (*lsp.Hover, error) { - if yamllsConnector.Conn == nil { + if yamllsConnector.server == nil { return &lsp.Hover{}, nil } diff --git a/internal/adapter/yamlls/initization.go b/internal/adapter/yamlls/initization.go index ff45772f..3611315e 100644 --- a/internal/adapter/yamlls/initization.go +++ b/internal/adapter/yamlls/initization.go @@ -8,9 +8,9 @@ import ( "go.lsp.dev/uri" ) -func (yamllsConnector Connector) CallInitialize(workspaceURI uri.URI) (result *lsp.InitializeResult, err error) { - if yamllsConnector.Conn == nil { - return +func (yamllsConnector Connector) CallInitialize(workspaceURI uri.URI) error { + if yamllsConnector.server == nil { + return nil } params := lsp.InitializeParams{ @@ -21,5 +21,13 @@ func (yamllsConnector Connector) CallInitialize(workspaceURI uri.URI) (result *l }, } - return yamllsConnector.server.Initialize(context.Background(), ¶ms) + _, err := yamllsConnector.server.Initialize(context.Background(), ¶ms) + if err != nil { + return err + } + err = yamllsConnector.server.DidChangeConfiguration(context.Background(), &lsp.DidChangeConfigurationParams{}) + if err != nil { + return err + } + return yamllsConnector.server.Initialized(context.Background(), &lsp.InitializedParams{}) } diff --git a/internal/adapter/yamlls/yamlls.go b/internal/adapter/yamlls/yamlls.go index 8025ae2d..b9e28265 100644 --- a/internal/adapter/yamlls/yamlls.go +++ b/internal/adapter/yamlls/yamlls.go @@ -15,7 +15,6 @@ import ( var logger = log.GetLogger() type Connector struct { - Conn *jsonrpc2.Conn config util.YamllsConfiguration server protocol.Server documents *lsplocal.DocumentStore @@ -23,7 +22,7 @@ type Connector struct { } func NewConnector(yamllsConfiguration util.YamllsConfiguration, client protocol.Client, documents *lsplocal.DocumentStore) *Connector { - yamllsCmd := exec.Command("yamlls-debug.sh", "--stdio") + yamllsCmd := exec.Command(yamllsConfiguration.Path, "--stdio") stdin, err := yamllsCmd.StdinPipe() if err != nil { @@ -59,10 +58,8 @@ func NewConnector(yamllsConfiguration util.YamllsConfiguration, client protocol. ctx := context.Background() zapLogger, _ := zap.NewProduction() - ctx, conn, server := protocol.NewClient(ctx, yamllsConnector, jsonrpc2.NewStream(readWriteCloser), zapLogger) + ctx, _, server := protocol.NewClient(ctx, yamllsConnector, jsonrpc2.NewStream(readWriteCloser), zapLogger) - // conn.Go(context.Background(), yamllsConnector.yamllsHandler(clientConn, documents)) - yamllsConnector.Conn = &conn yamllsConnector.server = server return &yamllsConnector } diff --git a/internal/handler/initialization.go b/internal/handler/initialization.go index 56cbe69d..4113787a 100644 --- a/internal/handler/initialization.go +++ b/internal/handler/initialization.go @@ -26,9 +26,6 @@ func (h *langHandler) Initialize(ctx context.Context, params *lsp.InitializePara workspaceURI = uri.File(".") } - logger.Debug("Initializing yamllsConnector") - h.yamllsConnector.CallInitialize(workspaceURI) - logger.Debug("Initializing chartStore") h.chartStore = charts.NewChartStore(workspaceURI, h.NewChartWithWatchedFiles) @@ -52,13 +49,12 @@ func (h *langHandler) Initialize(ctx context.Context, params *lsp.InitializePara }, nil } -func (h *langHandler) Initialized(ctx context.Context, params *lsp.InitializedParams) (err error) { +func (h *langHandler) Initialized(ctx context.Context, _ *lsp.InitializedParams) (err error) { go h.RetrieveWorkspaceConfiguration(ctx) return nil } func (h *langHandler) initializationWithConfig() { - logger.Println("initializationWithConfig") configureLogLevel(h.helmlsConfig) h.chartStore.SetValuesFilesConfig(h.helmlsConfig.ValuesFilesConfig) configureYamlls(h) @@ -68,8 +64,10 @@ func configureYamlls(h *langHandler) { config := h.helmlsConfig if config.YamllsConfiguration.Enabled { h.yamllsConnector = yamlls.NewConnector(config.YamllsConfiguration, h.client, h.documents) - h.yamllsConnector.CallInitialize(h.chartStore.RootURI) - h.yamllsConnector.DidChangeConfiguration() + err := h.yamllsConnector.CallInitialize(h.chartStore.RootURI) + if err != nil { + logger.Error("Error initializing yamlls", err) + } h.yamllsConnector.InitiallySyncOpenDocuments(h.documents.GetAllDocs()) } } diff --git a/internal/util/config.go b/internal/util/config.go index f0615ee4..5c65ff98 100644 --- a/internal/util/config.go +++ b/internal/util/config.go @@ -42,7 +42,7 @@ var DefaultConfig = HelmlsConfiguration{ type YamllsSchemaStoreSettings struct { Enable bool `json:"enable"` - Url string `json:"url"` + URL string `json:"url"` } type YamllsSettings struct { @@ -58,6 +58,6 @@ var DefaultYamllsSettings = YamllsSettings{ Hover: true, YamllsSchemaStoreSettings: YamllsSchemaStoreSettings{ Enable: true, - Url: "https://www.schemastore.org/api/json/catalog.json", + URL: "https://www.schemastore.org/api/json/catalog.json", }, }