@@ -3,8 +3,8 @@ import { SUPPORTED_DOCUMENT_PATTERN } from '#constants'
33import { logger } from '#state'
44import { isSupportedDependencyDocument } from '#utils/file'
55import { 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
99export 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
0 commit comments