|
4 | 4 |
|
5 | 5 | import assert from 'node:assert/strict'
|
6 | 6 | import {spawn} from 'node:child_process'
|
| 7 | +import process from 'node:process' |
7 | 8 | import fs from 'node:fs/promises'
|
8 | 9 | import {afterEach, test} from 'node:test'
|
9 | 10 | import {fileURLToPath} from 'node:url'
|
@@ -773,23 +774,35 @@ function cleanStack(stack, max) {
|
773 | 774 | *
|
774 | 775 | * @param {string} serverFilePath The path to the language server relative to
|
775 | 776 | * this test file.
|
776 |
| - * @param cwd The cwd to use for the process relative to this test file. |
| 777 | + * @param relativeCwd The cwd to use for the process relative to this test file. |
777 | 778 | */
|
778 |
| -function startLanguageServer(serverFilePath, cwd = './') { |
779 |
| - const proc = spawn( |
780 |
| - 'node', |
781 |
| - [fileURLToPath(new URL(serverFilePath, import.meta.url)), '--node-ipc'], |
782 |
| - { |
783 |
| - cwd: new URL(cwd, import.meta.url), |
| 779 | +function startLanguageServer(serverFilePath, relativeCwd = './') { |
| 780 | + const bin = fileURLToPath(new URL(serverFilePath, import.meta.url)) |
| 781 | + const cwd = new URL(relativeCwd, import.meta.url) |
| 782 | + |
| 783 | + // Using ipc is useful for debugging. This allows logging in the language |
| 784 | + // server. |
| 785 | + // Enabling this breaks code coverage |
| 786 | + // https://github.com/bcoe/c8/issues/189 |
| 787 | + if (process.argv.includes('--ipc')) { |
| 788 | + const proc = spawn('node', [bin, '--node-ipc'], { |
| 789 | + cwd, |
784 | 790 | stdio: [null, 'inherit', 'inherit', 'ipc']
|
785 |
| - } |
786 |
| - ) |
787 |
| - connection = createProtocolConnection( |
788 |
| - new IPCMessageReader(proc), |
789 |
| - new IPCMessageWriter(proc) |
790 |
| - ) |
| 791 | + }) |
| 792 | + connection = createProtocolConnection( |
| 793 | + new IPCMessageReader(proc), |
| 794 | + new IPCMessageWriter(proc) |
| 795 | + ) |
| 796 | + connection.onDispose(() => { |
| 797 | + proc.kill() |
| 798 | + }) |
| 799 | + } else { |
| 800 | + const proc = spawn('node', [bin, '--stdio'], {cwd}) |
| 801 | + connection = createProtocolConnection(proc.stdout, proc.stdin) |
| 802 | + } |
| 803 | + |
791 | 804 | connection.onDispose(() => {
|
792 |
| - proc.kill() |
| 805 | + connection.end() |
793 | 806 | })
|
794 | 807 | connection.listen()
|
795 | 808 | }
|
|
0 commit comments