Skip to content

Commit 39706d9

Browse files
Cleanup
1 parent ba7c2d6 commit 39706d9

File tree

11 files changed

+123
-251
lines changed

11 files changed

+123
-251
lines changed

package-lock.json

Lines changed: 34 additions & 208 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
"name": "r-debugger",
33
"displayName": "R Debugger",
44
"description": "R Debugger for VS Code",
5-
"version": "0.3.1",
5+
"version": "0.4.0",
66
"publisher": "RDebugger",
77
"license": "MIT",
88
"author": {
99
"name": "Manuel Hentschel"
1010
},
1111
"rPackageInfo": {
1212
"name": "vscDebugger",
13-
"required": "0.3.0",
14-
"recommended": "0.3.1",
15-
"warnIfNewer": "0.4.0"
13+
"required": "0.4.0",
14+
"recommended": "0.4.0",
15+
"warnIfNewer": "0.5.0"
1616
},
1717
"repository": {
1818
"type": "git",
@@ -113,7 +113,6 @@
113113
"default": false,
114114
"description": "Whether to show the overwritten output in the normal stdout/stderr as well."
115115
},
116-
117116
"overwritePrint": {
118117
"type": "boolean",
119118
"default": true,
@@ -200,7 +199,6 @@
200199
"default": "main",
201200
"description": "The name of the main function, if a single function is being debugged. Must be callable without arguments."
202201
},
203-
204202
"overwritePrint": {
205203
"type": "boolean",
206204
"default": true,
@@ -274,6 +272,12 @@
274272
"file": "${file}",
275273
"mainFunction": "main",
276274
"allowGlobalDebugging": false
275+
},
276+
{
277+
"type": "R-Debugger",
278+
"request": "attach",
279+
"name": "Attach to R process",
280+
"splitOverwrittenOutput": true
277281
}
278282
]
279283
}
@@ -321,6 +325,11 @@
321325
],
322326
"default": "recommended",
323327
"description": "Whether to check the version of the R package before launching the debugger."
328+
},
329+
"rdebugger.trackTerminals": {
330+
"type": "boolean",
331+
"default": true,
332+
"description": "Whether to track terminals opened while using the extension. Recommended for debugging in attached mode on windows."
324333
}
325334
}
326335
}

