Skip to content

Commit daf8c6a

Browse files
committed
fix: only watch document text changes, no active editor changes listening
1 parent 882e4a9 commit daf8c6a

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

src/composables/workspace-context.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { SUPPORTED_DOCUMENT_PATTERN } from '#constants'
33
import { logger } from '#state'
44
import { isSupportedDependencyDocument } from '#utils/file'
55
import { getWorkspaceContext } from '#utils/workspace'
6-
import { useActiveTextEditor, useDocumentText, useFileSystemWatcher, watch } from 'reactive-vscode'
7-
import { workspace } from 'vscode'
6+
import { useDisposable, useFileSystemWatcher } from 'reactive-vscode'
7+
import { window, workspace } from 'vscode'
88

99
export function useWorkspaceContext() {
1010
workspace.onDidChangeWorkspaceFolders(({ removed }) => {
@@ -15,6 +15,9 @@ export function useWorkspaceContext() {
1515
})
1616

1717
async function deleteCacheByUri(uri: Uri) {
18+
if (!isSupportedDependencyDocument(uri))
19+
return
20+
1821
const ctx = await getWorkspaceContext(uri)
1922
if (!ctx)
2023
return
@@ -24,16 +27,12 @@ export function useWorkspaceContext() {
2427
logger.info(`[workspace-context] delete cache: ${uri.path}`)
2528
}
2629

27-
const activeEditor = useActiveTextEditor()
28-
const activeDocumentText = useDocumentText(() => activeEditor.value?.document)
29-
30-
watch(activeDocumentText, async () => {
31-
const document = activeEditor.value?.document
32-
if (!document || !isSupportedDependencyDocument(document))
30+
useDisposable(workspace.onDidChangeTextDocument(({ document }) => {
31+
if (document !== window.activeTextEditor?.document)
3332
return
3433

3534
deleteCacheByUri(document.uri)
36-
}, { flush: 'pre' })
35+
}))
3736

3837
const { onDidChange, onDidDelete } = useFileSystemWatcher(SUPPORTED_DOCUMENT_PATTERN)
3938

src/utils/workspace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class WorkspaceContext {
9393

9494
return {
9595
...info,
96-
dependencies: info.dependencies.map(this.#createResolvedDependencyInfo),
96+
dependencies: info.dependencies.map(dep => this.#createResolvedDependencyInfo(dep)),
9797
}
9898
}, this.#memoizeOptions)
9999

@@ -118,7 +118,7 @@ class WorkspaceContext {
118118

119119
return {
120120
...info,
121-
dependencies: info.dependencies.map(this.#createResolvedDependencyInfo),
121+
dependencies: info.dependencies.map(dep => this.#createResolvedDependencyInfo(dep)),
122122
}
123123
}, this.#memoizeOptions)
124124
}

0 commit comments

Comments
 (0)