@codingame/monaco-vscode-1b4486de-4fe4-59c4-9e6d-34f265ff6625-common 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ import { ITerminalService } from "vscode/vscode/vs/workbench/contrib/terminal/browser/terminal.service";
2
+ import { Disposable } from "vscode/vscode/vs/base/common/lifecycle";
3
+ import { IDebugService } from "vscode/vscode/vs/workbench/contrib/debug/common/debug.service";
4
+ export declare class UrlFinder extends Disposable {
5
+ private static readonly localUrlRegex;
6
+ private static readonly extractPortRegex;
7
+ private static readonly localPythonServerRegex;
8
+ private static readonly excludeTerminals;
9
+ private _onDidMatchLocalUrl;
10
+ readonly onDidMatchLocalUrl: import("vscode/vscode/vs/base/common/event").Event<{
11
+ host: string;
12
+ port: number;
13
+ }>;
14
+ private listeners;
15
+ constructor(terminalService: ITerminalService, debugService: IDebugService);
16
+ private registerTerminalInstance;
17
+ private replPositions;
18
+ private processNewReplElements;
19
+ dispose(): void;
20
+ private processData;
21
+ }
@@ -0,0 +1,110 @@
1
+
2
+ import { Emitter } from 'vscode/vscode/vs/base/common/event';
3
+ import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
4
+ import { removeAnsiEscapeCodes } from 'vscode/vscode/vs/base/common/strings';
5
+
6
+ class UrlFinder extends Disposable {
7
+ static { this.localUrlRegex = /\b\w{0,20}(?::\/\/)?(?:localhost|127\.0\.0\.1|0\.0\.0\.0|:\d{2,5})[\w\-\.\~:\/\?\#[\]\@!\$&\(\)\*\+\,\;\=]*/gim; }
8
+ static { this.extractPortRegex = /(localhost|127\.0\.0\.1|0\.0\.0\.0):(\d{1,5})/; }
9
+ static { this.localPythonServerRegex = /HTTP\son\s(127\.0\.0\.1|0\.0\.0\.0)\sport\s(\d+)/; }
10
+ static { this.excludeTerminals = ['Dev Containers']; }
11
+ constructor(terminalService, debugService) {
12
+ super();
13
+ this._onDidMatchLocalUrl = ( new Emitter());
14
+ this.onDidMatchLocalUrl = this._onDidMatchLocalUrl.event;
15
+ this.listeners = ( new Map());
16
+ this.replPositions = ( new Map());
17
+ terminalService.instances.forEach(instance => {
18
+ this.registerTerminalInstance(instance);
19
+ });
20
+ this._register(terminalService.onDidCreateInstance(instance => {
21
+ this.registerTerminalInstance(instance);
22
+ }));
23
+ this._register(terminalService.onDidDisposeInstance(instance => {
24
+ this.listeners.get(instance)?.dispose();
25
+ this.listeners.delete(instance);
26
+ }));
27
+ this._register(debugService.onDidNewSession(session => {
28
+ if (!session.parentSession || (session.parentSession && session.hasSeparateRepl())) {
29
+ this.listeners.set(session.getId(), session.onDidChangeReplElements(() => {
30
+ this.processNewReplElements(session);
31
+ }));
32
+ }
33
+ }));
34
+ this._register(debugService.onDidEndSession(({ session }) => {
35
+ if (( this.listeners.has(session.getId()))) {
36
+ this.listeners.get(session.getId())?.dispose();
37
+ this.listeners.delete(session.getId());
38
+ }
39
+ }));
40
+ }
41
+ registerTerminalInstance(instance) {
42
+ if (!UrlFinder.excludeTerminals.includes(instance.title)) {
43
+ this.listeners.set(instance, instance.onData(data => {
44
+ this.processData(data);
45
+ }));
46
+ }
47
+ }
48
+ processNewReplElements(session) {
49
+ const oldReplPosition = this.replPositions.get(session.getId());
50
+ const replElements = session.getReplElements();
51
+ this.replPositions.set(session.getId(), { position: replElements.length - 1, tail: replElements[replElements.length - 1] });
52
+ if (!oldReplPosition && replElements.length > 0) {
53
+ replElements.forEach(element => this.processData(( element.toString())));
54
+ }
55
+ else if (oldReplPosition && (replElements.length - 1 !== oldReplPosition.position)) {
56
+ for (let i = replElements.length - 1; i >= 0; i--) {
57
+ const element = replElements[i];
58
+ if (element === oldReplPosition.tail) {
59
+ break;
60
+ }
61
+ else {
62
+ this.processData(( element.toString()));
63
+ }
64
+ }
65
+ }
66
+ }
67
+ dispose() {
68
+ super.dispose();
69
+ const listeners = ( this.listeners.values());
70
+ for (const listener of listeners) {
71
+ listener.dispose();
72
+ }
73
+ }
74
+ processData(data) {
75
+ data = removeAnsiEscapeCodes(data);
76
+ const urlMatches = data.match(UrlFinder.localUrlRegex) || [];
77
+ if (urlMatches.length > 0) {
78
+ urlMatches.forEach((match) => {
79
+ let serverUrl;
80
+ try {
81
+ serverUrl = ( new URL(match));
82
+ }
83
+ catch (e) {
84
+ }
85
+ if (serverUrl) {
86
+ const portMatch = match.match(UrlFinder.extractPortRegex);
87
+ const port = parseFloat(serverUrl.port ? serverUrl.port : (portMatch ? portMatch[2] : 'NaN'));
88
+ if (!isNaN(port) && Number.isInteger(port) && port > 0 && port <= 65535) {
89
+ let host = serverUrl.hostname;
90
+ if (host !== '0.0.0.0' && host !== '127.0.0.1') {
91
+ host = 'localhost';
92
+ }
93
+ if (port !== 9229 && data.startsWith('Debugger listening on')) {
94
+ return;
95
+ }
96
+ this._onDidMatchLocalUrl.fire({ port, host });
97
+ }
98
+ }
99
+ });
100
+ }
101
+ else {
102
+ const pythonMatch = data.match(UrlFinder.localPythonServerRegex);
103
+ if (pythonMatch && pythonMatch.length === 3) {
104
+ this._onDidMatchLocalUrl.fire({ host: pythonMatch[1], port: Number(pythonMatch[2]) });
105
+ }
106
+ }
107
+ }
108
+ }
109
+
110
+ export { UrlFinder };