diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index b06f5e547..102304e90 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -10,6 +10,7 @@ import { basename, dirname } from 'path'; import { spawn, ChildProcess } from 'child_process'; import { Client, RPCConnection } from 'json-rpc2'; import { getBinPath } from '../goPath'; +import {random} from './../util'; require('console-stamp')(console); @@ -214,7 +215,7 @@ class Delve { function connectClient(port: number, host: string) { // Add a slight delay to avoid issues on Linux with - // Delve failing calls made shortly after connection. + // Delve failing calls made shortly after connection. setTimeout(() => { let client = Client.$create(port, host); client.connectSocket((err, conn) => { @@ -320,7 +321,7 @@ class GoDebugSession extends DebugSession { protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void { // Launch the Delve debugger on the program let remotePath = args.remotePath || ''; - let port = args.port || 2345; + let port = args.port || random(2000, 50000); let host = args.host || '127.0.0.1'; if (remotePath.length > 0) { diff --git a/src/util.ts b/src/util.ts index 826bcaf47..246c77d8c 100644 --- a/src/util.ts +++ b/src/util.ts @@ -49,7 +49,7 @@ export function parseFilePrelude(text: string): Prelude { } // Takes a Go function signature like: -// (foo, bar string, baz number) (string, string) +// (foo, bar string, baz number) (string, string) // and returns an array of parameter strings: // ["foo", "bar string", "baz string"] // Takes care of balancing parens so to not get confused by signatures like: @@ -94,4 +94,8 @@ export function canonicalizeGOPATHPrefix(filename: string): string { } } return filename; -} \ No newline at end of file +} + +export function random(low: number, high: number): number { + return Math.floor(Math.random() * (high - low) + low); +}