Giter Club home page Giter Club logo

Comments (8)

stevenguh avatar stevenguh commented on July 3, 2024 1

Kind of just jotting here. Apparently, we can add the (limited) schema into package.json so there is a prompt of possible value when people edit the settings.json
For example:

"whichkey.bindings": {
    "type": "array",
    "items": {
        "type": "object",
        "title": "Binding",
        "properties": {
            "key": {
                "type": "string",
                "description": "Key of this binding in this level"
            },
            "name": {
                "type": "string",
                "description": "The display name of this binding"
            },
            "type": {
                "type": "string",
                "enum": ["command", "commands", "transient", "conditional"],
                "description": "The type of this binding"
            }
        }
    },
    "markdownDescription": "The bindings of the which key menu",
    "default": []
}

Maybe the hack mentioned in microsoft/vscode#95270 (comment) can bypass the limited functionality. Also maybe be able to reuse across extensions like VSpaceCode and which-key

from vscode-which-key.

stevenguh avatar stevenguh commented on July 3, 2024

Just jotting notes here. Thinking we can use JSON Schema with https://ajv.js.org. To handle requirements of different requirement of properties on the type name, we can use the if/then/else as described in https://json-schema.org/understanding-json-schema/reference/conditionals.html and https://ajv.js.org/keywords.html#ifthenelse

And we can use https://github.com/adobe/jsonschema2md to generate documentations

from vscode-which-key.

MarcoIeni avatar MarcoIeni commented on July 3, 2024

I've used json schema before. I could write the schema if you want.

Tell me:

  • the file(s) to be validated
  • where to place the schema file

from vscode-which-key.

stevenguh avatar stevenguh commented on July 3, 2024

Thank you for helping, it would be great if you can help as I am going to be busy in the next few weeks. The schemas are used to validate the bindings and bindingOverrides.

Thebindings contains an array of BindingItem(s).

BindingItem

key value
key required string
name required string
type required enum string (command, commands, bindings and transient)
command required string if type == command | (optional if type == transient && only if commands is not exists)
commands required array of strings if type == commands | (optional if type == transient && only if command is not exists)
args optional any object | array of objects if type == commands
bindings Array of BindingItem(s), required if type == bindings

The bindingOverrides contains an array of OverrideBindingItem(s).

OverrideBindingItem

key value
keys required (string | array of string)
position optional number
name optional string if keys is negative else required
type optional enum string as in BindingItem if keys is negative else required
command Same as BindingItem
commands Same as BindingItem
args Same as BindingItem
bindings Same as BindingItem

Can you put the schemas in src/scemas in a new branch? Then I can use the schema to validate finish this out.

from vscode-which-key.

MarcoIeni avatar MarcoIeni commented on July 3, 2024

if keys is negative else required

Do you mean position, right?

Furthermore, is args required if type == commands?

from vscode-which-key.

stevenguh avatar stevenguh commented on July 3, 2024

Do you mean position, right?

Sorry, yes.

Furthermore, is args required if type == commands?

They are optional as not all commands need args

from vscode-which-key.

MarcoIeni avatar MarcoIeni commented on July 3, 2024

Take a look at b331678

Are the examples valid? They are validated by vscode, but I don't think the schema is that accurate at the moment and I am not a json schema expert, so feel free to edit both schemas or examples if you want.

The biggest problem at the moment is that I don't know a better way to apply the following constraint to the schemas/binding.json file, too.

Do you know how to solve this problem? If not, I will try to figure it out by myself and if I find no way I will just copy and paste.

from vscode-which-key.

stevenguh avatar stevenguh commented on July 3, 2024

The examples seems to be correct, although it doesn't encompass the whole spectrum. It would be still be a great testing point. Thank you for getting the preliminary schema up. I'd suggest to change the schema for bidningOverrides and bindings to the array type. Ultimately, we only care if the array user entered is correct.

I also added a testing code for loading schema and validating with Ajv. It is very preliminary, you can run it by

npm run test-compile
node out/test/suite/schema.test.js

Also make sure you run npm install to install the dependencies.

from vscode-which-key.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.