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

Option to automatically switch language extension after opening a v1 file #214

Closed Lexikos closed 1 year ago

Lexikos commented 1 year ago

I have created (but not published) a proof-of-concept extension which automatically selects between the installed v1 (ahk) and v2 (ahk2) language extensions when a file is opened in the editor. I found that your extension is reasonably good at detecting when a file is for v1, so my extension monitors for the diagnostic emitted by your extension. It seems to work quite well, and would automatically benefit if you happen to make any improvements to detection of v1 scripts.

Would you consider making this a feature of your extension, perhaps optional, enabled by default if a v1 extension is present?

Your extension already detects #Requires AutoHotkey v1.1 or something like #NoEnv or MsgBox,. If the feature is enabled, instead of emitting a diagnostic, it would switch the language extension in use for the file by calling setTextDocumentLanguage.

thqby commented 1 year ago

I have considered automatically switching to the v1 extension, but sometimes I may mistype to trigger unnecessary switching. Or check and switch only once when you open the file.

RaptorX commented 1 year ago

As of yet I would regard your extension as doing an outstanding job of detecting v1 scripts. Haven't got false detections that I remember.

Even when not using the requires directive. It has been pretty reliable.

One time check at file open might be a good idea.

I was thinking of making the same suggestion of switching to the default v1 extension if possible, but thought it might be harder than what I would have expected and is better to let you work on fixing the little details the extension has instead of jumping in to a potentially complex feature.

I would definitely be on board with switching to the default v1 extension automatically by default with a preferences option to disable it if not wanted.

Lexikos commented 1 year ago

check and switch only once when you open the file.

I was thinking the same. Typing code into a v2 file shouldn't trigger a switch, although pasting code into a new file might be different.

There are a couple of other cases that are currently just treated as errors but might be more useful to flag as v1 (if found in a file that is newly being opened); e.g.

fn1(ByRef a) {
}
fn2(a=1) {
}
x::
MsgBox without braces
return

The launcher detects these cases. I didn't think it was worth replicating it all with JavaScript's version of regex while also avoiding false positives, but since your extension already detects these conditions, it should be easier.

thqby commented 1 year ago
a = 1
loop % a
  msgbox
loop, 1
  msgbox

This is also the feature of v1.