Skip to content

Commit

Permalink
Add .editorconfig file, standardize formatting
Browse files Browse the repository at this point in the history
I see quite a of bit of inconsistency in the formatting.  Let's add a
.editorconfig file, so the code we write uses the right whitespacing
regardless of the editor we use.  I just copied the one I wrote earlier
for Theia to get started, but it doesn't have to be identical.

I used Theia to auto-format all ts and json files and then tslint --fix
to fixup any warnings that it would have inserted.

For example, I the Typescript formatter handles quite badly (IMO) wrapping long
parameter lists, and produces code that result in a warning according to
our current tslint config.  The Typescript formatter will do this:

```
export class Bob {
    constructor(a: number, b: number, c: number, d: number,
        e: number, f: number) {
        console.log('Hello');
    }
}
```

where the second line of parameters is indented with 4 spaces.  I think
is not very readable, because it's easily confused with the first line
of code.  I prefer our current tslint setting, which requires it to be
aligned like this:

```
export class Bob {
    constructor(a: number, b: number, c: number, d: number,
i               e: number, f: number) {
        console.log('Hello');
    }
}
```

This means that formatting entire documents will always change the code
to look like the first snippet above.  It's a minor annoyance, and
hopefully there will be a setting for that one day in the Typescript
formatter.  There is an issue about that here:

microsoft/TypeScript#11629
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
  • Loading branch information
Simon Marchi committed Nov 27, 2018
1 parent ec78875 commit 80b5495
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 174 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
insert_final_newline = true
end_of_line = lf
indent_style = space

[*.{js,ts,md}]
indent_size = 4

[*.{json,yml}]
indent_size = 2
108 changes: 58 additions & 50 deletions src/GDBDebugSession.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ import * as path from 'path';
*/
export function getExecPath(): string {
return path.join(__dirname, 'debugAdapter.js');
}
}
2 changes: 1 addition & 1 deletion src/integration-tests/launch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('launch', function() {
source: { path: 'empty.c' },
breakpoints: [{
line: 3,
}]
}],
});
await dc.configurationDoneRequest({});
await dc.assertStoppedLocation('breakpoint', {});
Expand Down
54 changes: 27 additions & 27 deletions src/mi/breakpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*
* SPDX-License-Identifier: EPL-2.0
*********************************************************************/
import {GDBBackend} from '../GDBBackend';
import { GDBBackend } from '../GDBBackend';
import { MIBreakpointInfo, MIResponse } from './base';

export interface MIBreakInsertResponse extends MIResponse {
bkpt: MIBreakpointInfo;
bkpt: MIBreakpointInfo;
}

