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

Valdo extension for VS Code #3

Open
pervoj opened this issue Jun 20, 2021 · 37 comments
Open

Valdo extension for VS Code #3

pervoj opened this issue Jun 20, 2021 · 37 comments
Labels
enhancement New feature or request

Comments

@pervoj
Copy link
Contributor

pervoj commented Jun 20, 2021

Are you also planning to create a Valdo extension for VS Code?

@Prince781
Copy link
Member

I'll have to think about it.

@Prince781
Copy link
Member

I think there was some discussion in a thread on GNOME Builder's issue page about templating too. I hope that, for now at least, a command-line interface is rather useful.

@Prince781 Prince781 added the enhancement New feature or request label Jun 23, 2021
@ghost
Copy link

ghost commented Aug 19, 2021

@Prince781 will you mind if I make one

@Prince781
Copy link
Member

@abdallah-moh feel free

@ghost
Copy link

ghost commented Aug 19, 2021

thanks

@ghost
Copy link

ghost commented Sep 1, 2021

is there any way to enter the app name and the rest when calling the command

@Prince781
Copy link
Member

@abdallah-moh not currently. What context do you need to use this in?

@ghost
Copy link

ghost commented Sep 1, 2021

the vscode extention

@ghost
Copy link

ghost commented Sep 1, 2021

the user will be required to have valdo installed

@Prince781
Copy link
Member

Prince781 commented Sep 1, 2021

the vscode extention

I mean more specifically, how to you plan to have the plugin interact with valdo? For example, are you going to rewrite the prompt in JS and intend to call valdo to instantiate the template? Walk me through your proposal.

@ghost
Copy link

ghost commented Sep 1, 2021

What I will do is get all the required info from the user then use a node module to run valdo --data in here

@Prince781
Copy link
Member

@abdallah-moh how will you determine what information you need? Don't you need to analyze the template?

@ghost
Copy link

ghost commented Sep 1, 2021

Yes I will get the template type at the beginning

@Prince781
Copy link
Member

Prince781 commented Sep 3, 2021

@abdallah-moh so it looks like I'll need to make some changes to valdo for you. What do you think of this API?

% valdo eos --list-vars
{
        "PROGRAM_NAME": {
            "summary": "the name of the program",
            "default": "/${PROJECT_NAME}/\\w+/\\u\\0/(\\w)?\\W+(\\w)?(\\w*)/\\1\\u\\2\\L\\3\\E/^\\w/\\u\\0/",
            "pattern": "^[[:word:]-]+$"
        },
        "PROJECT_SUMMARY": {
            "summary": "a very short summary of the project",
            "default": "a new app for elementary OS"
        },
        "PROJECT_CATEGORIES": {
            "summary": "categories (semicolon-separated)",
            "pattern": "^((AudioVideo|Audio|Video|Development|Education|Game|Graphics|Network|Office|Science|Settings|System|Utility);)+$"
        },
        "PROJECT_KEYWORDS": {
            "summary": "keywords (semicolon-separated)",
            "default": "/${PROJECT_NAME}/\\W+/;/^;+//\\w+/\\L\\0\\E/[^;]$/\\0;/",
            "pattern": "^(\\w+;)+$"
        }
}
% valdo --list-builtin-vars
# will list all built-in variables
% valdo eos -DPROGRAM_NAME='valdo' -DPROJECT_VERSION='1.0.0' \
 -DPROJECT_SUMMARY='a templating engine for Vala' -DPROJECT_CATEGORIES='System;Utility;' \
 -DPROJECT_KEYWORDS='vala,templating' -o $DIRECTORY

Note, this is an example of how it would work with the eos template.

@ghost
Copy link

ghost commented Sep 3, 2021

looks nice for me

@Prince781
Copy link
Member

@abdallah-moh checkout and build wip/commands and try getting your frontend to work with Valdo

@ghost
Copy link

ghost commented Sep 10, 2021

@Prince781 is there an arg to get a list of all the templates

@Prince781
Copy link
Member

Prince781 commented Sep 10, 2021

@abdallah-moh you can just run valdo and it'll print out all of the templates. The output should be easy to parse.

e.g.

% valdo | tail -n +3 | awk '{print $1}'
lib
new
gtk
swifty-gtk4
eos

@pervoj
Copy link
Contributor Author

pervoj commented Sep 11, 2021

Maybe it would be better to parse the output using JS for better running support on Windows.

@ghost
Copy link

ghost commented Sep 11, 2021

@pervoj Why would someone create a vala project on windows,
and js is what is used to create vscode extentions

@pervoj
Copy link
Contributor Author

pervoj commented Sep 11, 2021

@abdallah-moh Maybe someone can start working on Linux and continue working on Windows. Otherwise, I think it's a shame to have a non-multiplatform extension for the multiplatform Valdo.

