@@ -11,19 +11,35 @@ import {
1111import { updateRPackage } from './installRPackage' ;
1212import { trackTerminals , TerminalHandler } from './terminals' ;
1313
14- let terminalHandler : TerminalHandler ;
14+ import { RExtension , HelpPanel } from './rExtensionApi' ;
15+
1516import * as fs from 'fs' ;
1617import * as path from 'path' ;
1718
1819
1920// this method is called when the extension is activated
2021export async function activate ( context : vscode . ExtensionContext ) {
2122
22- terminalHandler = new TerminalHandler ( ) ;
23+ const rExtension = vscode . extensions . getExtension < RExtension > ( 'ikuyadeu.r' ) ;
24+
25+ let rHelpPanel : HelpPanel = undefined ;
26+
27+ if ( rExtension ) {
28+ const api = await rExtension . activate ( ) ;
29+ if ( api ) {
30+ rHelpPanel = api . helpPanel ;
31+ }
32+ }
33+
34+ const supportsHelpViewer = ! ! rHelpPanel ;
35+
36+ const terminalHandler = new TerminalHandler ( ) ;
2337 const port = await terminalHandler . portPromise ;
2438
39+ context . subscriptions . push ( terminalHandler ) ;
40+
2541 // register configuration resolver
26- const resolver = new DebugConfigurationResolver ( port ) ;
42+ const resolver = new DebugConfigurationResolver ( port , 'localhost' , supportsHelpViewer ) ;
2743 context . subscriptions . push ( vscode . debug . registerDebugConfigurationProvider ( 'R-Debugger' , resolver ) ) ;
2844
2945 // register dynamic configuration provider
@@ -35,7 +51,7 @@ export async function activate(context: vscode.ExtensionContext) {
3551 context . subscriptions . push ( vscode . debug . registerDebugConfigurationProvider ( 'R-Debugger' , initialProvider , DebugConfigurationProviderTriggerKind . Initial ) ) ;
3652
3753 // register the debug adapter descriptor provider
38- const factory = new DebugAdapterDescriptorFactory ( ) ;
54+ const factory = new DebugAdapterDescriptorFactory ( rHelpPanel ) ;
3955 context . subscriptions . push ( vscode . debug . registerDebugAdapterDescriptorFactory ( 'R-Debugger' , factory ) ) ;
4056
4157 if ( vscode . workspace . getConfiguration ( 'rdebugger' ) . get < boolean > ( 'trackTerminals' , false ) ) {
@@ -48,18 +64,18 @@ export async function activate(context: vscode.ExtensionContext) {
4864}
4965
5066// this method is called when the extension is deactivated
51- export function deactivate ( ) {
52- // close connections opened by terminalHandler
53- if ( terminalHandler ) {
54- terminalHandler . close ( ) ;
55- }
56- }
67+ export function deactivate ( ) { }
5768
5869class DebugAdapterDescriptorFactory implements vscode . DebugAdapterDescriptorFactory {
70+ helpPanel ?: HelpPanel ;
71+
72+ constructor ( helpPanel ?: HelpPanel ) {
73+ this . helpPanel = helpPanel ;
74+ }
5975 createDebugAdapterDescriptor ( session : vscode . DebugSession ) : ProviderResult < vscode . DebugAdapterDescriptor > {
6076 const config = session . configuration ;
6177 if ( config . request === 'launch' ) {
62- return new vscode . DebugAdapterInlineImplementation ( new DebugAdapter ( ) ) ;
78+ return new vscode . DebugAdapterInlineImplementation ( new DebugAdapter ( this . helpPanel ) ) ;
6379 } else if ( config . request === 'attach' ) {
6480 const port : number = config . port || 18721 ;
6581 const host : string = config . host || 'localhost' ;
@@ -190,10 +206,12 @@ class DebugConfigurationResolver implements vscode.DebugConfigurationProvider {
190206
191207 readonly customPort : number ;
192208 readonly customHost : string ;
209+ readonly supportsHelpViewer : boolean ;
193210
194- constructor ( customPort : number , customHost : string = 'localhost' ) {
211+ constructor ( customPort : number , customHost : string = 'localhost' , supportsHelpViewer : boolean = false ) {
195212 this . customPort = customPort ;
196213 this . customHost = customHost ;
214+ this . supportsHelpViewer = supportsHelpViewer ;
197215 }
198216
199217 resolveDebugConfiguration ( folder : WorkspaceFolder | undefined , config : vscode . DebugConfiguration , token ?: CancellationToken ) : ProviderResult < StrictDebugConfiguration > {
@@ -250,6 +268,9 @@ class DebugConfigurationResolver implements vscode.DebugConfigurationProvider {
250268 config . supportsStdoutReading = true ;
251269 config . supportsWriteToStdinEvent = true ;
252270 config . supportsShowingPromptRequest = true ;
271+ // set to true if not specified. necessary since its default in vscDebugger is FALSE:
272+ config . overwriteHelp = config . overwriteHelp ?? true ;
273+ config . overwriteHelp = config . overwriteHelp && this . supportsHelpViewer ; // check if helpview available
253274 } else if ( config . request === 'attach' ) {
254275 // communication info with TerminalHandler():
255276 config . customPort = config . customPort ?? this . customPort ;
0 commit comments