From 73460e08e9daaecdfdbb2533dded3e3a1850be7d Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Wed, 26 Oct 2016 23:01:32 -0700 Subject: [PATCH] Fix #564 - util should not be imported from the debug adapter! (#576) * Fix #564 - util should not be imported from the debug adapter! * Add warning to goPath.ts --- src/debugAdapter/goDebug.ts | 5 ++++- src/goPath.ts | 9 ++++++--- src/util.ts | 6 +----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts index 102304e90..8d7d170f5 100644 --- a/src/debugAdapter/goDebug.ts +++ b/src/debugAdapter/goDebug.ts @@ -10,7 +10,6 @@ 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); @@ -709,4 +708,8 @@ class GoDebugSession extends DebugSession { } } +function random(low: number, high: number): number { + return Math.floor(Math.random() * (high - low) + low); +} + DebugSession.run(GoDebugSession); diff --git a/src/goPath.ts b/src/goPath.ts index 94ca8e2a0..f4be592f4 100644 --- a/src/goPath.ts +++ b/src/goPath.ts @@ -5,6 +5,9 @@ 'use strict'; +/** + * This file is loaded by both the extension and debug adapter, so it cannot import 'vscode' + */ import fs = require('fs'); import path = require('path'); import os = require('os'); @@ -48,7 +51,7 @@ export function getBinPath(binname: string) { return pathFromGoRoot; } - // Else return the binary name directly (this will likely always fail downstream) + // Else return the binary name directly (this will likely always fail downstream) return binname; } @@ -61,8 +64,8 @@ function correctBinname(binname: string) { /** * Returns Go runtime binary path. - * - * @return the path to the Go binary. + * + * @return the path to the Go binary. */ export function getGoRuntimePath(): string { if (runtimePathCache !== 'go') return runtimePathCache; diff --git a/src/util.ts b/src/util.ts index c66a4de30..2c19eebd1 100644 --- a/src/util.ts +++ b/src/util.ts @@ -107,7 +107,7 @@ export function canonicalizeGOPATHPrefix(filename: string): string { } /** - * Gets version of Go based on the output of the command `go version`. + * Gets version of Go based on the output of the command `go version`. * Returns null if go is being used from source/tip in which case `go version` will not return release tag like go1.6.3 */ export function getGoVersion(): Promise { @@ -161,7 +161,3 @@ export function isVendorSupported(): Promise { return vendorSupport; }); } - -export function random(low: number, high: number): number { - return Math.floor(Math.random() * (high - low) + low); -}