@@ -20,8 +20,8 @@ import {
2020} from 'vscode-languageclient/node'
2121import type { URI } from 'vscode-uri'
2222import { getEnabledFromConfig$ } from '../configurations'
23- import type { CommandArgs } from '../run'
24- import { wrapAndJoinCommandArgsWithQuotes } from '../run'
23+ import type { CommandArgs , ExecError , StdErrError } from '../run'
24+ import { run , wrapAndJoinCommandArgsWithQuotes } from '../run'
2525import { getToolCommand$ } from '../tool-utils'
2626import type { ErrorResult , SuccessResult } from '../types'
2727
@@ -36,6 +36,15 @@ export function registerQmlLanguageServer$({
3636 resource : undefined ,
3737 extensionUri,
3838 } ) . pipe (
39+ concatMap ( result => {
40+ if ( result . kind !== 'Success' ) return of ( result )
41+
42+ return defer ( async ( ) => {
43+ const checkResult = await checkQmllsExists ( result . value . command )
44+ if ( checkResult . kind !== 'Success' ) return checkResult
45+ return result
46+ } )
47+ } ) ,
3948 concatMap ( result => {
4049 if ( result . kind !== 'Success' ) return of ( result )
4150
@@ -89,17 +98,12 @@ type RegisterQmlLanguageServerArgs = {
8998
9099type RegisterQmlLanguageServerResult =
91100 | ErrorResult < 'NotFound' >
101+ | ExecError
102+ | StdErrError
92103 | SuccessResult < string >
93104
94- // TODO: Unit test this behavior.
95- function stopPreviousClient ( ) {
96- return ( source$ : Observable < LanguageClient | undefined > ) =>
97- source$ . pipe (
98- startWith ( undefined ) ,
99- pairwise ( ) ,
100- concatMap ( async ( [ previous ] ) => previous ?. dispose ( ) ) ,
101- concatMap ( ( ) => source$ ) ,
102- )
105+ async function checkQmllsExists ( command : CommandArgs ) {
106+ return run ( { command : [ ...command , '--help' ] } )
103107}
104108
105109function createClient ( { command, options, outputChannel } : CreateClientArgs ) {
@@ -129,3 +133,14 @@ type CreateClientArgs = {
129133 readonly options : CommandArgs
130134 readonly outputChannel : OutputChannel
131135}
136+
137+ // TODO: Unit test this behavior.
138+ function stopPreviousClient ( ) {
139+ return ( source$ : Observable < LanguageClient | undefined > ) = >
140+ source$ . pipe (
141+ startWith ( undefined ) ,
142+ pairwise ( ) ,
143+ concatMap ( async ( [ previous ] ) => previous ?. dispose ( ) ) ,
144+ concatMap ( ( ) => source$ ) ,
145+ )
146+ }
0 commit comments