export interface MIBreakDeleteRequest {
Expand All @@ -22,40 +22,40 @@ export interface MIBreakDeleteResponse extends MIResponse {
}

export interface MIBreakListResponse extends MIResponse {
BreakpointTable: {
nr_rows: string,
nr_cols: string,
hrd: Array<{
width: string,
alignment: string,
col_name: string,
colhdr: string,
}>;
body: MIBreakpointInfo[]
};
BreakpointTable: {
nr_rows: string,
nr_cols: string,
hrd: Array<{
width: string,
alignment: string,
col_name: string,
colhdr: string,
}>;
body: MIBreakpointInfo[]
};
}

export function sendBreakInsert(gdb: GDBBackend, request: {
temporary?: boolean;
hardware?: boolean;
pending?: boolean;
disabled?: boolean;
tracepoint?: boolean;
condition?: string;
ignoreCount?: number;
threadId?: string;
location: string;
temporary?: boolean;
hardware?: boolean;
pending?: boolean;
disabled?: boolean;
tracepoint?: boolean;
condition?: string;
ignoreCount?: number;
threadId?: string;
location: string;
}): Promise<MIBreakInsertResponse> {
// Todo: lots of options
return gdb.sendCommand(`-break-insert ${request.location}`);
// Todo: lots of options
return gdb.sendCommand(`-break-insert ${request.location}`);
}

export function sendBreakDelete(gdb: GDBBackend, request: {
breakpoints: string[];
breakpoints: string[];
}): Promise<MIBreakDeleteResponse> {
return gdb.sendCommand(`-break-delete ${request.breakpoints.join(' ')}`);
return gdb.sendCommand(`-break-delete ${request.breakpoints.join(' ')}`);
}

export function sendBreakList(gdb: GDBBackend): Promise<MIBreakListResponse> {
return gdb.sendCommand('-break-list');
return gdb.sendCommand('-break-list');
}
8 changes: 4 additions & 4 deletions src/mi/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
*
* SPDX-License-Identifier: EPL-2.0
*********************************************************************/
import {GDBBackend} from '../GDBBackend';
import { GDBBackend } from '../GDBBackend';
import { MIResponse } from './base';

export function sendExecArguments(gdb: GDBBackend, params: {
arguments: string;
arguments: string;
}): Promise<MIResponse> {
return gdb.sendCommand(`-exec-arguments ${params.arguments}`);
return gdb.sendCommand(`-exec-arguments ${params.arguments}`);
}

export function sendExecRun(gdb: GDBBackend) {
export function sendExecRun(gdb: GDBBackend) {
return gdb.sendCommand('-exec-run');
}

Expand Down
8 changes: 4 additions & 4 deletions src/mi/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { MIResponse } from './base';

export function sendTargetAttachRequest(gdb: GDBBackend, params: {
pid: string;
}): Promise<MIResponse> {
return gdb.sendCommand(`-target-attach ${params.pid}`);
}): Promise<MIResponse> {
return gdb.sendCommand(`-target-attach ${params.pid}`);
}

export function sendTargetSelectRequest(gdb: GDBBackend, params: {
type: string;
parameters: string[];
}): Promise<MIResponse> {
return gdb.sendCommand(`-target-select ${params.type} ${params.parameters.join(' ')}`);
}): Promise<MIResponse> {
return gdb.sendCommand(`-target-select ${params.type} ${params.parameters.join(' ')}`);
}
18 changes: 9 additions & 9 deletions src/mi/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export interface MIThreadInfoResponse extends MIResponse {
currentThreadId: string;
}

