vscode#FileDeleteEvent TypeScript Examples

The following examples show how to use vscode#FileDeleteEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DoUpdateCache.ts    From vscode-alxmldocumentation with MIT License 5 votes vote down vote up
constructor() {
        const subscriptions: Disposable[] = []; 
        var changeTimeout: NodeJS.Timeout | null;
        var cancellation: { cancel: (reason?: any) => void, token: CancellationToken } | null = null;
        
        workspace.onDidDeleteFiles(async (event: FileDeleteEvent) => {
            event.files.forEach(fileUri => {
                ALObjectCache.ALObjects.filter(alObject => (alObject.Uri === fileUri)).forEach(alObject => {
                    ALObjectCache.ALObjects.splice(ALObjectCache.ALObjects.indexOf(alObject), 1); // remove object from cache
                });
            });
        });

        workspace.onDidChangeTextDocument(async (event: TextDocumentChangeEvent) => {
            if ((!event.document) || (event.document.languageId !== 'al')) {
                return;
            }

            if (event.contentChanges.length === 0) {
                return;
            }

            // clear timer to avoid update AL object cache while typing
            if (changeTimeout !== null) {
                clearTimeout(changeTimeout);
            }

            // send cancellation request to previously started process
            if (cancellation !== null) {
                cancellation.cancel();
            }
    
            // create cancellation token
            cancellation = CancellationToken.create();

            // avoid starting update AL object cache while typing
            changeTimeout = setInterval(function(token: CancellationToken) {
                if (changeTimeout !== null) {
                    clearTimeout(changeTimeout);
                }
                changeTimeout = null;

                ALSyntaxUtil.ClearALObjectFromCache(event.document);
                ALSyntaxUtil.GetALObject(event.document, token);
            }, 500, cancellation.token);
        }, this, subscriptions);
        
        this.disposable = Disposable.from(...subscriptions);
    }