Skip to content

Commit

Permalink
debug yamlls DocumentSymbol race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin committed Jul 25, 2024
1 parent e2c89b8 commit 9a7308d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 124 deletions.
117 changes: 0 additions & 117 deletions internal/adapter/yamlls/documentSync.go

This file was deleted.

32 changes: 30 additions & 2 deletions internal/adapter/yamlls/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,38 @@ import (
lsp "go.lsp.dev/protocol"
)

func getDocumentSymbolsError(text string) []interface{} {
return []interface{}{
lsp.DocumentSymbol{
Name: text,
Range: lsp.Range{
End: lsp.Position{
Line: 999999,
},
},
},
}
}

func (yamllsConnector Connector) CallDocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolParams) (result []interface{}, err error) {
if yamllsConnector.server == nil {
return []interface{}{}, nil
if !yamllsConnector.configured {
logger.Error("DocumentSymbol was called before yamlls was configured")
return getDocumentSymbolsError("Yamlls was not configured yet, editing the document should trigger a refesh"), nil
}
return getDocumentSymbolsError("Yamlls is disabled"), nil
}

yamllsResult, err := yamllsConnector.server.DocumentSymbol(ctx, params)
if err != nil {
logger.Error("Failed getting document symbol from yamlls", err)
return getDocumentSymbolsError("Could not get DocumentSymbol from yamlls"), nil
}

if len(yamllsResult) == 0 {
return getDocumentSymbolsError("Yamlls did not find any DocumentSymbols yet"), nil
}

return yamllsConnector.server.DocumentSymbol(ctx, params)
logger.Debug("DocumentSymbol yamlls result ", yamllsResult)
return yamllsResult, err
}
16 changes: 11 additions & 5 deletions internal/adapter/yamlls/yamlls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import (
var logger = log.GetLogger()

type Connector struct {
config util.YamllsConfiguration
server protocol.Server
documents *lsplocal.DocumentStore
client protocol.Client
config util.YamllsConfiguration
server protocol.Server
documents *lsplocal.DocumentStore
client protocol.Client
configured bool
}

func NewConnector(ctx context.Context, yamllsConfiguration util.YamllsConfiguration, client protocol.Client, documents *lsplocal.DocumentStore) *Connector {
Expand Down Expand Up @@ -68,7 +69,12 @@ func NewConnector(ctx context.Context, yamllsConfiguration util.YamllsConfigurat
io.Copy(os.Stderr, strderr)

Check failure on line 69 in internal/adapter/yamlls/yamlls.go

View workflow job for this annotation

GitHub Actions / lint (1.21.5, ubuntu-latest)

Error return value of `io.Copy` is not checked (errcheck)
}()

yamllsConnector := Connector{documents: documents, config: yamllsConfiguration, client: client}
yamllsConnector := Connector{
config: yamllsConfiguration,
documents: documents,
client: client,
configured: true,
}

zapLogger, _ := zap.NewProduction()
_, _, server := protocol.NewClient(ctx, yamllsConnector, jsonrpc2.NewStream(readWriteCloser), zapLogger)
Expand Down

0 comments on commit 9a7308d

Please sign in to comment.