Skip to content

Commit

Permalink
fix_: tests, address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed Oct 23, 2024
1 parent 1fa4249 commit 7735ef9
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 45 deletions.
21 changes: 21 additions & 0 deletions cmd/lint-panics/analyzer/testdata/src/functions/pointers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package functions

import (
"common"
)

func init() {
runAsync(ok)
runAsyncOk(ok)
}

func runAsync(fn func()) {
go fn() // want "missing defer call to LogOnPanic"
}

func runAsyncOk(fn func()) {
go func() {
defer common.LogOnPanic()
fn()
}()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,90 +13,69 @@ type DummyClient struct {
}

func NewDummyClient(logger *zap.Logger) *DummyClient {
if logger == nil {
logger = zap.NewNop()

Check warning on line 17 in cmd/lint-panics/gopls/dummy_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/gopls/dummy_client.go#L17

Added line #L17 was not covered by tests
}
return &DummyClient{
logger: nil, //logger.Named("client"),
logger: logger,
}
}

func (d *DummyClient) Progress(ctx context.Context, params *protocol.ProgressParams) (err error) {
if d.logger != nil {
d.logger.Debug("client: Progress", zap.Any("params", params))
}
d.logger.Debug("client: Progress", zap.Any("params", params))
return

Check warning on line 26 in cmd/lint-panics/gopls/dummy_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/gopls/dummy_client.go#L24-L26

Added lines #L24 - L26 were not covered by tests
}
func (d *DummyClient) WorkDoneProgressCreate(ctx context.Context, params *protocol.WorkDoneProgressCreateParams) (err error) {
if d.logger != nil {
d.logger.Debug("client: WorkDoneProgressCreate")
}
d.logger.Debug("client: WorkDoneProgressCreate")
return nil

Check warning on line 30 in cmd/lint-panics/gopls/dummy_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/gopls/dummy_client.go#L28-L30

Added lines #L28 - L30 were not covered by tests
}

func (d *DummyClient) LogMessage(ctx context.Context, params *protocol.LogMessageParams) (err error) {
if d.logger != nil {
d.logger.Debug("client: LogMessage", zap.Any("message", params))
}
d.logger.Debug("client: LogMessage", zap.Any("message", params))
return nil
}

func (d *DummyClient) PublishDiagnostics(ctx context.Context, params *protocol.PublishDiagnosticsParams) (err error) {
if d.logger != nil {
d.logger.Debug("client: PublishDiagnostics")
}
d.logger.Debug("client: PublishDiagnostics")
return nil

Check warning on line 40 in cmd/lint-panics/gopls/dummy_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/gopls/dummy_client.go#L38-L40

Added lines #L38 - L40 were not covered by tests
}

func (d *DummyClient) ShowMessage(ctx context.Context, params *protocol.ShowMessageParams) (err error) {
if d.logger != nil {
d.logger.Debug("client: ShowMessage", zap.Any("message", params))
}
d.logger.Debug("client: ShowMessage", zap.Any("message", params))
return nil
}

func (d *DummyClient) ShowMessageRequest(ctx context.Context, params *protocol.ShowMessageRequestParams) (result *protocol.MessageActionItem, err error) {
if d.logger != nil {
d.logger.Debug("client: ShowMessageRequest", zap.Any("message", params))
}
d.logger.Debug("client: ShowMessageRequest", zap.Any("message", params))
return nil, nil

Check warning on line 50 in cmd/lint-panics/gopls/dummy_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/gopls/dummy_client.go#L48-L50

Added lines #L48 - L50 were not covered by tests
}

func (d *DummyClient) Telemetry(ctx context.Context, params interface{}) (err error) {
if d.logger != nil {
d.logger.Debug("client: Telemetry")
}
d.logger.Debug("client: Telemetry")
return nil

Check warning on line 55 in cmd/lint-panics/gopls/dummy_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/gopls/dummy_client.go#L53-L55

Added lines #L53 - L55 were not covered by tests
}

func (d *DummyClient) RegisterCapability(ctx context.Context, params *protocol.RegistrationParams) (err error) {
if d.logger != nil {
d.logger.Debug("client: RegisterCapability")
}
d.logger.Debug("client: RegisterCapability")
return nil

Check warning on line 60 in cmd/lint-panics/gopls/dummy_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/gopls/dummy_client.go#L58-L60

Added lines #L58 - L60 were not covered by tests
}

func (d *DummyClient) UnregisterCapability(ctx context.Context, params *protocol.UnregistrationParams) (err error) {
if d.logger != nil {
d.logger.Debug("client: UnregisterCapability")
}
d.logger.Debug("client: UnregisterCapability")
return nil

Check warning on line 65 in cmd/lint-panics/gopls/dummy_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/gopls/dummy_client.go#L63-L65

Added lines #L63 - L65 were not covered by tests
}

func (d *DummyClient) ApplyEdit(ctx context.Context, params *protocol.ApplyWorkspaceEditParams) (result bool, err error) {
if d.logger != nil {
d.logger.Debug("client: ApplyEdit")
}
d.logger.Debug("client: ApplyEdit")
return false, nil

Check warning on line 70 in cmd/lint-panics/gopls/dummy_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/gopls/dummy_client.go#L68-L70

Added lines #L68 - L70 were not covered by tests
}

func (d *DummyClient) Configuration(ctx context.Context, params *protocol.ConfigurationParams) (result []interface{}, err error) {
if d.logger != nil {
d.logger.Debug("client: Configuration")
}
d.logger.Debug("client: Configuration")
return nil, nil

Check warning on line 75 in cmd/lint-panics/gopls/dummy_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/gopls/dummy_client.go#L73-L75

Added lines #L73 - L75 were not covered by tests
}

func (d *DummyClient) WorkspaceFolders(ctx context.Context) (result []protocol.WorkspaceFolder, err error) {
if d.logger != nil {
d.logger.Debug("client: WorkspaceFolders")
}
d.logger.Debug("client: WorkspaceFolders")
return nil, nil

Check warning on line 80 in cmd/lint-panics/gopls/dummy_client.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/gopls/dummy_client.go#L78-L80

Added lines #L78 - L80 were not covered by tests
}
6 changes: 4 additions & 2 deletions cmd/lint-panics/gopls/gopls.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewGoplsClient(ctx context.Context, logger *zap.Logger, rootDir string) *Co

client := NewDummyClient(logger)

// Create a JSON-RPC connection using stdin and stdout
// Step 1: Create a JSON-RPC connection using stdin and stdout
gopls.cmd = exec.Command("gopls", "serve")

stdin, err := gopls.cmd.StdinPipe()
Expand All @@ -60,8 +60,10 @@ func NewGoplsClient(ctx context.Context, logger *zap.Logger, rootDir string) *Co
stdout: stdout,
})

