mirror of https://github.com/databricks/cli.git
added timing logging
This commit is contained in:
parent
7a522897cd
commit
b67330f837
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/databricks/cli/cmd/root"
|
"github.com/databricks/cli/cmd/root"
|
||||||
"github.com/databricks/databricks-sdk-go/httpclient"
|
"github.com/databricks/databricks-sdk-go/httpclient"
|
||||||
|
@ -68,7 +69,9 @@ func (m *LspMultiplexer) QuickFix(ctx context.Context, params *protocol.CodeActi
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("quick fixer: %w", err)
|
return nil, fmt.Errorf("quick fixer: %w", err)
|
||||||
}
|
}
|
||||||
actions = append(actions, fixes...)
|
for _, fix := range fixes {
|
||||||
|
actions = append(actions, fix)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return actions, nil
|
return actions, nil
|
||||||
}
|
}
|
||||||
|
@ -182,54 +185,30 @@ func startServer(ctx context.Context) error {
|
||||||
Initialized: initialized,
|
Initialized: initialized,
|
||||||
Shutdown: shutdown,
|
Shutdown: shutdown,
|
||||||
SetTrace: setTrace,
|
SetTrace: setTrace,
|
||||||
TextDocumentCodeAction: func(context *glsp.Context, params *protocol.CodeActionParams) (any, error) {
|
TextDocumentCodeAction: func(lsp *glsp.Context, params *protocol.CodeActionParams) (any, error) {
|
||||||
return multiplexer.QuickFix(ctx, params)
|
started := time.Now()
|
||||||
foundUcx := false
|
codeActions, err := multiplexer.QuickFix(ctx, params)
|
||||||
var codeRange protocol.Range
|
protocol.Trace(lsp,
|
||||||
for _, v := range params.Context.Diagnostics {
|
protocol.MessageTypeLog,
|
||||||
if v.Source == nil {
|
fmt.Sprintf("code action: %d items, range %v, took %s",
|
||||||
continue
|
len(codeActions),
|
||||||
}
|
params.Range,
|
||||||
if *v.Source == "databricks.labs.ucx" {
|
time.Since(started).Round(time.Millisecond).String(),
|
||||||
codeRange = v.Range
|
))
|
||||||
foundUcx = true
|
return codeActions, err
|
||||||
}
|
|
||||||
}
|
|
||||||
if !foundUcx {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
quickFix := protocol.CodeActionKindQuickFix
|
|
||||||
codeActions := []protocol.CodeAction{
|
|
||||||
{
|
|
||||||
Title: "Replace table with migrated table",
|
|
||||||
Kind: &quickFix,
|
|
||||||
Edit: &protocol.WorkspaceEdit{
|
|
||||||
DocumentChanges: []any{
|
|
||||||
protocol.TextDocumentEdit{
|
|
||||||
TextDocument: protocol.OptionalVersionedTextDocumentIdentifier{
|
|
||||||
TextDocumentIdentifier: params.TextDocument,
|
|
||||||
},
|
|
||||||
Edits: []any{
|
|
||||||
protocol.TextEdit{
|
|
||||||
Range: codeRange,
|
|
||||||
NewText: "[beep-v3]",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return codeActions, nil
|
|
||||||
},
|
|
||||||
CodeActionResolve: func(context *glsp.Context, params *protocol.CodeAction) (*protocol.CodeAction, error) {
|
|
||||||
return params, nil
|
|
||||||
},
|
},
|
||||||
TextDocumentDidOpen: func(lsp *glsp.Context, params *protocol.DidOpenTextDocumentParams) error {
|
TextDocumentDidOpen: func(lsp *glsp.Context, params *protocol.DidOpenTextDocumentParams) error {
|
||||||
|
started := time.Now()
|
||||||
problems, err := multiplexer.Lint(ctx, params.TextDocument.URI)
|
problems, err := multiplexer.Lint(ctx, params.TextDocument.URI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
protocol.Trace(lsp,
|
||||||
|
protocol.MessageTypeLog,
|
||||||
|
fmt.Sprintf("did open: %d items: took %s",
|
||||||
|
len(problems),
|
||||||
|
time.Since(started).Round(time.Millisecond).String(),
|
||||||
|
))
|
||||||
if len(problems) == 0 {
|
if len(problems) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -240,10 +219,17 @@ func startServer(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
TextDocumentDidChange: func(lsp *glsp.Context, params *protocol.DidChangeTextDocumentParams) error {
|
TextDocumentDidChange: func(lsp *glsp.Context, params *protocol.DidChangeTextDocumentParams) error {
|
||||||
|
started := time.Now()
|
||||||
problems, err := multiplexer.Lint(ctx, params.TextDocument.URI)
|
problems, err := multiplexer.Lint(ctx, params.TextDocument.URI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
protocol.Trace(lsp,
|
||||||
|
protocol.MessageTypeLog,
|
||||||
|
fmt.Sprintf("did open: %d items: took %s",
|
||||||
|
len(problems),
|
||||||
|
time.Since(started).Round(time.Millisecond).String(),
|
||||||
|
))
|
||||||
if len(problems) == 0 {
|
if len(problems) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue