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

Commit b822c4e

Browse files
committed
fix: restart qmlls client if the configurations are changed
1 parent ad3db49 commit b822c4e

File tree

2 files changed

+50
-49
lines changed

2 files changed

+50
-49
lines changed

src/qmlls/client.ts

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Observable } from 'rxjs'
22
import {
3+
combineLatest,
34
concatMap,
45
defer,
56
of,
@@ -22,6 +23,7 @@ import type { URI } from 'vscode-uri'
2223
import { getEnabledFromConfig$ } from '../configurations'
2324
import type { CommandArgs } from '../run'
2425
import { run, wrapAndJoinCommandArgsWithQuotes } from '../run'
26+
import type { ToolCommand } from '../tool-utils'
2527
import { getToolCommand$ } from '../tool-utils'
2628

2729
export function registerQmlLanguageServer$({
@@ -30,62 +32,61 @@ export function registerQmlLanguageServer$({
3032
}: RegisterQmlLanguageServerArgs) {
3133
const client$ = new ReplaySubject<LanguageClient | undefined>(1)
3234

33-
const createClient$ = getToolCommand$({
34-
tool: 'qmlls',
35-
resource: undefined,
36-
extensionUri,
37-
}).pipe(
38-
concatMap(result => {
39-
if (result.kind !== 'Success') return of(result)
35+
const createClient$ = (toolCommand: ToolCommand) =>
36+
using(
37+
() => {
38+
const client = createClient({
39+
command: toolCommand.command,
40+
options: toolCommand.options,
41+
outputChannel,
42+
})
43+
client$.next(client)
4044

41-
return defer(async () => {
42-
const checkResult = await checkQmllsExists(result.value.command)
43-
if (checkResult.kind !== 'Success') return checkResult
44-
return result
45-
})
46-
}),
47-
concatMap(result => {
48-
if (result.kind !== 'Success') return of(result)
45+
return { unsubscribe: () => client.dispose() }
46+
},
47+
() =>
48+
client$.pipe(
49+
stopPreviousClient(),
50+
concatMap(client =>
51+
defer(async () => {
52+
await client?.start()
53+
return {
54+
kind: 'Success',
55+
value: `qmlls is running with the command: '${wrapAndJoinCommandArgsWithQuotes(
56+
[...toolCommand.command, ...toolCommand.options],
57+
)}'`,
58+
} as const
59+
}),
60+
),
61+
),
62+
)
4963

50-
return using(
51-
() => {
52-
const client = createClient({
53-
command: result.value.command,
54-
options: result.value.options,
55-
outputChannel,
56-
})
57-
client$.next(client)
64+
const createClientIfQmllsExists$ = (toolCommand: ToolCommand) =>
65+
defer(async () => checkQmllsExists(toolCommand.command)).pipe(
66+
concatMap(checkResult => {
67+
if (checkResult.kind !== 'Success') return of(checkResult)
68+
return createClient$(toolCommand)
69+
}),
70+
)
5871

59-
return { unsubscribe: () => client.dispose() }
60-
},
61-
() =>
62-
client$.pipe(
63-
stopPreviousClient(),
64-
concatMap(client =>
65-
defer(async () => {
66-
await client?.start()
67-
return {
68-
kind: 'Success',
69-
value: `qmlls is running with the command: '${wrapAndJoinCommandArgsWithQuotes(
70-
[...result.value.command, ...result.value.options],
71-
)}'`,
72-
} as const
73-
}),
74-
),
75-
),
76-
)
72+
return combineLatest([
73+
getEnabledFromConfig$({ tool: 'qmlls', resource: undefined }),
74+
getToolCommand$({
75+
tool: 'qmlls',
76+
resource: undefined,
77+
extensionUri,
7778
}),
78-
)
79-
80-
return getEnabledFromConfig$({ tool: 'qmlls', resource: undefined }).pipe(
81-
switchMap(enabled => {
79+
]).pipe(
80+
switchMap(([enabled, result]) => {
8281
if (!enabled)
8382
return defer(async () => {
8483
client$.next(undefined)
8584
return { kind: 'Success', value: 'qmlls has been stopped' } as const
8685
})
8786

88-
return createClient$
87+
if (result.kind !== 'Success') return of(result)
88+
89+
return createClientIfQmllsExists$(result.value)
8990
}),
9091
)
9192
}

src/tool-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Observable } from 'rxjs'
2-
import { combineLatest, concatMap, defer, iif, map, of } from 'rxjs'
2+
import { combineLatest, defer, iif, map, of, switchMap } from 'rxjs'
33
import type { URI } from 'vscode-uri'
44
import { getOptionsFromConfig$, getPathFromConfig$ } from './configurations'
55
import { resolveScriptCommand$ } from './python'
@@ -17,7 +17,7 @@ export function getToolCommand$({
1717
getOptionsFromConfig$({ tool, resource }),
1818
]),
1919
).pipe(
20-
concatMap(([path, options]) =>
20+
switchMap(([path, options]) =>
2121
iif(
2222
() => path.length > 0,
2323

@@ -51,7 +51,7 @@ export type GetToolCommandResult =
5151
| SuccessResult<ToolCommand>
5252
| ErrorResult<'NotFound'>
5353

54-
type ToolCommand = {
54+
export type ToolCommand = {
5555
readonly command: CommandArgs
5656
readonly options: CommandArgs
5757
}

0 commit comments

Comments
 (0)