loganch/AutoIt-VSCode

createRegionSymbol fails when #region contains hyphen

Danp2 opened this issue · 1 comments

Danp2 commented

With a region defined as #Region - JSON builder, the following pattern search will fail --

const result = pattern.exec(docText);

Below is the related error from attempting to read the non-existent index property --

2022-12-11 08:50:29.129 [error] [Damien.autoit] provider FAILED
2022-12-11 08:50:29.129 [error] TypeError: Cannot read properties of null (reading 'index')
	at createRegionSymbol (c:\Users\danpo\OneDrive\Documents\GitHub\AutoIt-VSCode\dist\extension.js:2153:25)
	at _loop (c:\Users\danpo\OneDrive\Documents\GitHub\AutoIt-VSCode\dist\extension.js:2243:30)
	at Object.provideDocumentSymbols (c:\Users\danpo\OneDrive\Documents\GitHub\AutoIt-VSCode\dist\extension.js:2254:18)
	at s.provideDocumentSymbols (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:96:32425)
	at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:96:57210
	at se.s (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:96:56458)
	at se.$provideDocumentSymbols (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:96:57199)
	at u.N (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:104:11208)
	at u.M (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:104:10926)
	at u.H (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:104:9981)
	at u.G (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:104:9000)
	at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:104:7788
	at d.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:145)
	at w.deliver (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:2029)
	at g.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:1667)
	at h.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:72:14314)
	at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:120:15804
	at d.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:145)
	at w.deliver (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:2029)
	at g.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:1667)
	at h.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:72:14314)
	at c.y (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:72:17324)
	at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:72:15795
	at d.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:145)
	at w.deliver (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:2029)
	at g.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:1667)
	at g.acceptChunk (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:72:12045)
	at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:72:11332
	at Socket.l (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:72:19792)
	at Socket.emit (node:events:526:28)
	at addChunk (node:internal/streams/readable:315:12)
	at readableAddChunk (node:internal/streams/readable:289:9)
	at Socket.push (node:internal/streams/readable:228:10)
	at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
	at Pipe.callbackTrampoline (node:internal/async_hooks:130:17)
Danp2 commented

Changing this line --

const pattern = new RegExp(#Region\\s(${cleanRegionName}).*?#EndRegion, 's');

to

const pattern = new RegExp(`#Region\\s[- ]{0,}(${cleanRegionName}).*?#EndRegion`, 's');

resolves the issue for me.