Yes, I know, I meant that I think it's better to parse the output right in the extension code.

@ghost
Copy link

ghost commented Sep 11, 2021

@pervoj The extension will need valdo to run and valdo is not available for windows

@pervoj
Copy link
Contributor Author

pervoj commented Sep 11, 2021

@abdallah-moh You can compile Valdo on Windows without any problems. I also talked with @Prince781 about packaging for MSYS2 (where these commands but are available).

It's up to you, it was just a suggestion.

@ghost
Copy link

ghost commented Sep 11, 2021

the extension will work if valdo is installed so yes it can work on windows if you install valdo

@Prince781
Copy link
Member

@abdallah-moh the example command I gave demonstrates that it's simple to parse valdo's output using a regex. I did not intend for you to execute that command.

@ghost
Copy link

ghost commented Sep 11, 2021

I know

@ghost
Copy link

ghost commented Sep 22, 2021

Is the feature added?

@pervoj
Copy link
Contributor Author

pervoj commented Sep 22, 2021

Try wip/commands branch

@ghost
Copy link

ghost commented Sep 22, 2021

I was busy but now I have time to work on the extension you can find it here
https://github.com/Abdallah-Moh/vs-valdo

@ghost
Copy link

ghost commented Sep 22, 2021

@abdallah-moh so it looks like I'll need to make some changes to valdo for you. What do you think of this API?

% valdo eos --list-vars
{
        "PROGRAM_NAME": {
            "summary": "the name of the program",
            "default": "/${PROJECT_NAME}/\\w+/\\u\\0/(\\w)?\\W+(\\w)?(\\w*)/\\1\\u\\2\\L\\3\\E/^\\w/\\u\\0/",
            "pattern": "^[[:word:]-]+$"
        },
        "PROJECT_SUMMARY": {
            "summary": "a very short summary of the project",
            "default": "a new app for elementary OS"
        },
        "PROJECT_CATEGORIES": {
            "summary": "categories (semicolon-separated)",
            "pattern": "^((AudioVideo|Audio|Video|Development|Education|Game|Graphics|Network|Office|Science|Settings|System|Utility);)+$"
        },
        "PROJECT_KEYWORDS": {
            "summary": "keywords (semicolon-separated)",
            "default": "/${PROJECT_NAME}/\\W+/;/^;+//\\w+/\\L\\0\\E/[^;]$/\\0;/",
            "pattern": "^(\\w+;)+$"
        }
}
% valdo --list-builtin-vars
# will list all built-in variables
% valdo eos -DPROGRAM_NAME='valdo' -DPROJECT_VERSION='1.0.0' \
 -DPROJECT_SUMMARY='a templating engine for Vala' -DPROJECT_CATEGORIES='System;Utility;' \
 -DPROJECT_KEYWORDS='vala,templating' -o $DIRECTORY

Note, this is an example of how it would work with the eos template.

@Prince781 can this return an array of objects and each object will contain the name and the rest

@Prince781
Copy link
Member

@abdallah-moh done. Do a git pull --rebase --force I think.

@ghost
Copy link

ghost commented Sep 26, 2021

@Prince781 The variable PROJECT_DIR for example has a regex as a default value
I can substitute the variable ${PROJECT_NAME} with the project name but i do not know how should I run this regex in js to return the value needed

@pervoj
Copy link
Contributor Author

pervoj commented Sep 27, 2021

Try this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

You can also init regex from string.

let re = new RegExp('ab+c', 'g');

g for global search.

Than test with test() method.

if (re.test(str)) {
    
}

@ghost
Copy link

ghost commented Sep 27, 2021

@pervoj I know how to test regex in js, What I mean is how to use this pattern
/${PROJECT_NAME}/\\w+/\\u\\0/(\\w)?\\W+(\\w)?(\\w*)/\\1\\u\\2\\L\\3\\E/^\\w/\\u\\0/

@Prince781
Copy link
Member

Prince781 commented Sep 27, 2021

@abdallah-moh read this carefully: https://github.com/Prince781/valdo#variable-substitution

Basically, this says "take ${PROJECT_NAME}, then replace \w+ with \u\0, then replace (\w)?\W+(\w)?(\w*) with \1\u\2\L\3\E, then replace ^\w with \u\0"

It's essentially ${SOURCE_VARIABLE} then a string of regex-replace pairs. You'll have to parse this string. This is how it's done in Valdo:
https://github.com/Prince781/valdo/blob/023505e22d2c39a42ce582a0318770f25bfbd104/src/value.vala#L51

(Edited comment to unquote the regex.)

@ghost
Copy link

ghost commented Sep 27, 2021

@Prince781 It looks like javascript literary searches for :word: in regex did you mean \w

@Prince781
Copy link
Member

@abdallah-moh Yeah, you can replace [:word:] with A-Za-z0-9_.

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

No branches or pull requests

2 participants