@@ -33,6 +33,7 @@ import {CliCommandExecutor, CliCommandExecutorImpl} from "./lib/cli-commands";
3333import { getErrorMessage } from "./lib/utils" ;
3434import { FileHandler , FileHandlerImpl } from "./lib/fs-utils" ;
3535import { VscodeWorkspace , VscodeWorkspaceImpl , WindowManager , WindowManagerImpl } from "./lib/vscode-api" ;
36+ import { Workspace } from "./lib/workspace" ;
3637
3738
3839// Object to hold the state of our extension for a specific activation context, to be returned by our activate function
@@ -85,13 +86,14 @@ export async function activate(context: vscode.ExtensionContext): Promise<SFCAEx
8586 context . subscriptions . push ( scanManager ) ;
8687
8788 const windowManager : WindowManager = new WindowManagerImpl ( outputChannel ) ;
89+ const vscodeWorkspace : VscodeWorkspace = new VscodeWorkspaceImpl ( ) ;
8890
8991 const taskWithProgressRunner : TaskWithProgressRunner = new TaskWithProgressRunnerImpl ( ) ;
9092
93+
9194 const cliCommandExecutor : CliCommandExecutor = new CliCommandExecutorImpl ( logger ) ;
92- const vscodeWorkspace : VscodeWorkspace = new VscodeWorkspaceImpl ( ) ;
9395 const fileHandler : FileHandler = new FileHandlerImpl ( ) ;
94- const codeAnalyzer : CodeAnalyzer = new CodeAnalyzerImpl ( cliCommandExecutor , settingsManager , display , vscodeWorkspace , fileHandler ) ;
96+ const codeAnalyzer : CodeAnalyzer = new CodeAnalyzerImpl ( cliCommandExecutor , settingsManager , display , fileHandler ) ;
9597 const dfaRunner : DfaRunner = new DfaRunner ( context , codeAnalyzer , telemetryService , logger ) ; // This thing is really old and clunky. It'll go away when we remove v4 stuff. But if we don't want to wait we could move all this into the v4-scanner.ts file
9698 context . subscriptions . push ( dfaRunner ) ;
9799
@@ -126,7 +128,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<SFCAEx
126128 vscode . window . showWarningMessage ( messages . noActiveEditor ) ;
127129 return ;
128130 }
129- return codeAnalyzerRunAction . run ( Constants . COMMAND_RUN_ON_ACTIVE_FILE , [ document . fileName ] ) ;
131+ const workspace : Workspace = await Workspace . fromTargetPaths ( [ document . fileName ] , vscodeWorkspace , fileHandler ) ;
132+ return codeAnalyzerRunAction . run ( Constants . COMMAND_RUN_ON_ACTIVE_FILE , workspace ) ;
130133 } ) ;
131134
132135 // "Analyze On Open" and "Analyze on Save" functionality:
@@ -139,7 +142,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<SFCAEx
139142 const isValidFileThatHasNotBeenScannedYet = isValidFile && ! scanManager . haveAlreadyScannedFile ( editor . document . fileName ) ;
140143 if ( isValidFileThatHasNotBeenScannedYet ) {
141144 scanManager . addFileToAlreadyScannedFiles ( editor . document . fileName ) ;
142- await codeAnalyzerRunAction . run ( Constants . COMMAND_RUN_ON_ACTIVE_FILE , [ editor . document . fileName ] ) ;
145+ const workspace : Workspace = await Workspace . fromTargetPaths ( [ editor . document . fileName ] , vscodeWorkspace , fileHandler ) ;
146+ await codeAnalyzerRunAction . run ( Constants . COMMAND_RUN_ON_ACTIVE_FILE , workspace ) ;
143147 }
144148 } ) ;
145149 onDidSaveTextDocument ( async ( document : vscode . TextDocument ) => {
@@ -154,22 +158,20 @@ export async function activate(context: vscode.ExtensionContext): Promise<SFCAEx
154158
155159 if ( settingsManager . getAnalyzeOnSave ( ) ) {
156160 scanManager . addFileToAlreadyScannedFiles ( document . fileName ) ;
157- await codeAnalyzerRunAction . run ( Constants . COMMAND_RUN_ON_ACTIVE_FILE , [ document . fileName ] ) ;
161+ const workspace : Workspace = await Workspace . fromTargetPaths ( [ document . fileName ] , vscodeWorkspace , fileHandler ) ;
162+ await codeAnalyzerRunAction . run ( Constants . COMMAND_RUN_ON_ACTIVE_FILE , workspace ) ;
158163 }
159164 } ) ;
160165
161166 // COMMAND_RUN_ON_SELECTED: Invokable by 'explorer/context' menu always. Uses v4 instead of v5 when 'sfca.codeAnalyzerV4Enabled'.
162167 registerCommand ( Constants . COMMAND_RUN_ON_SELECTED , async ( singleSelection : vscode . Uri , multiSelection ?: vscode . Uri [ ] ) => {
163168 const selection : vscode . Uri [ ] = ( multiSelection && multiSelection . length > 0 ) ? multiSelection : [ singleSelection ] ;
164- // TODO: We may wish to consider moving away from this target resolution, and just passing in files and folders
165- // as given to us. It's possible the current style could lead to overflowing the CLI when a folder has
166- // many files.
167- const selectedFiles : string [ ] = await targeting . getFilesFromSelection ( selection ) ;
168- if ( selectedFiles . length == 0 ) { // I have not found a way to hit this, but we should check just in case
169+ const workspace : Workspace = await Workspace . fromTargetPaths ( selection . map ( uri => uri . fsPath ) , vscodeWorkspace , fileHandler ) ;
170+ if ( workspace . getRawTargetPaths ( ) . length == 0 ) { // I have not found a way to hit this, but we should check just in case
169171 vscode . window . showWarningMessage ( messages . targeting . error . noFileSelected ) ;
170172 return ;
171173 }
172- await codeAnalyzerRunAction . run ( Constants . COMMAND_RUN_ON_SELECTED , selectedFiles ) ;
174+ await codeAnalyzerRunAction . run ( Constants . COMMAND_RUN_ON_SELECTED , workspace ) ;
173175 } ) ;
174176
175177
0 commit comments