readme.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ To install the latest development version of the required R-package from GitHub,
4343
or install from the artifacts found
4444
[here](https://github.com/ManuelHentschel/vscDebugger/actions).
4545

46+
If your R path is neither in the Windows registry nor the `PATH` environment variable, make sure to provide a valid path to the R executable in `rdebugger.rterm.*`.
47+
4648
**Note on the package version:**
4749
Since the debugger is still under initial development, both this extension and the accompanying R package are major version 0.y.z.
4850
The minor version (x.Y.z) is incremented when backward incompatible changes to the interface/communication between the VS Code extension and the R package are introduced.
@@ -51,16 +53,27 @@ The patch version (x.y.Z) is incremented independently for all other changes tha
5153

5254

5355
## Using the Debugger
54-
* Install this extension in VS Code.
55-
* Install the package [**vscDebugger**](https://github.com/ManuelHentschel/vscDebugger) in R.
56-
* If your R path is neither in the Windows registry nor the `PATH` environment variable, make sure to provide a valid path to the R executable in `rdebugger.rterm.*`.
56+
### Launch Mode
5757
* Press F5 and select `R Debugger` as debugger. With the default launch configuration, the debugger will start a new R session.
5858
* To run a file, focus the file in the editor and press F5 (or the continue button in the debug controls)
5959
* Output will be printed to the debug console,
6060
expressions entered into the debug console are evaluated in the currently active frame
6161
* During debugging in the global workspace it is often necessary to click the dummy frame
6262
in the callstack labelled 'Global Workspace' to see the variables in `.GlobalEnv`.
6363

64+
### Attach Mode
65+
* Start R in a terminal
66+
* Load `library(vscDebugger)`
67+
* Call `.vsc.listen()`
68+
* Start the debugger with launch configuration including `"request":"attach"`, e.g.:
69+
``` json
70+
{
71+
"type": "R-Debugger",
72+
"request": "attach",
73+
"name": "Attach to R process"
74+
}
75+
```
76+
6477
## Configuration
6578
For a detailed explanation of possible launch config entries and other settings, see
6679
[configuration.md](./configuration.md) on github.

src/debugProtocolModifications.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { DebugProtocol } from 'vscode-debugprotocol';
44
import * as VsCode from 'vscode';
55
// import { DebugProtocol } from './debugProtocol';
66

7+
8+
//
9+
// Regular extension of the DAP:
10+
//
11+
712
export type DebugMode = "function"|"file"|"workspace";
813

914
export interface RStartupArguments {
@@ -14,11 +19,6 @@ export interface RStartupArguments {
1419
cwd: string;
1520
}
1621

17-
export interface Source extends DebugProtocol.Source {
18-
content?: string;
19-
}
20-
21-
2222
export interface DebugConfiguration extends VsCode.DebugConfiguration {
2323
type: "R-Debugger";
2424
request: "launch"|"attach";
@@ -91,6 +91,16 @@ export interface RStrings {
9191
packageName?: string;
9292
}
9393

94+
95+
96+
97+
//
98+
// Non standard extension/modification of the DAP:
99+
//
100+
101+
export interface InitializeRequest extends DebugProtocol.InitializeRequest {
102+
arguments: InitializeRequestArguments;
103+
}
94104
export interface InitializeRequestArguments extends DebugProtocol.InitializeRequestArguments {
95105
rStrings?: RStrings;
96106
threadId?: number;
@@ -103,32 +113,22 @@ export interface InitializeRequestArguments extends DebugProtocol.InitializeRequ
103113
extensionVersion?: string;
104114
}
105115

106-
export interface InitializeRequest extends DebugProtocol.InitializeRequest {
107-
arguments: InitializeRequestArguments;
116+
export interface InitializeResponse extends DebugProtocol.InitializeResponse {
117+
packageInfo?: PackageInfo;
108118
}
109-
110119
export interface PackageInfo {
111120
Package: string;
112121
Version: string;
113122
};
114123

115-
export interface InitializeResponse extends DebugProtocol.InitializeResponse {
116-
packageInfo?: PackageInfo;
124+
export interface ContinueRequest extends DebugProtocol.ContinueRequest {
125+
arguments: ContinueArguments;
117126
}
118-
119127
export interface ContinueArguments extends DebugProtocol.ContinueArguments {
120128
callDebugSource?: boolean;
121129
source?: DebugProtocol.Source;
122130
}
123131

124-
export interface ContinueRequest extends DebugProtocol.ContinueRequest {
125-
arguments: ContinueArguments;
126-
}
127-
128-
export interface SourceArguments extends DebugProtocol.SourceArguments {
129-
source?: Source;
130-
}
131-
132132

133133
export interface ResponseWithBody extends DebugProtocol.Response {
134134
body?: { [key: string]: any; };

src/debugRuntime.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const { Subject } = require('await-notify');
1616

1717
import * as log from 'loglevel';
1818
const logger = log.getLogger("DebugRuntime");
19+
logger.setLevel(config().get<log.LogLevelDesc>('logLevelRuntime', 'info'));
1920

2021

2122
export type LineHandler = (line: string, from: DataSource, isFullLine: boolean) => string;
@@ -74,7 +75,6 @@ export class DebugRuntime extends EventEmitter {
7475
// constructor
7576
constructor() {
7677
super();
77-
logger.setLevel(config().get<log.LogLevelDesc>('logLevelRuntime', 'info'));
7878
}
7979

8080
public async initializeRequest(response: DebugProtocol.InitializeResponse, args: MDebugProtocol.InitializeRequestArguments, request: MDebugProtocol.InitializeRequest) {
@@ -383,9 +383,8 @@ export class DebugRuntime extends EventEmitter {
383383
console.log('invalid wop');
384384
}
385385
} else {
386-
const cmdListen = `.vsc.listenOnPort(timeout = -1)`;
386+
const cmdListen = this.rStrings.packageName + `::.vsc.listenForJSON(timeout = -1)`;
387387
this.rSession.writeToStdin(cmdListen);
388-
// this.rSession.callFunction('.vsc.listenOnPort', {timeout: -1});
389388
this.sendShowingPromptRequest(which, text);
390389
}
391390
}

src/debugSession.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
import { basename } from 'path';
55
import { DebugRuntime } from './debugRuntime';
6-
import { Response } from 'vscode-debugadapter/lib/messages';
76
import { ProtocolServer } from 'vscode-debugadapter/lib/protocol';
87
import { DebugProtocol } from 'vscode-debugprotocol';
98
import { InitializeRequest, ResponseWithBody, InitializeRequestArguments, ContinueRequest } from './debugProtocolModifications';
109
import { config, getVSCodePackageVersion } from './utils';
1110

1211
import * as log from 'loglevel';
1312
const logger = log.getLogger("DebugSession");
13+
logger.setLevel(config().get<log.LogLevelDesc>('logLevelSession', 'INFO'));
1414

1515
export class DebugSession extends ProtocolServer {
1616

@@ -35,8 +35,6 @@ export class DebugSession extends ProtocolServer {
3535
constructor() {
3636
super();
3737

38-
logger.setLevel(config().get<log.LogLevelDesc>('logLevelSession', 'INFO'));
39-
4038
// construct R runtime
4139
this._runtime = new DebugRuntime();
4240

@@ -79,7 +77,13 @@ export class DebugSession extends ProtocolServer {
7977
}
8078

8179
protected dispatchRequest(request: DebugProtocol.Request) {
82-
const response: ResponseWithBody = new Response(request);
80+
const response: DebugProtocol.Response = {
81+
command: request.command,
82+
request_seq: request.seq,
83+
seq: 0,
84+
success: true,
85+
type: 'response'
86+
};
8387
var dispatchToR: boolean = false; // the cases handled here are not sent to R
8488
var sendResponse: boolean = true; // for cases handled here, the response must also be sent from here
8589
try {

src/terminals.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { WriteToStdinEvent, WriteToStdinBody } from './debugProtocolModification
66
import * as vscode from 'vscode';
77
import { config, getPortNumber } from './utils';
88

9+
import * as log from 'loglevel';
10+
const logger = log.getLogger("DebugRuntime");
11+
logger.setLevel(config().get<log.LogLevelDesc>('logLevelTerminals', 'INFO'));
12+
913
let doTrackTerminals: boolean = false;
1014

1115
export function trackTerminals(){
@@ -75,14 +79,15 @@ export class TerminalHandler {
7579
public constructor(port: number = 0, host: string = 'localhost'){
7680
const timeout = config().get<number>('timeouts.startup', 1000);
7781
this.server = net.createServer((socket) => {
82+
logger.debug('Cusotm server: connection!');
7883
socket.on('data', (data) => {
7984
this.handleData(data, socket);
8085
});
8186
});
8287
const portPromise = new Promise<number>((resolve, reject) => {
8388
this.server.listen(port, host, () => {
8489
const port = getPortNumber(this.server);
85-
console.log(`Server listening on ${host}:${port}`);
90+
logger.info(`Custom server listening on ${host}:${port}`);
8691
resolve(port);
8792
});
8893
setTimeout(() => {
@@ -94,7 +99,7 @@ export class TerminalHandler {
9499
}
95100

96101
public close(){
97-
console.log('closing terminal handler connections');
102+
console.log('Closing custom server connections');
98103
this.lineCache.forEach((_, socket) => {
99104
socket.destroy();
100105
});
@@ -146,6 +151,7 @@ async function writeToStdin(args: WriteToStdinArgs){
146151
terminal.sendText(args.text, args.addNewLine);
147152
return true;
148153
} else{
154+
logger.debug('No terminal found.')
149155
return false;
150156
}
151157
}
@@ -161,6 +167,7 @@ async function findTerminal(args: WriteToStdinArgs): Promise<vscode.Terminal|und
161167
for(term of vscode.window.terminals){
162168
const pid: number = await term.processId;
163169
if(pid === args.pid || pid === args.ppid){
170+
logger.debug('identified terminal by pid');
164171
return term;
165172
}
166173
}
@@ -169,12 +176,14 @@ async function findTerminal(args: WriteToStdinArgs): Promise<vscode.Terminal|und
169176
if(args.terminalId && doTrackTerminals){
170177
for(term of vscode.window.terminals){
171178
if('vscodeRDebuggerTerminalId' in term && args.terminalId === term.vscodeRDebuggerTerminalId){
179+
logger.debug('identified terminal by terminalId');
172180
return term;
173181
}
174182
}
175183
}
176184
// resort to active terminal
177185
if(args.useActiveTerminal){
186+
logger.debug('resort to active terminal');
178187
return vscode.window.activeTerminal;
179188
}
180189
// give up...

test/R/.Rprofile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
options(vsc.supportSetVariable = FALSE)

test/R/.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"type": "R-Debugger",
99
"request": "attach",
1010
"name": "Attach to R process",
11-
"supportsWriteToStdinEvent": false,
11+
"supportsWriteToStdinEvent": true,
1212
"splitOverwrittenOutput": false,
1313
"useCustomSocket": true
1414
},

test/R/.vscode/settings.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"rdebugger.checkVersion": "none",
33
// "rdebugger.printStdout": "all",
44
// "rdebugger.printSinkSocket": "all",
5-
"rdebugger.logLevelRSession": "debug",
5+
// "rdebugger.logLevelRSession": "debug",
66
// "rdebugger.logLevelSession": "debug",
7-
"rdebugger.logLevelRuntime": "debug",
7+
// "rdebugger.logLevelRuntime": "debug",
88
"terminal.integrated.env.windows": {
9-
"VSCODE_R_DEBUGGER_TERMINAL_ID": "53"
9+
"VSCODE_R_DEBUGGER_TERMINAL_ID": "81"
1010
},
11-
"rdebugger.trackTerminals": false
11+
"rdebugger.trackTerminals": true
1212
// "rdebugger.rterm.windows": "\"C:\\Program Files\\R\\R-4.0.2\\bin\\x64\\R.exe\""
1313
}

0 commit comments

Comments
 (0)