Skip to content

Commit 2fed60f

Browse files
committed
chore: format
1 parent a52eadf commit 2fed60f

File tree

8 files changed

+393
-496
lines changed

8 files changed

+393
-496
lines changed

.github/workflows/bump_deps.yml

-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
ncu -u --dep prod
2525
pnpm install
2626
27-
2827
- uses: tibdex/github-app-token@v1
2928
id: generate-token
3029
with:
@@ -38,7 +37,6 @@ jobs:
3837
labels: Dependencies
3938
branch: "Bump_Dependencies"
4039

41-
4240
Bump_devDependencies:
4341
runs-on: ubuntu-latest
4442
steps:

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Python language support for [Atom-IDE](https://atom-ide-community.github.io), po
1212

1313
### Important
1414

15-
Please note that `atom-ide-ui` is now deprecated, therefore, you must use the packages supplied from `atom-ide-community` as mentioned above. Links are also provided for more information.
15+
Please note that `atom-ide-ui` is now deprecated, therefore, you must use the packages supplied from `atom-ide-community` as mentioned above. Links are also provided for more information.
1616

1717
## Feature Providers
1818

@@ -62,12 +62,14 @@ apm install ide-python
6262
```
6363

6464
To use the debugger you need to install `atom-ide-debugger` and `atom-ide-console` as well:
65+
6566
```
6667
apm install atom-ide-debugger
6768
apm install atom-ide-console
6869
```
6970

7071
### Debugger (experimental)
72+
7173
After installation of the above packages:
7274

7375
- Open the file you need to debug
+77-81
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,147 @@
1-
import type {ConnectableObservable} from 'rxjs-compat/bundles/rxjs-compat.umd.min.js';
1+
import type { ConnectableObservable } from "rxjs-compat/bundles/rxjs-compat.umd.min.js"
22

3-
import http from 'http';
4-
import net from 'net';
5-
import {Observable, Subject} from 'rxjs-compat/bundles/rxjs-compat.umd.min.js';
6-
import {getLogger} from 'log4js';
7-
import {sleep} from '@atom-ide-community/nuclide-commons/promise';
3+
import http from "http"
4+
import net from "net"
5+
import { Observable, Subject } from "rxjs-compat/bundles/rxjs-compat.umd.min.js"
6+
import { getLogger } from "log4js"
7+
import { sleep } from "@atom-ide-community/nuclide-commons/promise"
88

9-
let isServerSetup = false;
9+
let isServerSetup = false
1010

1111
export type RemoteDebugCommandRequest = {
12-
type: 'python',
13-
command: 'attach',
12+
type: "python",
13+
command: "attach",
1414
target: PythonDebuggerAttachTarget,
15-
};
15+
}
1616

1717
export type PythonDebuggerAttachTarget = {
1818
port: number,
1919
localRoot: ?string,
2020
remoteRoot: ?string,
2121
debugOptions: ?Array<string>,
2222
id: ?string,
23-
};
23+
}
2424

25-
const debugRequests: Subject<RemoteDebugCommandRequest> = new Subject();
26-
const attachReady: Map<number, PythonDebuggerAttachTarget> = new Map();
27-
const DEBUGGER_REGISTRY_PORT = 9615;
25+
const debugRequests: Subject<RemoteDebugCommandRequest> = new Subject()
26+
const attachReady: Map<number, PythonDebuggerAttachTarget> = new Map()
27+
const DEBUGGER_REGISTRY_PORT = 9615
2828

29-
export function observeRemoteDebugCommands(): ConnectableObservable<
30-
RemoteDebugCommandRequest,
31-
> {
32-
let setupStep;
29+
export function observeRemoteDebugCommands(): ConnectableObservable<RemoteDebugCommandRequest> {
30+
let setupStep
3331
if (!isServerSetup) {
34-
setupStep = Observable.fromPromise(setupServer()).ignoreElements();
32+
setupStep = Observable.fromPromise(setupServer()).ignoreElements()
3533
} else {
36-
setupStep = Observable.empty();
34+
setupStep = Observable.empty()
3735
}
38-
return setupStep.concat(debugRequests).publish();
36+
return setupStep.concat(debugRequests).publish()
3937
}
4038

41-
export function observeAttachDebugTargets(): ConnectableObservable<
42-
Array<PythonDebuggerAttachTarget>,
43-
> {
39+
export function observeAttachDebugTargets(): ConnectableObservable<Array<PythonDebuggerAttachTarget>> {
4440
// Validate attach-ready values with the processes with used ports (ready to attach).
4541
// Note: we can't use process ids because we could be debugging processes inside containers
4642
// where the process ids don't map to the host running this code.
4743
return Observable.interval(3000)
4844
.startWith(0)
4945
.switchMap(() =>
5046
Promise.all(
51-
Array.from(attachReady.values()).map(async target => {
47+
Array.from(attachReady.values()).map(async (target) => {
5248
if (!(await isPortUsed(target.port))) {
53-
attachReady.delete(target.port);
49+
attachReady.delete(target.port)
5450
}
55-
}),
56-
),
51+
})
52+
)
5753
)
5854
.map(() => Array.from(attachReady.values()))
59-
.publish();
55+
.publish()
6056
}
6157

6258
function isPortUsed(port: number): Promise<boolean> {
6359
const tryConnectPromise = new Promise((resolve, reject) => {
64-
const client = new net.Socket();
60+
const client = new net.Socket()
6561
client
66-
.once('connect', () => {
67-
cleanUp();
68-
resolve(true);
62+
.once("connect", () => {
63+
cleanUp()
64+
resolve(true)
65+
})
66+
.once("error", (err) => {
67+
cleanUp()
68+
resolve(err.code !== "ECONNREFUSED")
6969
})
70-
.once('error', err => {
71-
cleanUp();
72-
resolve(err.code !== 'ECONNREFUSED');
73-
});
7470

7571
function cleanUp() {
76-
client.removeAllListeners('connect');
77-
client.removeAllListeners('error');
78-
client.end();
79-
client.destroy();
80-
client.unref();
72+
client.removeAllListeners("connect")
73+
client.removeAllListeners("error")
74+
client.end()
75+
client.destroy()
76+
client.unref()
8177
}
8278

83-
client.connect({port, host: '127.0.0.1'});
84-
});
79+
client.connect({ port, host: "127.0.0.1" })
80+
})
8581
// Trying to connect can take multiple seconds, then times out (if the server is busy).
8682
// Hence, we need to fallback to `true`.
87-
const connectTimeoutPromise = sleep(1000).then(() => true);
88-
return Promise.race([tryConnectPromise, connectTimeoutPromise]);
83+
const connectTimeoutPromise = sleep(1000).then(() => true)
84+
return Promise.race([tryConnectPromise, connectTimeoutPromise])
8985
}
9086

9187
function setupServer(): Promise<void> {
9288
return new Promise((resolve, reject) => {
9389
http
9490
.createServer((req, res) => {
95-
if (req.method !== 'POST') {
96-
res.writeHead(500, {'Content-Type': 'text/html'});
97-
res.end('Invalid request');
91+
if (req.method !== "POST") {
92+
res.writeHead(500, { "Content-Type": "text/html" })
93+
res.end("Invalid request")
9894
} else {
99-
let body = '';
100-
req.on('data', data => {
101-
body += data;
102-
});
103-
req.on('end', () => {
104-
handleJsonRequest(JSON.parse(body), res);
105-
});
95+
let body = ""
96+
req.on("data", (data) => {
97+
body += data
98+
})
99+
req.on("end", () => {
100+
handleJsonRequest(JSON.parse(body), res)
101+
})
106102
}
107103
})
108-
.on('error', reject)
104+
.on("error", reject)
109105
.listen((DEBUGGER_REGISTRY_PORT: any), () => {
110-
isServerSetup = true;
111-
resolve();
112-
});
113-
});
106+
isServerSetup = true
107+
resolve()
108+
})
109+
})
114110
}
115111

116112
function handleJsonRequest(body, res) {
117-
res.writeHead(200, {'Content-Type': 'application/json'});
118-
const {domain, command, type} = body;
119-
let success = false;
120-
if (domain !== 'debug' || type !== 'python') {
121-
res.end(JSON.stringify({success}));
122-
return;
113+
res.writeHead(200, { "Content-Type": "application/json" })
114+
const { domain, command, type } = body
115+
let success = false
116+
if (domain !== "debug" || type !== "python") {
117+
res.end(JSON.stringify({ success }))
118+
return
123119
}
124-
if (command === 'enable-attach') {
125-
const port = Number(body.port);
126-
const {options} = body;
120+
if (command === "enable-attach") {
121+
const port = Number(body.port)
122+
const { options } = body
127123
const target = {
128124
port,
129125
id: options.id,
130126
localRoot: options.localRoot,
131127
remoteRoot: options.remoteRoot,
132128
debugOptions: options.debugOptions,
133-
};
134-
attachReady.set(port, target);
135-
getLogger().info('Remote debug target is ready to attach', target);
136-
success = true;
137-
} else if (command === 'attach') {
138-
const port = Number(body.port);
139-
getLogger().info('Remote debug target attach request', body);
140-
const target = attachReady.get(port);
129+
}
130+
attachReady.set(port, target)
131+
getLogger().info("Remote debug target is ready to attach", target)
132+
success = true
133+
} else if (command === "attach") {
134+
const port = Number(body.port)
135+
getLogger().info("Remote debug target attach request", body)
136+
const target = attachReady.get(port)
141137
if (target != null) {
142138
debugRequests.next({
143139
type,
144140
command,
145141
target,
146-
});
147-
success = true;
142+
})
143+
success = true
148144
}
149145
}
150-
res.end(JSON.stringify({success}));
146+
res.end(JSON.stringify({ success }))
151147
}

0 commit comments

Comments
 (0)