@@ -10,7 +10,9 @@ import * as vscode from 'vscode';
1010import * as lsclient from 'vscode-languageclient/node' ;
1111import * as proto from 'vscode-languageserver-protocol' ;
1212import { MemoryFileSystemProvider } from './memoryFileSystemProvider' ;
13- import { vsdiag , DiagnosticProviderMiddleware } from 'vscode-languageclient' ;
13+ import { vsdiag , DiagnosticProviderMiddleware , LanguageClient } from 'vscode-languageclient' ;
14+ import { IsDetachedRequest } from './servers/types' ;
15+ import { afterEach } from 'mocha' ;
1416
1517namespace GotNotifiedRequest {
1618 export const method : 'testing/gotNotified' = 'testing/gotNotified' ;
@@ -1961,6 +1963,58 @@ class CrashClient extends lsclient.LanguageClient {
19611963}
19621964
19631965suite ( 'Server tests' , ( ) => {
1966+ suite ( 'detached' , async function ( ) {
1967+ const detachedServerModule = path . join ( __dirname , 'servers' , 'detachedServer.js' ) ;
1968+
1969+ let client : LanguageClient | undefined ;
1970+
1971+ afterEach ( async function ( ) {
1972+ await client ?. stop ( ) ;
1973+ } ) ;
1974+
1975+ test ( 'servers are NOT detached by default' , async ( ) => {
1976+ const serverOptions : lsclient . ServerOptions = {
1977+ module : detachedServerModule ,
1978+ transport : lsclient . TransportKind . ipc ,
1979+ } ;
1980+ const client = new lsclient . LanguageClient ( 'test svr' , serverOptions , { } ) ;
1981+ const res = await client . sendRequest ( IsDetachedRequest ) ;
1982+ assert . strictEqual ( res , false ) ;
1983+ } ) ;
1984+
1985+ [ lsclient . TransportKind . stdio , lsclient . TransportKind . ipc , lsclient . TransportKind . pipe ] . forEach ( ( transport ) => {
1986+ test ( `server detects it is detached using Node ServerOptions when transport: ${ transport } ` , async ( ) => {
1987+ const serverOptions : lsclient . ServerOptions = {
1988+ module : detachedServerModule ,
1989+ transport,
1990+ options : {
1991+ detached : true
1992+ }
1993+ } ;
1994+ const client = new lsclient . LanguageClient ( 'test svr' , serverOptions , { } ) ;
1995+ const res = await client . sendRequest ( IsDetachedRequest ) ;
1996+ assert . strictEqual ( res , true ) ;
1997+ } ) ;
1998+ } ) ;
1999+
2000+ [ lsclient . TransportKind . stdio , lsclient . TransportKind . pipe ] . forEach ( ( transport ) => {
2001+ test ( `server detects it is detached using Executable ServerOptions when transport: ${ transport } ` , async ( ) => {
2002+ const serverOptions : lsclient . ServerOptions = {
2003+ command : 'node' , // making assumption this exists in the PATH of the test environment
2004+ args : [ detachedServerModule ] ,
2005+ transport,
2006+ options : {
2007+ detached : true
2008+ }
2009+ } ;
2010+ const client = new lsclient . LanguageClient ( 'test svr' , serverOptions , { } ) ;
2011+ const res = await client . sendRequest ( IsDetachedRequest ) ;
2012+ assert . strictEqual ( res , true ) ;
2013+ } ) ;
2014+ } ) ;
2015+
2016+ } ) ;
2017+
19642018 test ( 'Stop fails if server crashes after shutdown request' , async ( ) => {
19652019 const serverOptions : lsclient . ServerOptions = {
19662020 module : path . join ( __dirname , './servers/crashOnShutdownServer.js' ) ,
0 commit comments