Skip to content

Commit 13d9ea0

Browse files
committed
fix: add scansource to workspace scan command (#831)
1 parent d8ed9c3 commit 13d9ea0

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

application/server/execute_command_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ func Test_executeWorkspaceScanCommand_shouldAskForTrust(t *testing.T) {
122122
}, 2*time.Second, time.Millisecond)
123123
}
124124

125+
func Test_executeWorkspaceScanCommand_shouldAcceptScanSourceParam(t *testing.T) {
126+
c := testutil.UnitTest(t)
127+
loc, jsonRPCRecorder := setupServerWithCustomDI(t, c, false)
128+
129+
s := &scanner.TestScanner{}
130+
c.Workspace().AddFolder(workspace.NewFolder(c, "dummy", "dummy", s, di.HoverService(), di.ScanNotifier(), di.Notifier(), di.ScanPersister(), di.ScanStateAggregator()))
131+
// explicitly enable folder trust which is disabled by default in tests
132+
config.CurrentConfig().SetTrustedFolderFeatureEnabled(true)
133+
134+
params := lsp.ExecuteCommandParams{Command: types.WorkspaceScanCommand, Arguments: []any{"LLM"}}
135+
_, err := loc.Client.Call(ctx, "workspace/executeCommand", params)
136+
if err != nil {
137+
t.Fatal(err)
138+
}
139+
assert.Eventually(t, func() bool {
140+
return s.Calls() == 0 && checkTrustMessageRequest(jsonRPCRecorder, c)
141+
}, 2*time.Second, time.Millisecond)
142+
}
143+
125144
func Test_loginCommand_StartsAuthentication(t *testing.T) {
126145
c := testutil.UnitTest(t)
127146
loc, jsonRPCRecorder := setupServer(t, c)

domain/ide/command/workspace_scan.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121

2222
"github.com/snyk/snyk-ls/application/config"
23+
context2 "github.com/snyk/snyk-ls/internal/context"
2324
"github.com/snyk/snyk-ls/internal/types"
2425
)
2526

@@ -36,7 +37,27 @@ func (cmd *workspaceScanCommand) Command() types.CommandData {
3637
func (cmd *workspaceScanCommand) Execute(ctx context.Context) (any, error) {
3738
w := cmd.c.Workspace()
3839
w.Clear()
39-
w.ScanWorkspace(ctx)
40-
HandleUntrustedFolders(ctx, cmd.c, cmd.srv)
40+
args := cmd.command.Arguments
41+
enrichedCtx := cmd.enrichContextWithScanSource(ctx, args)
42+
w.ScanWorkspace(enrichedCtx)
43+
HandleUntrustedFolders(enrichedCtx, cmd.c, cmd.srv)
4144
return nil, nil
4245
}
46+
47+
func (cmd *workspaceScanCommand) enrichContextWithScanSource(ctx context.Context, args []any) context.Context {
48+
if len(args) == 0 {
49+
return ctx
50+
}
51+
52+
sc, ok := args[0].(string)
53+
if !ok {
54+
return ctx
55+
}
56+
57+
if sc != context2.IDE.String() && sc != context2.LLM.String() {
58+
return ctx
59+
}
60+
61+
scanSource := context2.ScanSource(sc)
62+
return context2.NewContextWithScanSource(ctx, scanSource)
63+
}

0 commit comments

Comments
 (0)