44import { inject , injectable } from 'inversify' ;
55import { CodeLens , Position , Range , Selection , TextDocument , TextEditor , TextEditorRevealType } from 'vscode' ;
66
7- import { IApplicationShell , IDocumentManager } from '../../common/application/types' ;
7+ import { IDocumentManager } from '../../common/application/types' ;
88import { IFileSystem } from '../../common/platform/types' ;
9- import { IConfigurationService , IDataScienceSettings , ILogger } from '../../common/types' ;
10- import { noop } from '../../common/utils/misc ' ;
9+ import { IConfigurationService , IDataScienceSettings } from '../../common/types' ;
10+ // import * as localize from '../../common/utils/localize ';
1111import { StopWatch } from '../../common/utils/stopWatch' ;
12+ import { IServiceContainer } from '../../ioc/types' ;
1213import { captureTelemetry } from '../../telemetry' ;
1314import { ICodeExecutionHelper } from '../../terminals/types' ;
1415import { Commands , Telemetry } from '../constants' ;
15- import { JupyterInstallError } from '../jupyter/jupyterInstallError' ;
16- import { JupyterSelfCertsError } from '../jupyter/jupyterSelfCertsError' ;
17- import { ICodeLensFactory , ICodeWatcher , IInteractiveWindowProvider } from '../types' ;
16+ // import { JupyterInstallError } from '../jupyter/jupyterInstallError';
17+ // import { JupyterSelfCertsError } from '../jupyter/jupyterSelfCertsError';
18+ import { ICodeLensFactory , ICodeWatcher , IDataScienceErrorHandler , IInteractiveWindowProvider } from '../types' ;
1819
1920@injectable ( )
2021export class CodeWatcher implements ICodeWatcher {
@@ -24,15 +25,15 @@ export class CodeWatcher implements ICodeWatcher {
2425 private codeLenses : CodeLens [ ] = [ ] ;
2526 private cachedSettings : IDataScienceSettings | undefined ;
2627
27- constructor ( @inject ( IApplicationShell ) private applicationShell : IApplicationShell ,
28- @inject ( ILogger ) private logger : ILogger ,
29- @inject ( IInteractiveWindowProvider ) private interactiveWindowProvider : IInteractiveWindowProvider ,
30- @inject ( IFileSystem ) private fileSystem : IFileSystem ,
31- @inject ( IConfigurationService ) private configService : IConfigurationService ,
32- @inject ( IDocumentManager ) private documentManager : IDocumentManager ,
33- @inject ( ICodeExecutionHelper ) private executionHelper : ICodeExecutionHelper ,
34- @inject ( ICodeLensFactory ) private codeLensFactory : ICodeLensFactory
35- ) {
28+ constructor ( @inject ( IInteractiveWindowProvider ) private interactiveWindowProvider : IInteractiveWindowProvider ,
29+ @inject ( IFileSystem ) private fileSystem : IFileSystem ,
30+ @inject ( IConfigurationService ) private configService : IConfigurationService ,
31+ @inject ( IDocumentManager ) private documentManager : IDocumentManager ,
32+ @inject ( ICodeExecutionHelper ) private executionHelper : ICodeExecutionHelper ,
33+ @inject ( IDataScienceErrorHandler ) protected dataScienceErrorHandler : IDataScienceErrorHandler ,
34+ @inject ( ICodeLensFactory ) private codeLensFactory : ICodeLensFactory ,
35+ @inject ( IServiceContainer ) protected serviceContainer : IServiceContainer
36+ ) {
3637 }
3738
3839 public setDocument ( document : TextDocument ) {
@@ -57,7 +58,7 @@ export class CodeWatcher implements ICodeWatcher {
5758 return this . version ;
5859 }
5960
60- public getCachedSettings ( ) : IDataScienceSettings | undefined {
61+ public getCachedSettings ( ) : IDataScienceSettings | undefined {
6162 return this . cachedSettings ;
6263 }
6364
@@ -143,13 +144,13 @@ export class CodeWatcher implements ICodeWatcher {
143144 }
144145
145146 @captureTelemetry ( Telemetry . RunSelectionOrLine )
146- public async runSelectionOrLine ( activeEditor : TextEditor | undefined ) {
147+ public async runSelectionOrLine ( activeEditor : TextEditor | undefined ) {
147148 if ( this . document && activeEditor &&
148149 this . fileSystem . arePathsSame ( activeEditor . document . fileName , this . document . fileName ) ) {
149150 // Get just the text of the selection or the current line if none
150151 const codeToExecute = await this . executionHelper . getSelectedTextToExecute ( activeEditor ) ;
151152 if ( ! codeToExecute ) {
152- return ;
153+ return ;
153154 }
154155 const normalizedCode = await this . executionHelper . normalizeLines ( codeToExecute ! ) ;
155156 if ( ! normalizedCode || normalizedCode . trim ( ) . length === 0 ) {
@@ -184,7 +185,7 @@ export class CodeWatcher implements ICodeWatcher {
184185 }
185186
186187 @captureTelemetry ( Telemetry . RunCell )
187- public runCell ( range : Range ) : Promise < void > {
188+ public runCell ( range : Range ) : Promise < void > {
188189 if ( ! this . documentManager . activeTextEditor || ! this . documentManager . activeTextEditor . document ) {
189190 return Promise . resolve ( ) ;
190191 }
@@ -195,7 +196,7 @@ export class CodeWatcher implements ICodeWatcher {
195196 }
196197
197198 @captureTelemetry ( Telemetry . DebugCurrentCell )
198- public debugCell ( range : Range ) : Promise < void > {
199+ public debugCell ( range : Range ) : Promise < void > {
199200 if ( ! this . documentManager . activeTextEditor || ! this . documentManager . activeTextEditor . document ) {
200201 return Promise . resolve ( ) ;
201202 }
@@ -205,7 +206,7 @@ export class CodeWatcher implements ICodeWatcher {
205206 }
206207
207208 @captureTelemetry ( Telemetry . RunCurrentCell )
208- public runCurrentCell ( ) : Promise < void > {
209+ public runCurrentCell ( ) : Promise < void > {
209210 if ( ! this . documentManager . activeTextEditor || ! this . documentManager . activeTextEditor . document ) {
210211 return Promise . resolve ( ) ;
211212 }
@@ -224,7 +225,7 @@ export class CodeWatcher implements ICodeWatcher {
224225 return this . runMatchingCell ( this . documentManager . activeTextEditor . selection , true ) ;
225226 }
226227
227- public async addEmptyCellToBottom ( ) : Promise < void > {
228+ public async addEmptyCellToBottom ( ) : Promise < void > {
228229 const editor = this . documentManager . activeTextEditor ;
229230 if ( editor ) {
230231 editor . edit ( ( editBuilder ) => {
@@ -236,7 +237,7 @@ export class CodeWatcher implements ICodeWatcher {
236237 }
237238 }
238239
239- private async addCode ( code : string , file : string , line : number , editor ?: TextEditor , debug ?: boolean ) : Promise < void > {
240+ private async addCode ( code : string , file : string , line : number , editor ?: TextEditor , debug ?: boolean ) : Promise < void > {
240241 try {
241242 const stopWatch = new StopWatch ( ) ;
242243 const activeInteractiveWindow = await this . interactiveWindowProvider . getOrCreateActive ( ) ;
@@ -246,7 +247,7 @@ export class CodeWatcher implements ICodeWatcher {
246247 await activeInteractiveWindow . addCode ( code , file , line , editor , stopWatch ) ;
247248 }
248249 } catch ( err ) {
249- this . handleError ( err ) ;
250+ this . dataScienceErrorHandler . handleError ( err ) ;
250251 }
251252 }
252253
@@ -279,11 +280,11 @@ export class CodeWatcher implements ICodeWatcher {
279280 }
280281 }
281282
282- private getCurrentCellLens ( pos : Position ) : CodeLens | undefined {
283+ private getCurrentCellLens ( pos : Position ) : CodeLens | undefined {
283284 return this . codeLenses . find ( l => l . range . contains ( pos ) && l . command !== undefined && l . command . command === Commands . RunCell ) ;
284285 }
285286
286- private getNextCellLens ( pos : Position ) : CodeLens | undefined {
287+ private getNextCellLens ( pos : Position ) : CodeLens | undefined {
287288 const currentIndex = this . codeLenses . findIndex ( l => l . range . contains ( pos ) && l . command !== undefined && l . command . command === Commands . RunCell ) ;
288289 if ( currentIndex >= 0 ) {
289290 return this . codeLenses . find ( ( l : CodeLens , i : number ) => l . command !== undefined && l . command . command === Commands . RunCell && i > currentIndex ) ;
@@ -298,29 +299,6 @@ export class CodeWatcher implements ICodeWatcher {
298299 }
299300 }
300301
301- // tslint:disable-next-line:no-any
302- private handleError = ( err : any ) => {
303- if ( err instanceof JupyterInstallError ) {
304- const jupyterError = err as JupyterInstallError ;
305-
306- // This is a special error that shows a link to open for more help
307- this . applicationShell . showErrorMessage ( jupyterError . message , jupyterError . actionTitle ) . then ( v => {
308- // User clicked on the link, open it.
309- if ( v === jupyterError . actionTitle ) {
310- this . applicationShell . openUrl ( jupyterError . action ) ;
311- }
312- } ) ;
313- } else if ( err instanceof JupyterSelfCertsError ) {
314- // Don't show the message for self cert errors
315- noop ( ) ;
316- } else if ( err . message ) {
317- this . applicationShell . showErrorMessage ( err . message ) ;
318- } else {
319- this . applicationShell . showErrorMessage ( err . toString ( ) ) ;
320- }
321- this . logger . logError ( err ) ;
322- }
323-
324302 // User has picked run and advance on the last cell of a document
325303 // Create a new cell at the bottom and put their selection there, ready to type
326304 private createNewCell ( currentRange : Range ) : Range {
0 commit comments