thqby / vscode-autohotkey2-lsp

Autohotkey v2 Language Support using vscode-lsp.
https://marketplace.visualstudio.com/items?itemName=thqby.vscode-autohotkey2-lsp
GNU Lesser General Public License v3.0
210 stars 21 forks source link

TypeError: Cannot read properties of undefined (reading 'push') - 2.3.3-2.3.5 #487

Closed marium0505 closed 6 months ago

marium0505 commented 6 months ago

Recently I have kept getting the following error from your extension: TypeError: Cannot read properties of undefined (reading 'push') at me (c:\Users\Username\.vscode\extensions\thqby.vscode-autohotkey2-lsp-2.3.5\server\dist\server.js:1:69772) at le (c:\Users\Username\.vscode\extensions\thqby.vscode-autohotkey2-lsp-2.3.5\server\dist\server.js:1:49227) at ce (c:\Users\Username\.vscode\extensions\thqby.vscode-autohotkey2-lsp-2.3.5\server\dist\server.js:1:43898) at Q (c:\Users\Username\.vscode\extensions\thqby.vscode-autohotkey2-lsp-2.3.5\server\dist\server.js:1:22545) at Ke (c:\Users\Username\.vscode\extensions\thqby.vscode-autohotkey2-lsp-2.3.5\server\dist\server.js:1:15156) at ee (c:\Users\Username\.vscode\extensions\thqby.vscode-autohotkey2-lsp-2.3.5\server\dist\server.js:1:28532) at Q (c:\Users\Username\.vscode\extensions\thqby.vscode-autohotkey2-lsp-2.3.5\server\dist\server.js:1:23110) at Ke (c:\Users\Username\.vscode\extensions\thqby.vscode-autohotkey2-lsp-2.3.5\server\dist\server.js:1:15156) at e.uri.match.parseScript (c:\Users\Username\.vscode\extensions\thqby.vscode-autohotkey2-lsp-2.3.5\server\dist\server.js:1:112810) at $ (c:\Users\Username\.vscode\extensions\thqby.vscode-autohotkey2-lsp-2.3.5\server\dist\server.js:1:125800)

Running Windows 10 22H2.

It wasn't an issue until recently, so I rolled the extension back a few times, and seems like it started with version 2.3.3 (it was also on the latest version, 2.3.5). Rolling back to v2.3.2 removed the issue.

From what I have observed, the issue doesn't completely break the extension but affects certain parts of it. For instance code in included files wasn't recognized. Consequently, when using a class from those files, the extension would report an error indicating that the class variables are unset.

thqby commented 6 months ago

Is there any code to reproduce the issue?

GroggyOtter commented 6 months ago

I've been getting lots of these textDocument/completion failed messages.
Just got one 2 seconds ago.

Error message:

[Error - 6:47:27 AM] Request textDocument/completion failed. Message: Request textDocument/completion failed with message: Cannot read properties of undefined (reading 'filter') Code: -32603

Code:

WinMove(x, y, w, h, 'ahk_id')

Typing ahk_id is what throws the error.

Video: https://i.imgur.com/mH74IBI.mp4

This has happened multiple times before.

thqby commented 6 months ago

WinMove(x, y, w, h, 'ahk_id')

Typing ahk_id is what throws the error.

Because the corresponding fields are missing in the ahk2.json file. At present, some texts completions have been classified according to usage scenarios.

https://github.com/thqby/vscode-autohotkey2-lsp/blob/main/syntaxes/ahk2.json#L383-L406

marium0505 commented 6 months ago

Is there any code to reproduce the issue?

Unfortunately I wasn't able to understand a pattern before I went ahead and rolled back the extension. It occurred for some files, and not at all for others. I've updated to latest again now that I know which version to rollback to if needed, will share if I find anything.

But the error could often be pop up even without any code at all in the script.

GroggyOtter commented 6 months ago

WinMove(x, y, w, h, 'ahk_id') Typing ahk_id is what throws the error.

Because the corresponding fields are missing in the ahk2.json file. At present, some texts completions have been classified according to usage scenarios.

https://github.com/thqby/vscode-autohotkey2-lsp/blob/main/syntaxes/ahk2.json#L383-L406

I didn't realize you made massive changes to the ahk2.json file. Do you post changelogs anywhere so I don't have to diff check my definition files every update?

Also, why were variables removed instead of being relocated to their own section in the JSON file? Are those definitions hosted elsewhere now?

Another question:
What are they "syntax" properties that have been added in place of most "prefix" tags?
I understand "body" is what gets inserted when the selection is made and "description" is what gets displayed in the tooltip.
What are "prefix" and "syntax" used for?

Last questions: Is there a way to make a blank entry in a body's selection syntax?
Example: If I wanted to make 3 options to choose from (blank, 0, and 1) is there a way to make a selection not insert anything? Providing no characters before a comma doesn't work. $1{|,0,1|} The lack of anything before the first comma causes this to not work.
$1{| ,0,1|} Adding a space before the comma works, but also forces a space to be inserted.

Thanks.

thqby commented 6 months ago

This change is not mentioned in the change log.

The code was refactored in commit https://github.com/thqby/vscode-autohotkey2-lsp/commit/6052285b9e6866bab7e8625e539602579ad56ef6

variables fields in JSON files can still be used. The variables are currently merged into the ahk2.d.ahk file and have added type annotations. image

prefix is used as a label for input and display, syntax is used for hover prompts. image

Is there a way to make a blank entry in a body's selection syntax?

I don't know.

In addition, the string completion in the parameter is now extracted from the type annotation. image

GroggyOtter commented 6 months ago

@thqby That's some really good information and answered a lot of my questions. Thank you for the reply.

marium0505 commented 5 months ago

@thqby Thanks, I haven't had the issue since I installed the version with the fix you implemented. :)