Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Linter Context for MV Subroutines and Functions #113

Closed
brentlblair opened this issue Jun 23, 2020 · 8 comments
Closed

[FEATURE] Linter Context for MV Subroutines and Functions #113

brentlblair opened this issue Jun 23, 2020 · 8 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@brentlblair
Copy link
Contributor

I know the linter has custom text for jBase VERBS that shows how to use the VERB. I would like to enhance this by being able to describe SOME frequently used Subroutines and Functions from my system possibly using the MVBasic settings file in json format.

Something like this could be added to the MVBasic settings:

"MVBasic.CustomFunctions":[
  {
    "Name":"DateTimeFormat",
    "Values":"inDate,inTime,'format'",
    "Notes":"Format internal data and or time in custom external format|You must have INCLUDE BP CustomLibrary in any program that refreences this function|inDate=date in internal format - can be null if you do not need to convert date|inTime=time in internal format - can be null if you do not need to convert time|format=string using any combination of the follow characters, undefinded characters will be used as literals"
  }
],

The above code would auto complete the following in VS Code:
DateTimeFormat(inDate,inTime,'format')

It would also display the following hover / help text (I used a | to indicate a new line:

Format internal data and or time in custom external format
You must have INCLUDE BP CustomLibrary in any program that refreences this function
inDate=date in internal format - can be null if you do not need to convert date
inTime=time in internal format - can be null if you do not need to convert time
format=string using any combination of the follow characters, undefinded characters will be used as literals

Please let me know if this makes sense of if you have any questions.

@ianmcgowan
Copy link
Contributor

Brent, this seems like an excellent candidate for "User Snippets". I have the following in mine, as well as common things like OPEN, READ, WRITE, defined the way I like them. When I type SUB, hit Ctrl-Space for complete, and choose the SUB snippet, I can tab through the various completions to fill in $1, $2, etc in the snippet body.

Snippet

{
  "SUBROUTINE Skeleton": {
    "prefix": "SUB",
    "body": [
      "SUBROUTINE $1($2)",
      "***************************************************************************",
      "* Program: $1",
      "* Author : Ian McGowan",
      "* Created: ${3:$CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE}",
      "* Updated: $3",
      "* Comment: $4",
      "***************************************************************************",
      "*",
      "$0"
    ],
    "description": "The UniBasic SUBROUTINE command determines the beginning of an external subroutine"
  },
  "PROGRAM Skeleton": {
    "prefix": "PROG",
    "body": [
      "***************************************************************************",
      "* Program: $1",
      "* Author : Ian McGowan",
      "* Created: ${2:$CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE}
      "* Updated: $2",
      "* Comment: $3",
      "***************************************************************************",
      "*",
      "$0"
    ],
    "description": "The UniBasic PROGRAM command determines the beginning of a program"
  },
}

@dthiot
Copy link
Contributor

dthiot commented Jun 24, 2020 via email

@brentlblair
Copy link
Contributor Author

brentlblair commented Jun 24, 2020 via email

@ianmcgowan
Copy link
Contributor

To be technically correct (the best kind!) "Linting" is different from "Intellisense", both are managed in https://github.com/mvextensions/mvbasic/blob/master/server/src/server.ts, in loadIntelliSense and validateTextDocument functions.

There is an option for a custom word list in server.ts/loadIntelliSense, but it's far from the "autocomplete" option you're looking for - if you specify a filename with a bunch of words in it, optionally wrapped in double quotes, it will color code those words.

It's a good suggestion to have a "custom intellisense list" parameter that did something similar, where you provide your own syntax file (perhaps from a central file share as you suggested) and it gets merged with the system provided one.  But absent that, you should be able to modify the appropriate Language.json file in the Syntaxes folder and add your own syntax definitions.  Sadly that will be lost every time the extension updates though.

The user snippet option does show some help when completing (and snippets autocomplete just like the built in intellisense), but it sounds like that's not centrally managed enough for your situation, plus it looks kinda sucky if you have a lot of description:

image

@itsxallwater itsxallwater added enhancement New feature or request help wanted Extra attention is needed labels Aug 11, 2020
@itsxallwater
Copy link
Member

@brentlblair here's how I would approach this:

  • Take a look at the Language definition file for jBASE
    • To extend the language definition we'll need to allow the extension to ingest JSON records that resemble the contents of this file--specifically, this array:
{
  "key": "$Include",
  "icon": 14,
  "index": 1,
  "documentation": "The $INCLUDE or $INSERT directive inserts the program/code snippet specified into the current source code.\r\nIf the optional filename is specified the code is read from that file.",
  "detail": "$INCLUDE programname\r\n$INCLUDE filename programname\r\n$INSERT programname\r\n$INSERT filename programname"
}
  • The root package.json file has a section called configuration that will need to be extended to create the entry point for this custom JSON. You can look at the existing customWordPath setting which asks the user to specify a file to load from disk with the definition.
  • The language server code at server.ts has a loadIntellisense function that takes care to interpret the languageType setting for the extension and load the appropriate file in, so this is the section we'd want to tack on any custom definition as well.

@brentlblair
Copy link
Contributor Author

I have the functions autocomplete working now.
Code_0ZkcLh1XjP
I also changed it to use key along with insertText which will allow me to type 'DateTimeFormat' and autocomplete
"DateTimeFormat(internalDate,internalTime,'formatString')"
This also tells Intellisense that the hover word is 'DateTimeFormat' and will continue to show documentation even after you change the function vars in the code.
Do I need to do a pull request to get my changes ready for production?

@itsxallwater
Copy link
Member

A PR would be great, against the develop branch specifically as we aggregate changes there prior to releasing.

If you could include relevant doc updates for this new feature that'd be excellent as well. Nice work!!!

@itsxallwater itsxallwater added this to the v2.0.9 milestone Aug 25, 2020
@itsxallwater
Copy link
Member

2.0.9 released! Closing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants