Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 89ab7a7

Browse files
committed
feat: check if the environment has qmlls before establish language
client Fix #266
1 parent 04b4795 commit 89ab7a7

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/qmlls/client.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import {
2020
} from 'vscode-languageclient/node'
2121
import type { URI } from 'vscode-uri'
2222
import { 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'
2525
import { getToolCommand$ } from '../tool-utils'
2626
import 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

9099
type 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

105109
function 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

Comments
 (0)