Serpen / VBS-VSCode

VSCode VBScript language extension
https://marketplace.visualstudio.com/items?itemName=Serpen.vbsvscode
MIT License
24 stars 11 forks source link

Introduce Pseudo Type System? #16

Open Serpen opened 3 years ago

Serpen commented 3 years ago

VBS has no type System, however sometimes it is well known what a function or variable holds.

I use this syntax on my own: Dim str ' as String ' Comment

Maybe such a comment based As Type approach could be used to fake a typesystem like typescript is doing it for javascript. However the comments have to be parsed stricter and an comment like dim refObject ' as already used above whould create and return type of already

Benik3 commented 3 years ago

Maybe using something like String_t (similar from C and his uint16_t etc.).
The parser can then match first world toward list of types and ideally remove the _t.

Serpen commented 3 years ago

Maybe using something like String_t (similar from C and his uint16_t etc.). The parser can then match first world toward list of types and ideally remove the _t.

Hm, i don't think that would be very intuitive to any VB developer, but it would indeed prevent from accidentally using normal comments as type

Serpen commented 3 years ago

Thinking the damage cause by accidentally used comments as Types is insignificant.

The ' as Type, sounds familiar to a VB developer and would work for

Don't work

For those things the idea won't work:

Function/Sub Parameters

Function myFunc(p1 ' as String, p2 ' As Integer Maybe this isn't bad, because there is no benefit beyond documentation purpose Splitting the Function into multiple lines and comment each parameter would be idea, but I think there is no valid syntax for that?? If the extension grows so far the a error checking is doing a strict type check, like typescript for javascript, this could become useful. An alternative approach would be to use xml comments for those ''' <param name="p1" type="string">Description</param

Function with different return types

CreateObject or GetObject could not use this typesystem. But the developer could declare a variable which states the awaited type dim fso ' as Scripting.FilesystemObject. But i think in this case the string in createobject should be the type

Set/Let Property

The parameter has the same problem like in subs/functions, but it could be inconsequentially be used as Property Let Text(val) ' as String

Enums

Enums aren't supported by VBS, but they would be helpful for many parameters like MsgBox Constants or String Compare Options.

Have no good idea, and don't like any approach:

' Enum MsgBoxContantCom = Array(vbOK, vbYesNo)

Const Enum_MsgBoxConstants = "vbOK, vbYesNo"

dim MsgBoxConstantsVar : MsgBoxConstantsVar = Array(vbOK, vbYesNo) ' as Enum

Class Enum_MsgBoxConstants
    Public vbOK
    Public vbYesNo
End Class

Function Enum_MsgBoxConstantsFunc() ' As Enum
    Enum_MsgBoxConstantsFunc = Array(vbOK, vbYesNo)
End Function
Benik3 commented 3 years ago

For the functions I think that using ''' <param name="p1" type="string">Description</param> is pretty OK. Even write the type directly in to the description. I would not overcomplicate this :)