Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Nov 22, 2024
1 parent 43fbe6f commit e36e9a6
Show file tree
Hide file tree
Showing 12 changed files with 481 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Source/node/URI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class URI {

const u = new URI();
u._uri = path;

try {
u._u = URL.parse(path);
} catch (e) {
Expand All @@ -91,6 +92,7 @@ export class URI {
) {
const u = new URI();
u._uri = uri;

try {
u._u = URL.parse(uri);
} catch (e) {
Expand Down Expand Up @@ -132,6 +134,7 @@ export class URI {

data(): string | null {
const pos = this._uri.lastIndexOf(",");

if (pos > 0) {
return this._uri.substr(pos + 1);
}
Expand Down
6 changes: 6 additions & 0 deletions Source/node/extension/autoAttach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const localize = nls.loadMessageBundle();
const POLL_INTERVAL = 1000;

const pids: Promise<number>[] = [];

let autoAttacher: vscode.Disposable | undefined;

export function getPidFromSession(
Expand Down Expand Up @@ -79,6 +80,7 @@ export function initializeAutoAttach(context: vscode.ExtensionContext) {
true,
(pid, cmdPath, args) => {
const cmdName = basename(cmdPath, ".exe");

if (cmdName === "node") {
const name = localize(
"process.with.pid.label",
Expand Down Expand Up @@ -171,6 +173,7 @@ export function attachToProcess(
}

let { usePort, protocol, port } = analyseArguments(args);

if (usePort) {
config.processId = `${protocol}${port}`;
} else {
Expand Down Expand Up @@ -200,6 +203,7 @@ function pollProcesses(
//const start = Date.now();
findChildProcesses(rootPid, inTerminal, cb).then((_) => {
//console.log(`duration: ${Date.now() - start}`);

setTimeout((_) => {
if (!stopped) {
poll();
Expand Down Expand Up @@ -228,6 +232,7 @@ function findChildProcesses(
}

let { protocol } = analyseArguments(node.args);

if (terminal && protocol) {
cb(node.pid, node.command, node.args);
}
Expand All @@ -240,6 +245,7 @@ function findChildProcesses(
return getProcessTree(rootPid).then((tree) => {
if (tree) {
const terminals = vscode.window.terminals;

if (terminals.length > 0) {
Promise.all(
terminals.map((terminal) => terminal.processId),
Expand Down
5 changes: 5 additions & 0 deletions Source/node/extension/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ export class Cluster {

static startSession(session: vscode.DebugSession) {
const cluster = this.clusters.get(session.name);

if (cluster) {
cluster.startWatching(session);
}
}

static stopSession(session: vscode.DebugSession) {
const cluster = this.clusters.get(session.name);

if (cluster) {
cluster.stopWatching();
this.clusters.delete(session.name);
Expand All @@ -61,6 +63,7 @@ export class Cluster {
// only attach to new child processes
if (!this._subProcesses.has(pid)) {
this._subProcesses.add(pid);

const name = localize(
"child.process.with.pid.label",
"Child process {0}",
Expand Down Expand Up @@ -101,6 +104,7 @@ function pollProcesses(
//const start = Date.now();
findChildProcesses(rootPid, cb).then((_) => {
//console.log(`duration: ${Date.now() - start}`);

setTimeout((_) => {
if (!stopped) {
poll();
Expand All @@ -121,6 +125,7 @@ function findChildProcesses(
function walker(node: ProcessTreeNode) {
if (node.pid !== rootPid) {
let { protocol } = analyseArguments(node.args);

if (protocol) {
cb(node.pid, node.command, node.args);
}
Expand Down
36 changes: 36 additions & 0 deletions Source/node/extension/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import { detectDebugType } from "./protocolDetection";
import { Logger, mkdirP, writeToConsole } from "./utilities";

const DEBUG_SETTINGS = "debug.node";

const SHOW_USE_WSL_IS_DEPRECATED_WARNING_SETTING =
"showUseWslIsDeprecatedWarning";

const DEFAULT_JS_PATTERNS: ReadonlyArray<string> = [
"*.js",
"*.es6",
Expand Down Expand Up @@ -212,6 +214,7 @@ export class NodeConfigurationProvider

// determine which protocol to use after all variables have been substituted (including command variables for process picker)
const debugType = await determineDebugType(config, this._logger);

if (debugType) {
config.type = debugType;
}
Expand All @@ -223,9 +226,11 @@ export class NodeConfigurationProvider
private getJavaScriptPatterns() {
const associations =
vscode.workspace.getConfiguration("files.associations");

const extension = vscode.extensions.getExtension<{}>(
"ms-vscode.node-debug",
);

if (!extension) {
throw new Error("Expected to be able to load extension data");
}
Expand All @@ -234,6 +239,7 @@ export class NodeConfigurationProvider
extension.packageJSON.contributes.breakpoints.map(
(b) => b.language,
);

return Object.keys(associations)
.filter(
(pattern) =>
Expand Down Expand Up @@ -280,6 +286,7 @@ export class NodeConfigurationProvider
false,
vscode.ConfigurationTarget.Global,
);

break;
}
});
Expand All @@ -292,16 +299,19 @@ export class NodeConfigurationProvider
*/
private async nvmSupport(config: vscode.DebugConfiguration): Promise<void> {
let bin: string | undefined = undefined;

let versionManagerName: string | undefined = undefined;

// first try the Node Version Switcher 'nvs'
let nvsHome = process.env["NVS_HOME"];

if (!nvsHome) {
// NVS_HOME is not always set. Probe for 'nvs' directory instead
const nvsDir =
process.platform === "win32"
? join(process.env["LOCALAPPDATA"] || "", "nvs")
: join(process.env["HOME"] || "", ".nvs");

if (fs.existsSync(nvsDir)) {
nvsHome = nvsDir;
}
Expand All @@ -313,6 +323,7 @@ export class NodeConfigurationProvider
if (nvsFormat || nvsHome) {
if (nvsHome) {
bin = join(nvsHome, remoteName, semanticVersion, arch);

if (process.platform !== "win32") {
bin = join(bin, "bin");
}
Expand All @@ -331,6 +342,7 @@ export class NodeConfigurationProvider
// now try the Node Version Manager 'nvm'
if (process.platform === "win32") {
const nvmHome = process.env["NVM_HOME"];

if (!nvmHome) {
throw new Error(
localize(
Expand All @@ -344,9 +356,11 @@ export class NodeConfigurationProvider
} else {
// macOS and linux
let nvmHome = process.env["NVM_DIR"];

if (!nvmHome) {
// if NVM_DIR is not set. Probe for '.nvm' directory instead
const nvmDir = join(process.env["HOME"] || "", ".nvm");

if (fs.existsSync(nvmDir)) {
nvmHome = nvmDir;
}
Expand Down Expand Up @@ -411,6 +425,7 @@ function createLaunchConfigFromContext(
}

const pkg = loadJSON(folder, "package.json");

if (pkg && pkg.name === "mern-starter") {
if (resolve) {
writeToConsole(
Expand All @@ -429,11 +444,13 @@ function createLaunchConfigFromContext(
configureMern(config);
} else {
let program: string | undefined;

let useSourceMaps = false;

if (pkg) {
// try to find a value for 'program' by analysing package.json
program = guessProgramFromPackage(folder, pkg, resolve);

if (program && resolve) {
writeToConsole(
localize(
Expand All @@ -447,20 +464,24 @@ function createLaunchConfigFromContext(
if (!program) {
// try to use file open in editor
const editor = vscode.window.activeTextEditor;

if (editor) {
const languageId = editor.document.languageId;

if (
languageId === "javascript" ||
isTranspiledLanguage(languageId)
) {
const wf = vscode.workspace.getWorkspaceFolder(
editor.document.uri,
);

if (wf && wf === folder) {
program = relative(
wf.uri.fsPath || "/",
editor.document.uri.fsPath || "/",
);

if (program && !isAbsolute(program)) {
program = join("${workspaceFolder}", program);
}
Expand Down Expand Up @@ -496,15 +517,19 @@ function createLaunchConfigFromContext(
}

let dir = "";

const tsConfig = loadJSON(folder, "tsconfig.json");

if (
tsConfig &&
tsConfig.compilerOptions &&
tsConfig.compilerOptions.outDir
) {
const outDir = <string>tsConfig.compilerOptions.outDir;

if (!isAbsolute(outDir)) {
dir = outDir;

if (dir.indexOf("./") === 0) {
dir = dir.substr(2);
}
Expand All @@ -528,7 +553,9 @@ function loadJSON(
if (folder) {
try {
const path = join(folder.uri.fsPath, file);

const content = fs.readFileSync(path, "utf8");

return JSON.parse(content);
} catch (error) {
// silently ignore
Expand Down Expand Up @@ -577,6 +604,7 @@ function guessProgramFromPackage(

if (program) {
let path: string | undefined;

if (isAbsolute(program)) {
path = program;
} else {
Expand Down Expand Up @@ -621,13 +649,17 @@ function nvsStandardArchName(arch) {
case "x86":
case "ia32":
return "x86";

case "64":
case "x64":
case "amd64":
return "x64";

case "arm":
const arm_version = (process.config.variables as any).arm_version;

return arm_version ? "armv" + arm_version + "l" : "arm";

default:
return arch;
}
Expand All @@ -642,13 +674,17 @@ function parseVersionString(versionString) {
/^(([\w-]+)\/)?(v?(\d+(\.\d+(\.\d+)?)?))(\/((x86)|(32)|((x)?64)|(arm\w*)|(ppc\w*)))?$/i;

const match = versionRegex.exec(versionString);

if (!match) {
throw new Error("Invalid version string: " + versionString);
}

const nvsFormat = !!(match[2] || match[8]);

const remoteName = match[2] || "node";

const semanticVersion = match[4] || "";

const arch = nvsStandardArchName(match[8] || process.arch);

return { nvsFormat, remoteName, semanticVersion, arch };
Expand Down
7 changes: 7 additions & 0 deletions Source/node/extension/processPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function resolveProcessId(
/^(inspector|legacy)?([0-9]+)(inspector|legacy)?([0-9]+)?$/.exec(
processId,
);

if (matches && matches.length === 5) {
if (matches[2] && matches[3] && matches[4]) {
// process id and protocol and port
Expand Down Expand Up @@ -85,6 +86,7 @@ export async function resolveProcessId(
config,
pid,
);

if (debugType) {
// processID is handled, so turn this config into a normal port attach configuration
delete config.processId;
Expand Down Expand Up @@ -135,6 +137,7 @@ export function pickProcess(ports?): Promise<string | null> {
matchOnDescription: true,
matchOnDetail: true,
};

return vscode.window
.showQuickPick(items, options)
.then((item) => (item ? item.pidOrPort : null));
Expand Down Expand Up @@ -181,7 +184,9 @@ function listProcesses(ports: boolean): Promise<ProcessItem[]> {
const executable_name = basename(command, ".exe");

let port = -1;

let protocol: string | undefined = "";

let usePort = true;

if (ports) {
Expand All @@ -192,6 +197,7 @@ function listProcesses(ports: boolean): Promise<ProcessItem[]> {
}

let description = "";

let pidOrPort = "";

if (usePort) {
Expand Down Expand Up @@ -281,6 +287,7 @@ function determineDebugTypeForPidInDebugMode(
pid: number,
): Promise<string | null> {
let debugProtocolP: Promise<string | null>;

if (config.port === INSPECTOR_PORT_DEFAULT) {
debugProtocolP = Promise.resolve("inspector");
} else if (config.port === LEGACY_PORT_DEFAULT) {
Expand Down
Loading

0 comments on commit e36e9a6

Please sign in to comment.