From 328cf1494b90f7a44dce2cfc9fc090325fa62cb2 Mon Sep 17 00:00:00 2001 From: sslinky Date: Fri, 27 Sep 2024 16:12:23 +0800 Subject: [PATCH 1/4] Function now has default return type to prevent parser error --- snippets/vba.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/vba.json b/snippets/vba.json index 5517788..61f5556 100644 --- a/snippets/vba.json +++ b/snippets/vba.json @@ -69,7 +69,7 @@ "prefix": "func", "description": "Function", "body": [ - "${1:Public }Function ${2:Identifier}($3) As $4", + "${1:Public }Function ${2:Identifier}($3) As ${4:Variant}", "Attribute $2.VB_Description = \"${5:Dosctring}.\"", "' $5.", "'", From 4053dcae40ad7932259dc59d82d28849444690c6 Mon Sep 17 00:00:00 2001 From: sslinky Date: Fri, 27 Sep 2024 16:17:29 +0800 Subject: [PATCH 2/4] Added async cancellation support. --- server/src/project/document.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/src/project/document.ts b/server/src/project/document.ts index f59be68..5db51a4 100644 --- a/server/src/project/document.ts +++ b/server/src/project/document.ts @@ -6,6 +6,7 @@ import { Range, TextDocument } from 'vscode-languageserver-textdocument'; import { SyntaxParser } from './parser/vbaSyntaxParser'; import { FoldingRange } from '../capabilities/folding'; import { SemanticTokensManager } from '../capabilities/semanticTokens'; +import { ParseCancellationException } from 'antlr4ng'; export interface DocumentSettings { maxDocumentLines: number; @@ -134,13 +135,28 @@ export abstract class BaseProjectDocument { } async parseAsync(token: CancellationToken): Promise { + // Handle already cancelled. + if (token.isCancellationRequested) { + throw new ParseCancellationException(Error('Parse operation cancelled before it started.')); + } + + // Listen for cancellation event. + token.onCancellationRequested(() => { + throw new ParseCancellationException(new Error('Parse operation cancelled during parse.')); + }) + + // Don't parse oversize documents. if (await this.isOversize) { console.log(`Document oversize: ${this.textDocument.lineCount} lines.`); console.warn(`Syntax parsing has been disabled to prevent crashing.`); this._isBusy = false; return; } + + // Parse the document. await (new SyntaxParser()).parseAsync(this, token) + + // Evaluate the diagnostics. this._hasDiagnosticElements.forEach(element => { element.evaluateDiagnostics; this._diagnostics.concat(element.diagnostics); From 03066e4016037d51d71d7140f9eb3d675643d2ab Mon Sep 17 00:00:00 2001 From: sslinky Date: Fri, 27 Sep 2024 16:17:55 +0800 Subject: [PATCH 3/4] Ignore exceptions from parser --- server/src/project/workspace.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/src/project/workspace.ts b/server/src/project/workspace.ts index 022c2fb..6ad75eb 100644 --- a/server/src/project/workspace.ts +++ b/server/src/project/workspace.ts @@ -48,7 +48,14 @@ export class Workspace { this.activateDocument(document); this._parseCancellationTokenSource?.cancel(); this._parseCancellationTokenSource = new CancellationTokenSource(); - await this._activeDocument?.parseAsync(this._parseCancellationTokenSource.token); + + // Exceptions thrown by the parser should be ignored. + try { + await this._activeDocument?.parseAsync(this._parseCancellationTokenSource.token); + } catch (error) { + this.connection.console.log(`Parser error: ${error}`) + } + this._parseCancellationTokenSource = undefined; this.connection.sendDiagnostics(this._activeDocument?.languageServerDiagnostics() ?? {uri: "", diagnostics: []}); } From 049ddacfb0e9bc5301c5235626934a7ffeadba95 Mon Sep 17 00:00:00 2001 From: sslinky Date: Fri, 27 Sep 2024 16:19:49 +0800 Subject: [PATCH 4/4] 1.4.4 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index d210ac9..ba9a93a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vba-lsp", - "version": "1.4.3", + "version": "1.4.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vba-lsp", - "version": "1.4.3", + "version": "1.4.4", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 8e4010b..b0a0ac4 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "icon": "images/vba-lsp-icon.png", "author": "SSlinky", "license": "MIT", - "version": "1.4.3", + "version": "1.4.4", "repository": { "type": "git", "url": "https://github.com/SSlinky/VBA-LanguageServer"