@@ -4,40 +4,29 @@ import { getTree, getTrees, queryNode, toRange, trueParent } from "./TreeSitter"
44import { DocumentSelector } from './extension' ;
55
66
7+ type IOnigBinding = {
8+ HEAPU8 : Uint8Array ;
9+ HEAPU32 : Uint32Array ;
710
8- export async function initDiagnostics ( context : vscode . ExtensionContext ) {
9- // vscode.window.showInformationMessage(JSON.stringify("initDiagnostics"));
10- // Oniguruma regex parser
11- // try {
12- const uri = vscode . Uri . joinPath ( context . extensionUri , 'node_modules' , 'vscode-oniguruma' , 'release' , 'onig.wasm' ) ;
13- const wasm = await vscode . workspace . fs . readFile ( uri ) ;
14- const options : vscodeOniguruma . IDataOptions = {
15- data : wasm ,
16- print ( string : string ) {
17- console . log ( string ) ;
18- }
19- }
20- await vscodeOniguruma . loadWASM ( options ) ;
21-
22- // } catch (error) {
23- // vscode.window.showInformationMessage(JSON.stringify(error));
24- // // https://github.com/microsoft/vscode-oniguruma/issues/10
25- // const response = await fetch('/node_modules/vscode-oniguruma/release/onig.wasm');
26- // const contentType = response.headers.get('content-type');
11+ _omalloc ( count : number ) : Pointer ;
12+ _ofree ( ptr : Pointer ) : void ;
13+ UTF8ToString ( ptr : Pointer ) : string ;
2714
28- // // Using the response directly only works if the server sets the MIME type 'application/wasm'.
29- // // Otherwise, a TypeError is thrown when using the streaming compiler.
30- // // We therefore use the non-streaming compiler :(.
31- // const wasm = contentType === 'application/wasm' ? response : await response.arrayBuffer() ;
32- // const options: vscodeOniguruma.IDataOptions = {
33- // data: wasm,
34- // print(string: string) {
35- // console.log(string);
36- // }
37- // }
38- // await vscodeOniguruma.loadWASM(options) ;
39- // }
15+ _getLastOnigError ( ) : Pointer ;
16+ _createOnigScanner ( strPtrsPtr : Pointer , strLenPtr : Pointer , count : number , options : number , syntax : Pointer ) : Pointer ;
17+ _freeOnigScanner ( ptr : Pointer ) : void ;
18+ _findNextOnigScannerMatch ( scanner : Pointer , strCacheId : number , strData : Pointer , strLength : number , position : number , options : number ) : number ;
19+ _findNextOnigScannerMatchDbg ( scanner : Pointer , strCacheId : number , strData : Pointer , strLength : number , position : number , options : number ) : number ;
20+ }
21+ type Pointer = number ;
22+ type OnigScanner = vscodeOniguruma . OnigScanner & {
23+ readonly _onigBinding : IOnigBinding ;
24+ readonly _ptr : Pointer ;
25+ readonly _options : vscodeOniguruma . FindOption [ ] ;
26+ }
4027
28+ export function initDiagnostics ( context : vscode . ExtensionContext ) {
29+ // vscode.window.showInformationMessage(JSON.stringify("initDiagnostics"));
4130 const DiagnosticCollection = vscode . languages . createDiagnosticCollection ( "textmate" ) ;
4231 context . subscriptions . push ( DiagnosticCollection ) ;
4332
@@ -223,20 +212,23 @@ function Diagnostics(document: vscode.TextDocument, Diagnostics: vscode.Diagnost
223212 // `\\3` could be valid; could be invalid. Who knows?
224213 // Would need to check the `begin` regex first for the number of capture groups
225214 // Then how to tell Oniguruma how many are available??
215+ // Keeping in mind /(?I:...)/
226216 regex = regex . replace ( / \\ [ 1 - 9 ] ( \d { 2 } ) ? (? ! \d ) / g, '\\0' ) ;
227217 }
228218
229- const string = vscodeOniguruma . createOnigString ( '' ) ; // blank. Maybe can test against a user provided string?
230- // const scanner = vscodeOniguruma.createOnigScanner([regex]);
231- const scanner = new vscodeOniguruma . OnigScanner ( [ '' , regex ] ) ;
232- const match = scanner . findNextMatchSync ( string , 0 ) ; // returns null if `regex` is invalid
219+ const scanner = new vscodeOniguruma . OnigScanner ( [ regex ] ) ;
220+
221+ const onigBinding = ( < OnigScanner > scanner ) . _onigBinding ;
222+ const errorCode = onigBinding . UTF8ToString ( onigBinding . _getLastOnigError ( ) ) ;
233223
234- // vscode.window.showInformationMessage(JSON.stringify(match));
235- if ( ! match ) {
224+ // const string = vscodeOniguruma.createOnigString(''); // blank. Maybe can test against a user provided string?
225+ // const match = scanner.findNextMatchSync(string, 0); // returns null if `regex` is invalid
226+
227+ if ( errorCode != 'undefined error code' ) {
236228 const range = toRange ( key ) ;
237229 const diagnostic : vscode . Diagnostic = {
238230 range : range ,
239- message : `Regex Failed Parse Test.` ,
231+ message : errorCode ,
240232 severity : vscode . DiagnosticSeverity . Error ,
241233 source : 'Oniguruma' ,
242234 } ;
0 commit comments