src/goDebugFactory: disable logDest support on windows

Updates golang/vscode-go#1472
Updates golang/vscode-go#1407

Change-Id: Ia19b89c2c8d7001d06a4d0c5826c7b2c8f9a20d7
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/317290
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
diff --git a/docs/debugging.md b/docs/debugging.md
index 06b2cc4..5e81b51 100644
--- a/docs/debugging.md
+++ b/docs/debugging.md
@@ -111,7 +111,7 @@
 args       | Array of command-line arguments to pass to the program being debugged.
 showLog    | If `true` and `logDest` is not set, Delve logs will be printed in the Debug Console panel. If `true` and `logDest` is set, logs will be written to the `logDest` file. This corresponds to `dlv`'s `--log` flag.
 logOutput  | Comma-separated list of Delve components (`debugger`, `gdbwire`, `lldbout`, `debuglineerr`, `rpc`) that should produce debug output when `showLog` is `true`. This corresponds to `dlv`'s `--log-output` flag.
-logDest    | Absolute path to the delve log output file. This corresponds to `dlv`'s `--log-dest` flag, but number (used for file descriptor) is disallowed. Supported only in dlv-dap mode.
+logDest    | Absolute path to the delve log output file. This corresponds to `dlv`'s `--log-dest` flag, but number (used for file descriptor) is disallowed. Supported only in dlv-dap mode on Linux and Mac.
 buildFlags | Build flags to pass to the Go compiler. This corresponds to `dlv`'s `--build-flags` flag.
 dlvFlags   | Extra flags passed to `dlv`. See `dlv help` for the full list of supported flags. This is useful when users need to pass less commonly used or new flags such as `--only-same-user`, `--check-go-version`. Note that some flags such as `--log-output`, `--log`, `--log-dest`, `--init`, `--api-version` already have corresponding properties in the debug configuration, and flags such as `--listen` and `--headless` are used internally. If they are specified in `dlvFlags`, they may be ignored or cause an error.
 remotePath | If remote debugging (`mode`: `remote`), this should be the absolute path to the package being debugged on the remote machine. See the section on [Remote Debugging](#remote-debugging) for further details. [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) is also relevant. Becomes the first mapping in substitutePath.
diff --git a/package.json b/package.json
index 33dfe02..e9bc433 100644
--- a/package.json
+++ b/package.json
@@ -672,7 +672,7 @@
               },
               "logDest": {
                 "type": "string",
-                "description": "dlv's `--log-dest` flag. See `dlv log` for details. Number argument is not allowed. Supported only in dlv-dap mode."
+                "description": "dlv's `--log-dest` flag. See `dlv log` for details. Number argument is not allowed. Supported only on Linux and Mac OS in dlv-dap mode."
               },
               "dlvLoadConfig": {
                 "type": "object",
@@ -865,7 +865,7 @@
               },
               "logDest": {
                 "type": "string",
-                "description": "dlv's `--log-dest` flag. See `dlv log` for details. Number argument is not allowed. Supported only in dlv-dap mode."
+                "description": "dlv's `--log-dest` flag. See `dlv log` for details. Number argument is not allowed. Supported only on Linux and Mac OS in dlv-dap mode."
               },
               "dlvLoadConfig": {
                 "type": "object",
diff --git a/src/goDebugFactory.ts b/src/goDebugFactory.ts
index 01e04fa..9fb36ac 100644
--- a/src/goDebugFactory.ts
+++ b/src/goDebugFactory.ts
@@ -347,7 +347,12 @@
 	if (launchArgs.logOutput) {
 		dlvArgs.push('--log-output=' + launchArgs.logOutput);
 	}
-	dlvArgs.push('--log-dest=3');
+
+	const onWindows = process.platform === 'win32';
+
+	if (!onWindows) {
+		dlvArgs.push('--log-dest=3');
+	}
 
 	const logDest = launchArgs.logDest;
 	if (typeof logDest === 'number') {
@@ -360,6 +365,13 @@
 		);
 		throw new Error('Using a relative path for `logDest` is not allowed');
 	}
+	if (logDest && onWindows) {
+		logErr(
+			'Using `logDest` or `--log-dest` is not supported on windows yet. See https://github.com/golang/vscode-go/issues/1472.'
+		);
+		throw new Error('Using `logDest` on windows is not allowed');
+	}
+
 	const logDestStream = logDest ? fs.createWriteStream(logDest) : undefined;
 
 	logConsole(`Running: ${dlvPath} ${dlvArgs.join(' ')}\n`);
@@ -394,10 +406,15 @@
 		};
 
 		p.stdout.on('data', (chunk) => {
+			const msg = chunk.toString();
 			if (!started) {
-				stopWaitingForServerToStart(`Unexpected output from dlv dap on start: '${chunk.toString()}'`);
+				if (msg.startsWith('DAP server listening at:')) {
+					stopWaitingForServerToStart();
+				} else {
+					stopWaitingForServerToStart(`Unexpected output from dlv dap on start: '${msg}'`);
+				}
 			}
-			log(chunk.toString());
+			log(msg);
 		});
 		p.stderr.on('data', (chunk) => {
 			if (!started) {
@@ -415,6 +432,7 @@
 				}
 			}
 			if (logDestStream) {
+				// always false on windows.
 				// write to the specified file.
 				logDestStream?.write(chunk, (err) => {
 					if (err) {
@@ -426,6 +444,7 @@
 			}
 		});
 		p.stdio[3].on('close', () => {
+			// always false on windows.
 			logDestStream?.end();
 		});
 		p.on('close', (code, signal) => {
diff --git a/test/integration/goDebug.test.ts b/test/integration/goDebug.test.ts
index adfdd07..2d2465c 100644
--- a/test/integration/goDebug.test.ts
+++ b/test/integration/goDebug.test.ts
@@ -28,7 +28,6 @@
 import { killProcessTree } from '../../src/utils/processUtils';
 import getPort = require('get-port');
 import util = require('util');
-import { OutputEvent } from 'vscode-debugadapter';
 import { parseProgramArgSync } from '../../src/goDebugFactory';
 import { TimestampedLogger } from '../../src/goLogging';
 
@@ -1771,7 +1770,7 @@
 		});
 
 		test('logs are written to logDest file', async function () {
-			if (!isDlvDap) {
+			if (!isDlvDap || process.platform === 'win32') {
 				this.skip();
 			}
 			const DELVE_LOG = path.join(tmpDir, 'delve.log');
@@ -1816,12 +1815,12 @@
 			assert.fail('dlv dap started normally, wanted the invalid logDest to cause failure');
 		}
 		test('relative path as logDest triggers an error', async function () {
-			if (!isDlvDap) this.skip();
+			if (!isDlvDap || process.platform === 'win32') this.skip();
 			await testWithInvalidLogDest('delve.log', 'relative path');
 		});
 
 		test('number as logDest triggers an error', async function () {
-			if (!isDlvDap) this.skip();
+			if (!isDlvDap || process.platform === 'win32') this.skip();
 			await testWithInvalidLogDest(3, 'file descriptor');
 		});
 	});