// Step 2: Create a client for the running gopls server
ctx, gopls.conn, gopls.server = protocol.NewClient(ctx, client, stream, logger)

// Step 3: Initialize the gopls server
initParams := protocol.InitializeParams{
RootURI: uri.From("file", "", rootDir, "", ""),
InitializationOptions: map[string]interface{}{
Expand All @@ -75,7 +77,7 @@ func NewGoplsClient(ctx context.Context, logger *zap.Logger, rootDir string) *Co
panic(err)

Check warning on line 77 in cmd/lint-panics/gopls/gopls.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/gopls/gopls.go#L76-L77

Added lines #L76 - L77 were not covered by tests
}

// Step 2: Send 'initialized' notification
// Step 4: Send 'initialized' notification
err = gopls.server.Initialized(ctx, &protocol.InitializedParams{})
if err != nil {
logger.Error("Error during initialized", zap.Error(err))
Expand Down
1 change: 0 additions & 1 deletion cmd/lint-panics/testdata/goroutine_test.go

This file was deleted.

5 changes: 0 additions & 5 deletions cmd/lint-panics/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package utils

import (
gotoken "go/token"
"strconv"

"fmt"
Expand All @@ -11,10 +10,6 @@ import (
"go.uber.org/zap/zapcore"
)

func PositionURI(pos gotoken.Position) string {
return URI(pos.Filename, pos.Line)
}

func URI(path string, line int) string {
return path + ":" + strconv.Itoa(line)
}
Expand Down

0 comments on commit 7735ef9

Please sign in to comment.