export function sendThreadInfoRequest(gdb: GDBBackend, params: {
threadId?: string;
}): Promise<MIThreadInfoResponse> {
let command = '-thread-info';
if (params.threadId) {
command += ` ${params.threadId}`;
}
return gdb.sendCommand(command);
export function sendThreadInfoRequest(gdb: GDBBackend, params: {
threadId?: string;
}): Promise<MIThreadInfoResponse> {
let command = '-thread-info';
if (params.threadId) {
command += ` ${params.threadId}`;
}
return gdb.sendCommand(command);
}

export interface MIThreadSelectResponse extends MIResponse {
Expand All @@ -43,5 +43,5 @@ export interface MIThreadSelectResponse extends MIResponse {
export function sendThreadSelectRequest(gdb: GDBBackend, params: {
threadId: number;
}): Promise<MIThreadSelectResponse> {
return gdb.sendCommand(`-thread-select ${params.threadId}`);
return gdb.sendCommand(`-thread-select ${params.threadId}`);
}
88 changes: 44 additions & 44 deletions src/mi/var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ import { GDBBackend } from '../GDBBackend';
import { MIResponse } from './base';

export interface MIVarCreateResponse extends MIResponse {
name: string;
numchild: string;
value: string;
type: string;
'thread-id'?: string;
has_more?: string;
dynamic?: string;
displayhint?: string;
name: string;
numchild: string;
value: string;
type: string;
'thread-id'?: string;
has_more?: string;
dynamic?: string;
displayhint?: string;
}

export interface MIVarListChildrenResponse {
numchild: string;
children: Array<{
name: string;
exp: string;
numchild: string;
type: string;
value?: string;
'thread-id'?: string;
frozen?: string;
displayhint?: string;
dynamic?: string;
}>;
numchild: string;
children: Array<{
name: string;
exp: string;
numchild: string;
type: string;
value?: string;
'thread-id'?: string;
frozen?: string;
displayhint?: string;
dynamic?: string;
}>;
}

export interface MIVarUpdateResponse {
Expand All @@ -51,35 +51,35 @@ export interface MIVarEvalResponse {
}

export function sendVarCreate(gdb: GDBBackend, params: {
name?: string;
frameAddr?: string;
frame?: 'current' | 'floating';
expression: string;
name?: string;
frameAddr?: string;
frame?: 'current' | 'floating';
expression: string;
}): Promise<MIVarCreateResponse> {
let command = '-var-create';
command += ` ${params.name ? params.name : '-'}`;
if (params.frameAddr) {
command += ` ${params.frameAddr}`;
} else if (params.frame) {
switch (params.frame) {
case 'current':
command += ' *';
break;
case 'floating':
command += ' @';
break;
}
}
command += ` ${params.expression}`;
let command = '-var-create';
command += ` ${params.name ? params.name : '-'}`;
if (params.frameAddr) {
command += ` ${params.frameAddr}`;
} else if (params.frame) {
switch (params.frame) {
case 'current':
command += ' *';
break;
case 'floating':
command += ' @';
break;
}
}
command += ` ${params.expression}`;

return gdb.sendCommand(command);
return gdb.sendCommand(command);
}

export function sendVarListChildren(gdb: GDBBackend, params: {
printValues?: 'no-values' | 'all-values' | 'simple-values';
name: string;
from?: number;
to?: number;
printValues?: 'no-values' | 'all-values' | 'simple-values';
name: string;
from?: number;
to?: number;
}): Promise<MIVarListChildrenResponse> {
let command = '-var-list-children';
if (params.printValues) {
Expand Down
38 changes: 20 additions & 18 deletions src/varManager.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { GDBBackend } from './GDBBackend';
import {MIVarCreateResponse} from './mi/var';
import { MIVarCreateResponse } from './mi/var';
import { sendVarCreate, sendVarDelete, sendVarUpdate } from './mi/var';

export interface VarObjType {
varname: string;
expression: string;
numchild: string;
children: VarObjType[];
value: string;
type: string;
isVar: boolean;
isChild: boolean;
varname: string;
expression: string;
numchild: string;
children: VarObjType[];
value: string;
type: string;
isVar: boolean;
isChild: boolean;
}

const variableMap: Map<string, VarObjType[]> = new Map<string, VarObjType[]>();
Expand Down Expand Up @@ -42,14 +42,16 @@ export function addVar(frameId: number, threadId: number, depth: number, express
vars = [];
variableMap.set(getKey(frameId, threadId, depth), vars);
}
const varobj: VarObjType = {varname: varCreateResponse.name, expression, numchild: varCreateResponse.numchild,
children: [], value: varCreateResponse.value, type: varCreateResponse.type, isVar, isChild};
const varobj: VarObjType = {
varname: varCreateResponse.name, expression, numchild: varCreateResponse.numchild,
children: [], value: varCreateResponse.value, type: varCreateResponse.type, isVar, isChild,
};
vars.push(varobj);
return varobj;
}

export async function removeVar(gdb: GDBBackend, frameId: number, threadId: number, depth: number, varname: string)
: Promise<void> {
: Promise<void> {
let deleteme: VarObjType | undefined;
const vars = variableMap.get(getKey(frameId, threadId, depth));
if (vars) {
Expand All @@ -59,8 +61,8 @@ export async function removeVar(gdb: GDBBackend, frameId: number, threadId: numb
break;
}
}
if (deleteme) {
await sendVarDelete(gdb, {varname: deleteme.varname});
if (deleteme) {
await sendVarDelete(gdb, { varname: deleteme.varname });
vars.splice(vars.indexOf(deleteme), 1);
for (const child of deleteme.children) {
await removeVar(gdb, frameId, threadId, depth, child.varname);
Expand All @@ -70,18 +72,18 @@ export async function removeVar(gdb: GDBBackend, frameId: number, threadId: numb
}

export async function updateVar(gdb: GDBBackend, frameId: number, threadId: number, depth: number, varobj: VarObjType)
: Promise<VarObjType> {
: Promise<VarObjType> {
let returnVar = varobj;
const vup = await sendVarUpdate(gdb, {threadId, name: varobj.varname});
const vup = await sendVarUpdate(gdb, { threadId, name: varobj.varname });
const update = vup.changelist[0];
if (update) {
if (update.in_scope === 'true') {
varobj.value = update.value;
varobj.isVar = true;
} else {
removeVar(gdb, frameId, threadId, depth, varobj.varname);
await sendVarDelete(gdb, {varname: varobj.varname});
const createResponse = await sendVarCreate(gdb, {frame: 'current', expression: varobj.expression});
await sendVarDelete(gdb, { varname: varobj.varname });
const createResponse = await sendVarCreate(gdb, { frame: 'current', expression: varobj.expression });
returnVar = addVar(frameId, threadId, depth, varobj.expression, true, false, createResponse);
}
}
Expand Down
Loading

0 comments on commit 80b5495

Please sign in to comment.